Index: trunk/Ohana/src/addstar/include/addstar.h
===================================================================
--- trunk/Ohana/src/addstar/include/addstar.h	(revision 27392)
+++ trunk/Ohana/src/addstar/include/addstar.h	(revision 27435)
@@ -44,7 +44,7 @@
 
 typedef struct {
-  int Nstars;
+  unsigned int Nstars;
   Stars *stars;
-  int Nimages;
+  off_t Nimages;
   Image *images;
   Coords *mosaic;
@@ -76,5 +76,5 @@
 char   PASSWORD[80];
 char   HOSTNAME[80];
-int    NVALID, *VALID_IP;
+int    NVALID_IP, *VALID_IP;
 char   SKY_TABLE[256];
 int    SKY_DEPTH;  /** XXX EAM : depth of catalog tables, fix usage */
@@ -152,12 +152,12 @@
 AddstarClientOptions args         PROTO((int argc, char **argv, AddstarClientOptions options));
 
-void       AddToCalibration       PROTO((Average *average, SecFilt *secfilt, Measure *measure, Measure *new, int *next, int Nstar));
+void       AddToCalibration       PROTO((Average *average, SecFilt *secfilt, Measure *measure, Measure *new, off_t *next, off_t Nstar));
 void       FindCalibration        PROTO((Image *image));
 FILE      *GetDB                  PROTO((int *state));
 void       InitCalibration        PROTO((int mode));
-void       SaveCalibration        PROTO((float Mo, float dMo, float Mr, float dMr, float Mi, int N));
+void       SaveCalibration        PROTO((float Mo, float dMo, float Mr, float dMr, float Mi, off_t N));
 void       SetProtect             PROTO((int mode));
 int        SetSignals             PROTO((void));
-int        Shutdown               PROTO((char *message, ...));
+int        Shutdown               PROTO((char *message, ...)) OHANA_FORMAT(printf, 1, 2);
 void       TrapSignal             PROTO((int sig));
 float      airmass                PROTO((float secz_image, double ra, double dec, double st, double latitude));
@@ -166,32 +166,32 @@
 SkyTable  *SkyTableFromTychoIndex PROTO((char *filename, int VERBOSE));
 void       check_permissions      PROTO((char *basefile));
-int        dump_rawstars          PROTO((Stars *stars, int Nstars));
+int        dump_rawstars          PROTO((Stars *stars, unsigned int Nstars));
 int        edge_check             PROTO((double *x1, double *y1, double *x2, double *y2));
-Image     *fakeimage              PROTO((char *rootname, int *Nimage, int photcode));
-
-int        find_matches           PROTO((SkyRegion *region, Stars *stars, int Nstars, Catalog *catalog, AddstarClientOptions options));
-int        find_matches_closest   PROTO((SkyRegion *region, Stars *stars, int Nstars, Catalog *catalog, AddstarClientOptions options));
-int        find_matches_refstars  PROTO((SkyRegion *region, Stars **stars, int Nstars, Catalog *catalog, AddstarClientOptions options));
-int        find_matches_closest_refstars  PROTO((SkyRegion *region, Stars **stars, int Nstars, Catalog *catalog, AddstarClientOptions options));
-
-Stars    **find_subset            PROTO((SkyRegion *region, Stars *stars, int Nstars, int *NSTARS));
+Image     *fakeimage              PROTO((char *rootname, off_t *Nimage, int photcode));
+
+int        find_matches           	 PROTO((SkyRegion *region, Stars *stars,  unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
+int        find_matches_closest   	 PROTO((SkyRegion *region, Stars *stars,  unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
+int        find_matches_refstars  	 PROTO((SkyRegion *region, Stars **stars, unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
+int        find_matches_closest_refstars PROTO((SkyRegion *region, Stars **stars, unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
+
+Stars    **find_subset            PROTO((SkyRegion *region, Stars *stars, unsigned int Nstars, unsigned int *NSTARS));
 int        gcatalog               PROTO((Catalog *catalog));
-Stars     *get2mass               PROTO((SkyRegion *patch, int photcode, int mode, int *NSTARS));
+Stars     *get2mass               PROTO((SkyRegion *patch, int photcode, int mode, unsigned int *NSTARS));
 double     get_subpix             PROTO((double x, double y));
 
-Stars     *greference             PROTO((char *Refcat, SkyRegion *catstats, int photcode, int *nstars));
-Stars     *getgsc                 PROTO((SkyRegion *patch, int *NSTARS));
-Stars     *gettycho               PROTO((SkyRegion *catstats, int photcode, int *Nstars));
-Stars     *getusno                PROTO((SkyRegion *catstats, int photcode, int *Nstars));
-Stars     *getusnob               PROTO((SkyRegion *catstats, int photcode, int *Nstars));
+Stars     *greference             PROTO((char *Refcat, SkyRegion *catstats, int photcode, unsigned int *nstars));
+Stars     *getgsc                 PROTO((SkyRegion *patch, unsigned int *NSTARS));
+Stars     *gettycho               PROTO((SkyRegion *catstats, int photcode, unsigned int *Nstars));
+Stars     *getusno                PROTO((SkyRegion *catstats, int photcode, unsigned int *Nstars));
+Stars     *getusnob               PROTO((SkyRegion *catstats, int photcode, unsigned int *Nstars));
 
 // load text-based stars (REF only in the sense of REF photcodes)
-Stars     *grefstars              PROTO((char *file, int photcode, int *Nstars));
-
-Stars     *LoadStars              PROTO((char *file, int *Nstars, Image **images, int *Nimages, AddstarClientOptions *options));
+Stars     *grefstars              PROTO((char *file, int photcode, unsigned int *Nstars));
+
+Stars     *LoadStars              PROTO((char *file, unsigned int *Nstars, Image **images, off_t *Nimages, AddstarClientOptions *options));
 Header   **LoadHeaders            PROTO((FILE *f, int *mode, int *Nheader));
-HeaderSet *MatchHeaders           PROTO((int **extsize, int *nimage, int mode, Header **headers, int Nheaders));
-int        LoadData               PROTO((FILE *f, char *file, Image **images, int *nvalid, Stars **stars, int *Nstars, Header **headers, int *extsize, HeaderSet *headerSets, int NheaderSets, AddstarClientOptions *options));
-int        GetZeroPointExposure   PROTO((Header **headers, HeaderSet *headerSets, int Nimages));
+HeaderSet *MatchHeaders           PROTO((off_t **extsize, off_t *nimage, int mode, Header **headers, int Nheaders));
+int        LoadData               PROTO((FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, int NheaderSets, AddstarClientOptions *options));
+int        GetZeroPointExposure   PROTO((Header **headers, HeaderSet *headerSets, off_t Nimages));
 
 int        in_image               PROTO((double r, double d, Image *image));
@@ -200,44 +200,25 @@
 void       lock_image_db          PROTO((FITS_DB *db, char *filename));
 int        main                   PROTO((int argc, char **argv));
-void       make_backup            PROTO((char *filename));
-int        match_refstars         PROTO((Stars *stars, int Nstars));
-void       mkcatalog              PROTO((SkyRegion *region, Catalog *catalog));
 double     opening_angle          PROTO((double x1, double y1, double x2, double y2, double x3, double y3));
 int        parse_time             PROTO((Header *header));
-Stars     *rd_gsc                 PROTO((char *filename, int *nstars));
+Stars     *rd_gsc                 PROTO((char *filename, unsigned int *nstars));
 int        replace_match          PROTO((Average *average, Measure *measure, Stars *star));
 void       resort_catalog         PROTO((Catalog *catalog));
-Stars     *rfits                  PROTO((FILE *f, unsigned int *nstars));
-Stars     *rtext                  PROTO((FILE *f, unsigned int *nstars));
 Stars     *ReadStarsFITS          PROTO((FILE *f, Header *header, Header *in_theader, unsigned int *nstars));
 Stars     *ReadStarsTEXT          PROTO((FILE *f, unsigned int *nstars));
-Stars     *ReadStarsSDSS          PROTO((FILE *f, char *name, Header *header, Header *in_theader, Image *images, int *nimages, unsigned int *nstars));
+Stars     *ReadStarsSDSS          PROTO((FILE *f, char *name, Header *header, Header *in_theader, Image *images, off_t *nimages, unsigned int *nstars));
 int        ReadImageHeader        PROTO((Header *header, Image *image, int photcode));
 Stars     *FilterStars            PROTO((Stars *instars, Image *image, unsigned int imageID));
-Stars     *MergeStars             PROTO((Stars *stars, int *Nstars, Stars *instars, int Ninstars));
-void       save_pt_catalog        PROTO((Catalog *catalog));  /*** choose new name ***/
+Stars     *MergeStars             PROTO((Stars *stars, unsigned int *Nstars, Stars *instars, unsigned int Ninstars));
 double     scat_subpix            PROTO((double x, double y));
-time_t     short_date_to_sec      PROTO((char *date));
-void       sort_lists             PROTO((float *X, float *Y, int *S, int N));
-void       sort_stars             PROTO((Stars *stars, int N));
-int        str_to_radec           PROTO((double *ra, double *dec, char *str1, char *str2));
-void       unlock_image_db        PROTO((FITS_DB *db));
-void       update_coords          PROTO((Average *average, Measure *measure, int *next));
-void       wcatalog               PROTO((Catalog *catalog));
-void       free_catalog           PROTO((Catalog *catalog));
-void       wimage                 PROTO((FITS_DB *db, Image *image));
-void       create_image_db        PROTO((FITS_DB *db));
-void       set_db                 PROTO((FITS_DB *in));
-void       uppercase              PROTO((char *string));
-void       fsort                  PROTO((float *X, int N));
-void       fsort2                 PROTO((float *X, float *Y, int N));
-int 	  *init_measure_links     PROTO((Average *average, int Naverage, Measure *measure, int Nmeasure));
-int 	  *init_missing_links     PROTO((Average *average, int Naverage, Missing *missing, int Nmissing));
-int 	   add_meas_link     	  PROTO((Average *average, int *next, int Nmeasure, int NMEASURE));
-int 	   add_miss_link     	  PROTO((Average *average, int *next, int Nmissing));
-int 	  *build_measure_links    PROTO((Average *average, int Naverage, Measure *measure, int Nmeasure));
-Measure   *sort_measure     	  PROTO((Average *average, int Naverage, Measure *measure, int Nmeasure, int *next));
-Missing   *sort_missing     	  PROTO((Average *average, int Naverage, Missing *missing, int Nmissing, int *next_miss));
-int        ImageOptions		  PROTO((AddstarClientOptions *options, Image *images, int Nimages));
+void       update_coords          PROTO((Average *average, Measure *measure, off_t *next));
+off_t 	  *init_measure_links     PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
+off_t 	  *init_missing_links     PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing));
+off_t 	   add_meas_link     	  PROTO((Average *average, off_t *next_meas, off_t Nmeasure, off_t NMEASURE));
+off_t 	   add_miss_link     	  PROTO((Average *average, off_t *next_miss, off_t Nmissing));
+off_t 	  *build_measure_links    PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
+Measure   *sort_measure     	  PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next_meas));
+Missing   *sort_missing     	  PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next_miss));
+int        ImageOptions		  PROTO((AddstarClientOptions *options, Image *images, off_t Nimages));
 int        GetFileMode		  PROTO((Header *header));
 AddstarClientOptions args_client  PROTO((int argc, char **argv, AddstarClientOptions options));
@@ -252,8 +233,8 @@
 int 	   WaitServerSocket	  PROTO((int InitSocket, SockAddress *Address, int *validIP, int Nvalid));
 int 	   GetClientSocket	  PROTO((char *hostname));
-int 	   UpdateDatabase_Image	  PROTO((AddstarClientOptions *options, Image *images, int Nimages, Coords *mosaic, Stars *stars, int Nstars));
-int 	   UpdateDatabase_Reflist PROTO((AddstarClientOptions *options, Stars *stars, int Nstars));
+int 	   UpdateDatabase_Image	  PROTO((AddstarClientOptions *options, Image *images, off_t Nimages, Coords *mosaic, Stars *stars, unsigned int Nstars));
+int 	   UpdateDatabase_Reflist PROTO((AddstarClientOptions *options, Stars *stars, unsigned int Nstars));
 int 	   UpdateDatabase_Refcat  PROTO((AddstarClientOptions *options, SkyRegion *UserPatch, char *refcat));
-SkyList   *SkyListForStars	  PROTO((SkyTable *table, int depth, Stars *stars, int Nstars));
+SkyList   *SkyListForStars	  PROTO((SkyTable *table, int depth, Stars *stars, unsigned int Nstars));
 SkyList   *SkyListExistingSubset  PROTO((SkyList *input, char *path));
 int        SkyListSetPath	  PROTO((SkyList *list, char *path));
@@ -266,10 +247,10 @@
 int 	   NewReflist_Thread	  PROTO((int BindSocket));
 
-Stars     *Convert_SMPDATA	  PROTO((FTable *table, int *nstars));
-Stars     *Convert_PS1_DEV_0	  PROTO((FTable *table, int *nstars));
-Stars     *Convert_PS1_DEV_1	  PROTO((FTable *table, int *nstars));
-Stars     *Convert_PS1_V1	  PROTO((FTable *table, int *nstars));
-Stars     *Convert_PS1_V1_Alt	  PROTO((FTable *table, int *nstars));
-Stars     *Convert_PS1_V2	  PROTO((FTable *table, int *nstars));
+Stars     *Convert_SMPDATA	  PROTO((FTable *table, unsigned int *nstars));
+Stars     *Convert_PS1_DEV_0	  PROTO((FTable *table, unsigned int *nstars));
+Stars     *Convert_PS1_DEV_1	  PROTO((FTable *table, unsigned int *nstars));
+Stars     *Convert_PS1_V1	  PROTO((FTable *table, unsigned int *nstars));
+Stars     *Convert_PS1_V1_Alt	  PROTO((FTable *table, unsigned int *nstars));
+Stars     *Convert_PS1_V2	  PROTO((FTable *table, unsigned int *nstars));
 
 int        InitStar               PROTO((Stars *star));
@@ -279,9 +260,9 @@
 int args_skycells (int argc, char **argv);
 int ConfigInit_skycells (int *argc, char **argv);
-int UpdateImageIDs (Stars *stars, int Nstars, Image *images, int Nimages);
-int LoadDataSDSS (FILE *f, char *file, Image **images, int *nvalid, Stars **stars, int *Nstars, Header **headers, int *extsize, HeaderSet *headerSets, int Nimages);
-int altaz (double *alt, double *az, double ha, double dec, double latitude);
-
-int LoadDataPMM (FILE *f, char *file, Image **images, int *nvalid, Stars **stars, int *Nstars);
+int UpdateImageIDs (Stars *stars, unsigned int Nstars, Image *images, off_t Nimages);
+
+int LoadDataSDSS (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t Nimages);
+int LoadDataPMM (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars);
+
 PhotCode *LoadMetadataPMM (char *datafile, Image *image);
 time_t pmm_date_to_sec (char *date, char *time);
@@ -293,4 +274,6 @@
 uint64_t CreatePSPSDetectionID(double tobs, int ccdid, int detID);
 uint64_t CreatePSPSObjectID(double ra, double dec);
+
+int altaz (double *alt, double *az, double ha, double dec, double latitude);
 
 // this is a gnu extension?? caution!
Index: trunk/Ohana/src/addstar/include/skycells.h
===================================================================
--- trunk/Ohana/src/addstar/include/skycells.h	(revision 27392)
+++ trunk/Ohana/src/addstar/include/skycells.h	(revision 27435)
@@ -78,5 +78,5 @@
 void         SetProtect                	    PROTO((int mode));
 int          SetSignals                	    PROTO((void));
-int          Shutdown                  	    PROTO((char *message, ...); ) 
+int          Shutdown                  	    PROTO((char *message, ...)) OHANA_FORMAT(printf, 1, 2);
 void         TrapSignal                	    PROTO((int sig));
 
Index: trunk/Ohana/src/addstar/src/ConfigInit.c
===================================================================
--- trunk/Ohana/src/addstar/src/ConfigInit.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/ConfigInit.c	(revision 27435)
@@ -130,10 +130,10 @@
   /* load valid ip list */
   {
-    int i, Nvalid, ip1, ip2, ip3, ip4, test, status;
+    int i, Nvalid_IP, ip1, ip2, ip3, ip4, test, status;
     char string[80];
 
-    Nvalid = 0;
-    NVALID = 10;
-    ALLOCATE (VALID_IP, int, NVALID);
+    Nvalid_IP = 0;
+    NVALID_IP = 10;
+    ALLOCATE (VALID_IP, int, NVALID_IP);
     for (i = 0; ScanConfig (config, "VALID_IP", "%s", i, string) != NULL; i++) {
       status = sscanf (string, "%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4);
@@ -148,11 +148,11 @@
 	exit (2);
       }
-      VALID_IP[Nvalid] = ip1 | (ip2 << 8) | (ip3 << 16) | (ip4 << 24);
-      Nvalid ++;
-      CHECK_REALLOCATE (VALID_IP, int, NVALID, Nvalid, 10);
-    }
-    NVALID = Nvalid;
-    REALLOCATE (VALID_IP, int, NVALID);
-    if (NVALID == 0) {
+      VALID_IP[Nvalid_IP] = ip1 | (ip2 << 8) | (ip3 << 16) | (ip4 << 24);
+      Nvalid_IP ++;
+      CHECK_REALLOCATE (VALID_IP, int, NVALID_IP, Nvalid_IP, 10);
+    }
+    NVALID_IP = Nvalid_IP;
+    REALLOCATE (VALID_IP, int, NVALID_IP);
+    if (NVALID_IP == 0) {
       free (VALID_IP);
       VALID_IP = NULL;
@@ -172,4 +172,8 @@
   } else {
     options.radius = atof (RadiusWord);
+    if (options.radius < 1e-6) {
+      fprintf (stderr, "non-sensical correlation radius %f\n", options.radius);
+      exit (1);
+    }
   }
 
Index: trunk/Ohana/src/addstar/src/FilterStars.c
===================================================================
--- trunk/Ohana/src/addstar/src/FilterStars.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/FilterStars.c	(revision 27435)
@@ -109,5 +109,5 @@
 }
 
-Stars *MergeStars (Stars *stars, int *Nstars, Stars *instars, int Ninstars) {
+Stars *MergeStars (Stars *stars, unsigned int *Nstars, Stars *instars, unsigned int Ninstars) {
 
   int i, j;
Index: trunk/Ohana/src/addstar/src/GetFileMode.c
===================================================================
--- trunk/Ohana/src/addstar/src/GetFileMode.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/GetFileMode.c	(revision 27435)
@@ -4,19 +4,19 @@
 int GetFileMode (Header *header) {
 
-  char ctype[80];
+  char ctype[80], ctmp;
   int Naxis;
   int simple, extend, haveNaxis, haveCTYPE;
-  int tmp, havePHOT_VER, haveTARG_VER;
+  int havePHOT_VER, haveTARG_VER;
 
-  gfits_scan (header, "SIMPLE", "%t", 1, &simple);
+  gfits_scan_alt (header, "SIMPLE", "%t", 1, &simple);
   haveNaxis = gfits_scan (header, "NAXIS",  "%d", 1, &Naxis);
   haveCTYPE = gfits_scan (header, "CTYPE1", "%s", 1, ctype);
 
-  gfits_scan (header, "EXTEND", "%t", 1, &extend);
+  gfits_scan_alt (header, "EXTEND", "%t", 1, &extend);
     
   // SDSS tsObj files have a version number for the PHOTO and 
   // TS (target selection) pipelines present as header keywords
-  havePHOT_VER = gfits_scan (header, "PHOT_VER", "%s", 1, &tmp);
-  haveTARG_VER = gfits_scan (header, "TARG_VER", "%s", 1, &tmp);
+  havePHOT_VER = gfits_scan (header, "PHOT_VER", "%s", 1, &ctmp);
+  haveTARG_VER = gfits_scan (header, "TARG_VER", "%s", 1, &ctmp);
   if (havePHOT_VER && haveTARG_VER) return SDSS_OBJ;
 
Index: trunk/Ohana/src/addstar/src/GetZeroPointExposure.c
===================================================================
--- trunk/Ohana/src/addstar/src/GetZeroPointExposure.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/GetZeroPointExposure.c	(revision 27435)
@@ -21,5 +21,5 @@
 // offset in ReadImageHeader based on the per-chip zero points in the photcode database
 
-int GetZeroPointExposure (Header **headers, HeaderSet *headerSets, int Nimages) {
+int GetZeroPointExposure (Header **headers, HeaderSet *headerSets, off_t Nimages) {
 
     // the zero point correction is not applied
@@ -37,4 +37,5 @@
     // the zero point correction is measured here and applied in ReadImageHeader
     if (!strcasecmp(ZERO_POINT_OPTION, "CHIP_AVERAGE")) {
+
 	int i, Nzpt, Nmid, Nhead;
 	float *zpt, ZPT_OBS;
Index: trunk/Ohana/src/addstar/src/ImageOptions.c
===================================================================
--- trunk/Ohana/src/addstar/src/ImageOptions.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/ImageOptions.c	(revision 27435)
@@ -2,7 +2,8 @@
 
 /* set specific options based on the image collection */
-int ImageOptions (AddstarClientOptions *options, Image *images, int Nimages) {
+int ImageOptions (AddstarClientOptions *options, Image *images, off_t Nimages) {
 
-  int i, equivPhotcode, consistent;
+  off_t i;
+  int equivPhotcode, consistent;
   float maxError;
   PhotCode *photcode;
Index: trunk/Ohana/src/addstar/src/ListenClients_Thread.c
===================================================================
--- trunk/Ohana/src/addstar/src/ListenClients_Thread.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/ListenClients_Thread.c	(revision 27435)
@@ -14,5 +14,5 @@
 
     /* wait for clients to make connection */
-    BindSocket = WaitServerSocket (InitSocket, &Address, VALID_IP, NVALID);
+    BindSocket = WaitServerSocket (InitSocket, &Address, VALID_IP, NVALID_IP);
     if (BindSocket == -1) continue;
 
Index: trunk/Ohana/src/addstar/src/LoadData.c
===================================================================
--- trunk/Ohana/src/addstar/src/LoadData.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/LoadData.c	(revision 27435)
@@ -6,8 +6,9 @@
 
 // examine the header sets and set the Image entries for the the valid images
-int LoadData (FILE *f, char *file, Image **images, int *nvalid, Stars **stars, int *Nstars, Header **headers, int *extsize, HeaderSet *headerSets, int Nimages, AddstarClientOptions *options) {
+int LoadData (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, int Nimages, AddstarClientOptions *options) {
 
   char *name;
-  int i, j, Nvalid, Nhead, Ndata, Nskip;
+  off_t Nskip, Nvalid, NVALID;
+  int i, j, Nhead, Ndata;
   uint32_t parentID = UINT32_MAX;
   Stars *inStars;
@@ -76,5 +77,5 @@
       Nskip += extsize[j];
     }
-    fseek (f, Nskip, SEEK_SET); 
+    fseeko (f, Nskip, SEEK_SET); 
 	 
     inStars = ReadStarsFITS (f, headers[Nhead], headers[Ndata], &images[0][Nvalid].nstar);
Index: trunk/Ohana/src/addstar/src/LoadDataPMM.c
===================================================================
--- trunk/Ohana/src/addstar/src/LoadDataPMM.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/LoadDataPMM.c	(revision 27435)
@@ -16,8 +16,9 @@
 # define MAG_INDEX_ASC 22
 
-int LoadDataPMM (FILE *f, char *file, Image **images, int *nvalid, Stars **stars, int *Nstars) {
-
+int LoadDataPMM (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars) {
+
+  off_t Nvalid, NVALID;
   char *name, *buffer;
-  int i, fd, Nbyte, Nline, Nvalid, code;
+  int i, fd, Nbyte, Nline, code;
   double ra, dec, mag, airmass, az, ZeroPoint, ZeroPt;
   unsigned int Ninstars, NINSTARS;
Index: trunk/Ohana/src/addstar/src/LoadDataSDSS.c
===================================================================
--- trunk/Ohana/src/addstar/src/LoadDataSDSS.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/LoadDataSDSS.c	(revision 27435)
@@ -4,8 +4,9 @@
 // there should only be a single data set (phu + table) in this file
 // each SDSS data set corresponds to 5 images (ugriz)
-int LoadDataSDSS (FILE *f, char *file, Image **images, int *nvalid, Stars **stars, int *Nstars, Header **headers, int *extsize, HeaderSet *headerSets, int Nimages) {
+int LoadDataSDSS (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t Nimages) {
 
+  off_t Nskip, Nvalid, NVALID;
   char *name;
-  int j, Nvalid, Nhead, Ndata, Nskip;
+  int j, Nhead, Ndata;
   unsigned int Ninstars;
   Stars *inStars;
@@ -36,5 +37,5 @@
     Nskip += extsize[j];
   }
-  fseek (f, Nskip, SEEK_SET); 
+  fseeko (f, Nskip, SEEK_SET); 
 	 
   // XXX I think this is an error?  should this be &images[0][Nvalid] ??
Index: trunk/Ohana/src/addstar/src/LoadHeaders.c
===================================================================
--- trunk/Ohana/src/addstar/src/LoadHeaders.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/LoadHeaders.c	(revision 27435)
@@ -4,5 +4,6 @@
 Header **LoadHeaders (FILE *f, int *mode, int *Nheaders) {
 
-  int i, status, Nskip, NHEADERS;
+  off_t Nskip;
+  int i, status, NHEADERS;
   Header **headers;
 
@@ -31,5 +32,5 @@
     // advance to the next header
     Nskip = gfits_data_size (headers[i]);
-    fseek (f, Nskip, SEEK_CUR); 
+    fseeko (f, Nskip, SEEK_CUR); 
     if (i == NHEADERS - 1) {
       NHEADERS += 10;
Index: trunk/Ohana/src/addstar/src/LoadStars.c
===================================================================
--- trunk/Ohana/src/addstar/src/LoadStars.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/LoadStars.c	(revision 27435)
@@ -1,7 +1,8 @@
 # include "addstar.h"
 
-Stars *LoadStars (char *filename, int *Nstars, Image **images, int *Nimages, AddstarClientOptions *options) {
+Stars *LoadStars (char *filename, unsigned int *Nstars, Image **images, off_t *Nimages, AddstarClientOptions *options) {
 
-  int i, Nfile, NFILE, Nheaders, NheaderSets, mode, *extsize;
+  off_t *extsize, NheaderSets;
+  int i, Nfile, NFILE, Nheaders, mode;
   char **file, line[1024];
   FILE *f;
@@ -80,5 +81,5 @@
       continue;
     }
-    if (VERBOSE) fprintf (stderr, "file %s has %d headers, including %d images\n", file[i], Nheaders, NheaderSets);
+    if (VERBOSE) fprintf (stderr, "file %s has %d headers, including %lld images\n", file[i], Nheaders, (long long) NheaderSets);
 
     /* supplied photcode is incompatible with multi-chip images */
Index: trunk/Ohana/src/addstar/src/MatchHeaders.c
===================================================================
--- trunk/Ohana/src/addstar/src/MatchHeaders.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/MatchHeaders.c	(revision 27435)
@@ -3,5 +3,5 @@
 // XXX largely psphot specific
 
-HeaderSet *MatchHeaders (int **extsize, int *nimage, int mode, Header **headers, int Nheaders) {
+HeaderSet *MatchHeaders (off_t **extsize, off_t *nimage, int mode, Header **headers, int Nheaders) {
 
   int i, j, Nimage, NIMAGE;
@@ -9,5 +9,5 @@
   HeaderSet *headerSets;
 
-  ALLOCATE (extsize[0], int, Nheaders);
+  ALLOCATE (extsize[0], off_t, Nheaders);
 
   Nimage = 0;
@@ -34,5 +34,5 @@
     headerSets[0].extnum_head = 0;
     headerSets[0].extnum_data = 1;
-    extsize[0][0] = headers[0][0].size;
+    extsize[0][0] = headers[0][0].datasize;
     *nimage = 1;
     return headerSets;
@@ -42,7 +42,7 @@
   for (i = 0; i < Nheaders; i++) {
     if (mode == SIMPLE_CMP) {
-      extsize[0][i] = headers[i][0].size;
+      extsize[0][i] = headers[i][0].datasize;
     } else {
-      extsize[0][i] = headers[i][0].size + gfits_data_size (headers[i]);
+      extsize[0][i] = headers[i][0].datasize + gfits_data_size (headers[i]);
     }
 
@@ -92,6 +92,6 @@
   // extension matched to the header in the PHU
   if (Nimage == 0) {
-    extsize[0][0] = headers[0][0].size + gfits_data_size (headers[0]);
-    extsize[0][1] = headers[1][0].size + gfits_data_size (headers[1]);
+    extsize[0][0] = headers[0][0].datasize + gfits_data_size (headers[0]);
+    extsize[0][1] = headers[1][0].datasize + gfits_data_size (headers[1]);
     gfits_scan (headers[1], ExtnameKeyword, "%s", 1, extname);
     if (!strcmp (extname, "SMPFILE")) {
Index: trunk/Ohana/src/addstar/src/ReadImageHeader.c
===================================================================
--- trunk/Ohana/src/addstar/src/ReadImageHeader.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/ReadImageHeader.c	(revision 27435)
@@ -181,11 +181,12 @@
     // RULE: ccdnum is the value of the first string of digits in CCDNumKeyword
     // For example: ccdnum(XY42.hdr) = 42, ccdnum(XY01.hdr) = 1
+    // if no digits occur, then we assume there is only one ccd
     char *p = ccdnum;
     // get rid of any leading non-digit characters
     while (*p && !isdigit(*p)) p++;
     if (*p) {
-        image[0].ccdnum = atoi(p);
+      image[0].ccdnum = atoi(p);
     } else {
-        image[0].ccdnum = 0;
+      image[0].ccdnum = 0;
     }
   }
Index: trunk/Ohana/src/addstar/src/ReadStarsFITS.c
===================================================================
--- trunk/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 27435)
@@ -5,5 +5,6 @@
 Stars *ReadStarsFITS (FILE *f, Header *header, Header *in_theader, unsigned int *nstars) {
 
-  int Nskip, Nstars;
+  off_t Nskip;
+  unsigned int Nstars;
   char type[80];
   Header theader;
@@ -16,6 +17,6 @@
   } else {
     table.header = in_theader;
-    Nskip = in_theader[0].size;
-    fseek (f, Nskip, SEEK_CUR); 
+    Nskip = in_theader[0].datasize;
+    fseeko (f, Nskip, SEEK_CUR); 
   }
 
@@ -57,7 +58,9 @@
 }
 
-Stars *Convert_SMPDATA (FTable *table, int *nstars) {
-
-  int i, Nstars, swapped;
+Stars *Convert_SMPDATA (FTable *table, unsigned int *nstars) {
+
+  off_t Nstars;
+  unsigned int i;
+  char swapped;
   double ZeroPt;
   Stars *stars = NULL;
@@ -96,7 +99,8 @@
 }
 
-Stars *Convert_PS1_DEV_0 (FTable *table, int *nstars) {
-
-  int i, Nstars;
+Stars *Convert_PS1_DEV_0 (FTable *table, unsigned int *nstars) {
+
+  off_t Nstars;
+  unsigned int i;
   double ZeroPt;
   Stars *stars;
@@ -140,7 +144,8 @@
 // XXX I need to make the IPP I/O functions and these functions
 // consistent wrt ZERO_POINT....
-Stars *Convert_PS1_DEV_1 (FTable *table, int *nstars) {
-
-  int i, Nstars;
+Stars *Convert_PS1_DEV_1 (FTable *table, unsigned int *nstars) {
+
+  off_t Nstars; 
+  unsigned int i;
   double ZeroPt;
   Stars *stars;
@@ -185,7 +190,8 @@
 }
 
-Stars *Convert_PS1_V1 (FTable *table, int *nstars) {
-
-  int i, Nstars;
+Stars *Convert_PS1_V1 (FTable *table, unsigned int *nstars) {
+
+  off_t Nstars; 
+  unsigned int i;
   double ZeroPt;
   Stars *stars;
@@ -261,7 +267,8 @@
 }
 
-Stars *Convert_PS1_V1_Alt (FTable *table, int *nstars) {
-
-  int i, Nstars;
+Stars *Convert_PS1_V1_Alt (FTable *table, unsigned int *nstars) {
+
+  off_t Nstars; 
+  unsigned int i;
   double ZeroPt;
   Stars *stars;
@@ -332,7 +339,8 @@
 }
 
-Stars *Convert_PS1_V2 (FTable *table, int *nstars) {
-
-  int i, Nstars;
+Stars *Convert_PS1_V2 (FTable *table, unsigned int *nstars) {
+
+  off_t Nstars; 
+  unsigned int i;
   double ZeroPt;
   Stars *stars;
Index: trunk/Ohana/src/addstar/src/ReadStarsSDSS.c
===================================================================
--- trunk/Ohana/src/addstar/src/ReadStarsSDSS.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/ReadStarsSDSS.c	(revision 27435)
@@ -31,7 +31,8 @@
 // given a file with the pointer at the start of the table block and the 
 // corresponding image header, load the stars from the table
-Stars *ReadStarsSDSS (FILE *f, char *name, Header *header, Header *in_theader, Image *images, int *nimages, unsigned int *nstars) {
-
-  int i, j, N, Nskip, Nstars, camcol;
+Stars *ReadStarsSDSS (FILE *f, char *name, Header *header, Header *in_theader, Image *images, off_t *nimages, unsigned int *nstars) {
+
+  off_t Nskip, Nrow;
+  int i, j, N, Nstars, camcol;
   char type[80];
   Header theader;
@@ -43,5 +44,5 @@
   char filtname[16][5];
   int photcode[5];
-  int Nrow, Ncol; // used in the GET_COLUMN_1,5 macros above
+  int Ncol; // used in the GET_COLUMN_1,5 macros above
   
   if (in_theader == NULL) {
@@ -50,6 +51,6 @@
   } else {
     table.header = in_theader;
-    Nskip = in_theader[0].size;
-    fseek (f, Nskip, SEEK_CUR); 
+    Nskip = in_theader[0].datasize;
+    fseeko (f, Nskip, SEEK_CUR); 
   }
 
Index: trunk/Ohana/src/addstar/src/SkyListForStars.c
===================================================================
--- trunk/Ohana/src/addstar/src/SkyListForStars.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/SkyListForStars.c	(revision 27435)
@@ -13,5 +13,5 @@
 }
 
-SkyList *SkyListForStars (SkyTable *table, int depth, Stars *stars, int Nstars) {
+SkyList *SkyListForStars (SkyTable *table, int depth, Stars *stars, unsigned int Nstars) {
   
   int i, j, Nr, NR;
Index: trunk/Ohana/src/addstar/src/SkyTableFromTychoIndex.c
===================================================================
--- trunk/Ohana/src/addstar/src/SkyTableFromTychoIndex.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/SkyTableFromTychoIndex.c	(revision 27435)
@@ -147,5 +147,5 @@
     skytable[0].filename[i] = NULL;
   }
-  if (VERBOSE) fprintf (stderr, "loaded %d tables from tycho index\n", skytable[0].Nregions);
+  if (VERBOSE) fprintf (stderr, "loaded %lld tables from tycho index\n", (long long) skytable[0].Nregions);
 
   return (skytable);
Index: trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c
===================================================================
--- trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c	(revision 27435)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-int UpdateDatabase_Image (AddstarClientOptions *options, Image *images, int Nimages, Coords *mosaic, Stars *stars, int Nstars) {
+int UpdateDatabase_Image (AddstarClientOptions *options, Image *images, int Nimages, Coords *mosaic, Stars *stars, unsigned int Nstars) {
 
   int i, status;
Index: trunk/Ohana/src/addstar/src/UpdateDatabase_Reflist.c
===================================================================
--- trunk/Ohana/src/addstar/src/UpdateDatabase_Reflist.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/UpdateDatabase_Reflist.c	(revision 27435)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-int UpdateDatabase_Reflist (AddstarClientOptions *options, Stars *stars, int Nstars) {
+int UpdateDatabase_Reflist (AddstarClientOptions *options, Stars *stars, unsigned int Nstars) {
 
   int i, Nsubset;
Index: trunk/Ohana/src/addstar/src/UpdateImageIDs.c
===================================================================
--- trunk/Ohana/src/addstar/src/UpdateImageIDs.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/UpdateImageIDs.c	(revision 27435)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-int UpdateImageIDs (Stars *stars, int Nstars, Image *images, int Nimages) {
+int UpdateImageIDs (Stars *stars, unsigned int Nstars, Image *images, off_t Nimages) {
 
   int i, status, isEmpty;
Index: trunk/Ohana/src/addstar/src/addstar.c
===================================================================
--- trunk/Ohana/src/addstar/src/addstar.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/addstar.c	(revision 27435)
@@ -1,9 +1,11 @@
 # include "addstar.h"
 
+// LARGEFILES: this program currently limits Nstars (input file) to < 2^31
 int main (int argc, char **argv) {
 
+  unsigned int Nstars, Nsubset;
   int Nmatch, status, loadObjects;
-  int i, Nstars, Nimages, Nsubset;
-  unsigned long long Naverage, Nmeasure;
+  off_t i, Nimages;
+  off_t Naverage, Nmeasure;
   Stars *stars, **subset;
   Image *images;
@@ -46,5 +48,5 @@
 	newlist = SkyListByImage (sky, -1, &images[i]);
 	SkyListMerge (&skylist, newlist);
-	if (VERBOSE) fprintf (stderr, "added %d regions to yield %d total\n", newlist[0].Nregions, skylist[0].Nregions);
+	if (VERBOSE) fprintf (stderr, "added %lld regions to yield %lld total\n", (long long) newlist[0].Nregions, (long long) skylist[0].Nregions);
 	SkyListFree (newlist);
       }
@@ -78,5 +80,5 @@
     skylist = tmp;
   }
-  if (VERBOSE) fprintf (stderr, "writing to %d regions\n", skylist[0].Nregions);
+  if (VERBOSE) fprintf (stderr, "writing to %lld regions\n", (long long) skylist[0].Nregions);
 
   /* don't load the object tables for only_images, unless we are getting the calibration. */
@@ -147,4 +149,12 @@
       case M_RESORT:
 	if (options.nosort == 3) catalog.sorted = FALSE;
+
+	// no need to resort empty catalogs
+	if (catalog.Naves_disk == 0) {
+	  dvo_catalog_unlock (&catalog);
+	  dvo_catalog_free (&catalog);
+	  continue;
+	}
+
 	resort_catalog (&catalog);
 	Nsubset = 1;
@@ -203,5 +213,5 @@
   gettimeofday (&stop, NULL);
   dtime = DTIME (stop, start);
-  fprintf (stderr, "SUCCESS: elapsed time %9.4f sec for %5d stars (%5d matches), %6lld average, %7lld measure\n", dtime, Nstars, Nmatch, Naverage, Nmeasure);
+  fprintf (stderr, "SUCCESS: elapsed time %9.4f sec for %5d stars (%5d matches), %6lld average, %7lld measure\n", dtime, Nstars, Nmatch, (long long) Naverage, (long long) Nmeasure);
 
   exit (0);
Index: trunk/Ohana/src/addstar/src/addstard.c
===================================================================
--- trunk/Ohana/src/addstar/src/addstard.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/addstard.c	(revision 27435)
@@ -23,5 +23,5 @@
 
     /* wait for clients to make connection */
-    BindSocket = WaitServerSocket (InitSocket, &Address, VALID_IP, NVALID);
+    BindSocket = WaitServerSocket (InitSocket, &Address, VALID_IP, NVALID_ID);
     if (BindSocket == -1) continue;
 
Index: trunk/Ohana/src/addstar/src/build_links.c
===================================================================
--- trunk/Ohana/src/addstar/src/build_links.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/build_links.c	(revision 27435)
@@ -26,20 +26,20 @@
 /* build the initial links assuming the table is sorted, 
    not partial, and has a correct set of average[].measureOffset,Nmeasure values */
-int *init_measure_links (Average *average, int Naverage, Measure *measure, int Nmeasure) {
-
-  int i, j, N;
-  int *next;
+off_t *init_measure_links (Average *average, off_t Naverage, Measure *measure, off_t Nmeasure) {
+
+  off_t i, j, N;
+  off_t *next_meas;
 
   N = 0;
 
-  ALLOCATE (next, int, Nmeasure);
+  ALLOCATE (next_meas, off_t, Nmeasure);
   for (i = 0; i < Naverage; i++, N++) {
     for (j = 0; j < average[i].Nmeasure - 1; j++, N++) {
-      next[N] = N + 1;
+      next_meas[N] = N + 1;
       if (N >= Nmeasure) {
 	fprintf (stderr, "WARNING: N out of bounds (1)\n");
       }
     }
-    next[N] = -1;
+    next_meas[N] = -1;
     if (N >= Nmeasure) {
       fprintf (stderr, "WARNING: N out of bounds (2)\n");
@@ -51,5 +51,5 @@
     }
   }
-  return (next);
+  return (next_meas);
 }
 
@@ -61,10 +61,10 @@
  */ 
 
-int *build_measure_links (Average *average, int Naverage, Measure *measure, int Nmeasure) {
-
-  int i, m, k, Nm, averef;
-  int *next;
-
-  ALLOCATE (next, int, Nmeasure);
+off_t *build_measure_links (Average *average, off_t Naverage, Measure *measure, off_t Nmeasure) {
+
+  off_t i, m, k, Nm, averef;
+  off_t *next_meas;
+
+  ALLOCATE (next_meas, off_t, Nmeasure);
 
   /* reset the Nm, offset values for average */
@@ -77,5 +77,5 @@
     averef = measure[Nm].averef;
     m = average[averef].measureOffset;  
-    next[Nm] = -1;
+    next_meas[Nm] = -1;
 
     if (m == -1) { /* no links yet for source */
@@ -85,6 +85,6 @@
     }
 
-    for (k = 0; next[m] != -1; k++) {
-      m = next[m];
+    for (k = 0; next_meas[m] != -1; k++) {
+      m = next_meas[m];
       if (m >= Nmeasure) {
 	fprintf (stderr, "WARNING: m out of bounds (1)\n");
@@ -93,22 +93,22 @@
 
     average[averef].Nmeasure = k + 2;
-    next[m] = Nm;
+    next_meas[m] = Nm;
     if (m >= Nmeasure) {
       fprintf (stderr, "WARNING: m out of bounds (2)\n");
     }
   }
-  return (next);
+  return (next_meas);
 }
 
 /* average[].measureOffset, average[].Nmeasure are valid within an addstar run */
-int add_meas_link (Average *average, int *next, int Nmeasure, int NMEASURE) {
-
-  int k, m;
-
-  /* if we have trouble, check validity of next[m] : m < Nmeasure */
+off_t add_meas_link (Average *average, off_t *next_meas, off_t Nmeasure, off_t NMEASURE) {
+
+  off_t k, m;
+
+  /* if we have trouble, check validity of next_meas[m] : m < Nmeasure */
   m = average[0].measureOffset;  
 
   for (k = 0; k < average[0].Nmeasure - 1; k++)  {
-    m = next[m];
+    m = next_meas[m];
     if (m >= NMEASURE) {
       fprintf (stderr, "WARNING: m out of bounds (3)\n");
@@ -117,5 +117,5 @@
 
   /* set up references */
-  next[Nmeasure] = -1;
+  next_meas[Nmeasure] = -1;
   if (Nmeasure >= NMEASURE) {
     fprintf (stderr, "WARNING: Nmeasure out of bounds (1)\n");
@@ -125,5 +125,5 @@
     average[0].measureOffset = Nmeasure;
   } else {
-    next[m] = Nmeasure;
+    next_meas[m] = Nmeasure;
     if (m >= NMEASURE) {
       fprintf (stderr, "WARNING: m out of bounds (4)\n");
@@ -137,7 +137,7 @@
    we must always save the missing table, if it exists */
 
-Measure *sort_measure (Average *average, int Naverage, Measure *measure, int Nmeasure, int *next) {
-
-  int i, k, n, N;
+Measure *sort_measure (Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next_meas) {
+
+  off_t i, k, n, N;
   Measure *tmpmeasure;
 
@@ -153,5 +153,5 @@
       if (measure[n].averef != i) abort();
       tmpmeasure[N].averef = i;
-      n = next[n];
+      n = next_meas[n];
     }
   }
@@ -161,18 +161,18 @@
 
 /* build the initial links assuming the table is sorted */
-int *init_missing_links (Average *average, int Naverage, Missing *missing, int Nmissing) {
-
-  int i, j, N;
-  int *next;
+off_t *init_missing_links (Average *average, off_t Naverage, Missing *missing, off_t Nmissing) {
+
+  off_t i, j, N;
+  off_t *next_miss;
 
   N = 0;
 
-  ALLOCATE (next, int, Nmissing);
+  ALLOCATE (next_miss, off_t, Nmissing);
   for (i = 0; i < Naverage; i++) {
     for (j = 0; j < average[i].Nmissing - 1; j++, N++) {
-      next[N] = N + 1;
+      next_miss[N] = N + 1;
     }
     if (average[i].Nmissing > 0) {
-      next[N] = -1;
+      next_miss[N] = -1;
       if (N >= Nmissing) {
 	fprintf (stderr, "overflow in init_missing_links");
@@ -183,29 +183,29 @@
 
   }
-  return (next);
-}
-
-int add_miss_link (Average *average, int *next, int Nmissing) {
-
-  int k, m;
+  return (next_miss);
+}
+
+off_t add_miss_link (Average *average, off_t *next_miss, off_t Nmissing) {
+
+  off_t k, m;
 
   /* there may be 0 Nmiss; this is not true for Nmeas */
   if (average[0].Nmissing < 1) {
     average[0].missingOffset = Nmissing;
-    next[Nmissing] = -1;
+    next_miss[Nmissing] = -1;
     return (TRUE);
   }
 
   m = average[0].missingOffset;  
-  for (k = 0; k < average[0].Nmissing - 1; k++) m = next[m];
+  for (k = 0; k < average[0].Nmissing - 1; k++) m = next_miss[m];
   /* set up references */
-  next[Nmissing] = -1;
-  next[m] = Nmissing;
+  next_miss[Nmissing] = -1;
+  next_miss[m] = Nmissing;
   return (TRUE);
 }
 
-Missing *sort_missing (Average *average, int Naverage, Missing *missing, int Nmissing, int *next) {
-
-  int i, k, n, N;
+Missing *sort_missing (Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next_miss) {
+
+  off_t i, k, n, N;
   Missing *tmpmissing;
 
@@ -218,5 +218,5 @@
     for (k = 0; k < average[i].Nmissing; k++, N++) {
       tmpmissing[N] = missing[n]; 
-      n = next[n];
+      n = next_miss[n];
     }
   }
Index: trunk/Ohana/src/addstar/src/calibrate.c
===================================================================
--- trunk/Ohana/src/addstar/src/calibrate.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/calibrate.c	(revision 27435)
@@ -2,5 +2,6 @@
 
 static int InternalCal;
-static int Ncal, NCAL, *Nstar;
+static int Ncal, NCAL;
+static off_t *Nstar;
 static float *Mobs, *dMobs, *Mref, *dMref, *Minst;
 
@@ -13,12 +14,12 @@
   NCAL = 1000;
   ALLOCATE (Mobs,  float,  NCAL);
-  ALLOCATE (dMobs, float, NCAL);
+  ALLOCATE (dMobs, float,  NCAL);
   ALLOCATE (Mref,  float,  NCAL);
   ALLOCATE (dMref, float,  NCAL);
   ALLOCATE (Minst, float,  NCAL);
-  ALLOCATE (Nstar, int, NCAL);
+  ALLOCATE (Nstar, off_t,  NCAL);
 }
   
-void SaveCalibration (float Mo, float dMo, float Mr, float dMr, float Mi, int N) {
+void SaveCalibration (float Mo, float dMo, float Mr, float dMr, float Mi, off_t N) {
 
   Mobs[Ncal]  = Mo;
@@ -37,10 +38,10 @@
     REALLOCATE (dMref, float, NCAL);
     REALLOCATE (Minst, float, NCAL);
-    REALLOCATE (Nstar, int,   NCAL);
+    REALLOCATE (Nstar, off_t, NCAL);
   }
 }
 
 /* use the linked list to navigate the measures; safe for unsorted measures */
-void AddToCalibration (Average *average, SecFilt *secfilt, Measure *measure, Measure *new, int *next, int Nstar) {
+void AddToCalibration (Average *average, SecFilt *secfilt, Measure *measure, Measure *new, off_t *next, off_t Nstar) {
 
   int i, j, m, Nsec, found0, found1, found2;
Index: trunk/Ohana/src/addstar/src/dump.c
===================================================================
--- trunk/Ohana/src/addstar/src/dump.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/dump.c	(revision 27435)
@@ -1,7 +1,7 @@
 # include "addstar.h"
 
-int dump_rawstars (Stars *stars, int Nstars) {
+int dump_rawstars (Stars *stars, unsigned int Nstars) {
 
-  int i;
+  unsigned int i;
   FILE *f;
 
Index: trunk/Ohana/src/addstar/src/fakeimage.c
===================================================================
--- trunk/Ohana/src/addstar/src/fakeimage.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/fakeimage.c	(revision 27435)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-Image *fakeimage (char *rootname, int *Nimage, int photcode) {
+Image *fakeimage (char *rootname, off_t *Nimage, int photcode) {
 
   int i, j, Nx, Ny, Nchips;
Index: trunk/Ohana/src/addstar/src/find_matches.c
===================================================================
--- trunk/Ohana/src/addstar/src/find_matches.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/find_matches.c	(revision 27435)
@@ -1,12 +1,12 @@
 # include "addstar.h"
 
-int find_matches (SkyRegion *region, Stars *stars, int NstarsIn, Catalog *catalog, AddstarClientOptions options) {
-
-  int i, j, n, N, J, status, Nstars;
+int find_matches (SkyRegion *region, Stars *stars, unsigned int NstarsIn, Catalog *catalog, AddstarClientOptions options) {
+
+  off_t i, j, n, N, J, status, Nstars;
   double RADIUS, RADIUS2;
   double *X1, *Y1, *X2, *Y2;
   double dX, dY, dR;
-  int *N1, *N2, *next_meas;
-  int Nave, NAVE, Nmeas, NMEAS, Nmatch;
+  off_t *N1, *N2, *next_meas;
+  off_t Nave, NAVE, Nmeas, NMEAS, Nmatch;
   int Nsecfilt, Nsec;
   unsigned int objID, catID;
@@ -29,5 +29,5 @@
   ALLOCATE (X1, double, NstarsIn);
   ALLOCATE (Y1, double, NstarsIn);
-  ALLOCATE (N1, int,    NstarsIn);
+  ALLOCATE (N1, off_t,  NstarsIn);
 
   /** allocate local arrays (catalog) **/
@@ -35,6 +35,6 @@
   ALLOCATE (X2, double, NAVE);
   ALLOCATE (Y2, double, NAVE);
-  ALLOCATE (N2, int,   NAVE);
-  ALLOCATE (catalog[0].found, int, NAVE);
+  ALLOCATE (N2, off_t,  NAVE);
+  ALLOCATE (catalog[0].found, off_t, NAVE);
   /* for secfilt j and star i, secfilt[i*Nsecfilt+j] */
 
@@ -146,5 +146,5 @@
       if (Nmeas >= NMEAS) {
 	NMEAS = Nmeas + 1000;
-	REALLOCATE (next_meas, int, NMEAS);
+	REALLOCATE (next_meas, off_t, NMEAS);
 
 	REALLOCATE (catalog[0].measure, Measure, NMEAS);
@@ -238,5 +238,5 @@
     if (Nmeas >= NMEAS - NSTAR_GROUP) {
       NMEAS = Nmeas + 1000;
-      REALLOCATE (next_meas, int, NMEAS);
+      REALLOCATE (next_meas, off_t, NMEAS);
       REALLOCATE (catalog[0].measure, Measure, NMEAS);
     }
@@ -352,5 +352,5 @@
   catalog[0].Nmeasure = Nmeas;
   catalog[0].Nsecf_mem = Nave*Nsecfilt;
-  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmatch);
+  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %lld %lld %lld, (%lld matches)\n", (long long) Nstars, (long long) Nave, (long long) Nmeas, (long long) Nmatch);
 
   free (catalog[0].found);
Index: trunk/Ohana/src/addstar/src/find_matches_closest.c
===================================================================
--- trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 27435)
@@ -1,12 +1,12 @@
 # include "addstar.h"
 
-int find_matches_closest (SkyRegion *region, Stars *stars, int NstarsIn, Catalog *catalog, AddstarClientOptions options) {
-
-  int i, j, n, N, J, Jmin, status, Nstars;
+int find_matches_closest (SkyRegion *region, Stars *stars, unsigned int NstarsIn, Catalog *catalog, AddstarClientOptions options) {
+  
+  off_t i, j, n, N, J, Jmin, status, Nstars;
   double RADIUS, RADIUS2, Rmin;
   double *X1, *Y1, *X2, *Y2;
   double dX, dY, dR;
-  int *N1, *N2,  *next_meas;
-  int Nave, NAVE, Nmeas, NMEAS, Nmatch;
+  off_t *N1, *N2, *next_meas;
+  off_t Nave, NAVE, Nmeas, NMEAS, Nmatch;
   int Nsecfilt, Nsec;
   unsigned int objID, catID;
@@ -29,5 +29,5 @@
   ALLOCATE (X1, double, NstarsIn);
   ALLOCATE (Y1, double, NstarsIn);
-  ALLOCATE (N1, int,    NstarsIn);
+  ALLOCATE (N1, off_t,  NstarsIn);
 
   /** allocate local arrays (catalog) **/
@@ -35,6 +35,6 @@
   ALLOCATE (X2, double, NAVE);
   ALLOCATE (Y2, double, NAVE);
-  ALLOCATE (N2, int,   NAVE);
-  ALLOCATE (catalog[0].found, int, NAVE);
+  ALLOCATE (N2, off_t,  NAVE);
+  ALLOCATE (catalog[0].found, off_t, NAVE);
   /* for secfilt j and star i, secfilt[i*Nsecfilt+j] */
 
@@ -161,5 +161,5 @@
     if (Nmeas >= NMEAS) {
       NMEAS = Nmeas + 1000;
-      REALLOCATE (next_meas, int, NMEAS);
+      REALLOCATE (next_meas, off_t, NMEAS);
       REALLOCATE (catalog[0].measure, Measure, NMEAS);
     }
@@ -198,4 +198,5 @@
 	       X1[i], X2[Jmin], 
 	       Y1[i], Y2[Jmin]);
+	// XXX abort on this? -- this is a bad failure...
     }
 
@@ -232,5 +233,5 @@
     if (Nmeas >= NMEAS - NSTAR_GROUP) {
       NMEAS = Nmeas + 1000;
-      REALLOCATE (next_meas, int, NMEAS);
+      REALLOCATE (next_meas, off_t, NMEAS);
       REALLOCATE (catalog[0].measure, Measure, NMEAS);
     }
@@ -273,10 +274,8 @@
     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);
+        catalog[0].average[Nave].extID = CreatePSPSObjectID(catalog[0].average[Nave].R, catalog[0].average[Nave].D);
     } else {
-        catalog[0].average[Nave].extID         = 0;
-    }
-
+        catalog[0].average[Nave].extID = 0;
+    }
 
     objID ++;
@@ -347,5 +346,5 @@
   catalog[0].Nmeasure = Nmeas;
   catalog[0].Nsecf_mem = Nave*Nsecfilt;
-  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmatch);
+  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %lld %lld %lld, (%lld matches)\n", (long long) Nstars, (long long) Nave, (long long) Nmeas, (long long) Nmatch);
 
   free (catalog[0].found);
Index: trunk/Ohana/src/addstar/src/find_matches_closest_refstars.c
===================================================================
--- trunk/Ohana/src/addstar/src/find_matches_closest_refstars.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/find_matches_closest_refstars.c	(revision 27435)
@@ -1,12 +1,12 @@
 # include "addstar.h"
 
-int find_matches_closest_refstars (SkyRegion *region, Stars **stars, int NstarsIn, Catalog *catalog, AddstarClientOptions options) {
-
-  int i, j, n, N, J, Jmin, status;
+int find_matches_closest_refstars (SkyRegion *region, Stars **stars, unsigned int NstarsIn, Catalog *catalog, AddstarClientOptions options) {
+
+  off_t i, j, n, N, J, Jmin, status;
   double RADIUS, RADIUS2, Rmin;
   double *X1, *Y1, *X2, *Y2;
   double dX, dY, dR;
-  int *N1, *N2, *next_meas;
-  int Nave, NAVE, Nmeas, NMEAS, Nstars, Nmatch;
+  off_t *N1, *N2, *next_meas;
+  off_t Nave, NAVE, Nmeas, NMEAS, Nstars, Nmatch;
   unsigned int objID, catID;
   Coords tcoords;
@@ -24,5 +24,5 @@
   ALLOCATE (X1, double, NstarsIn);
   ALLOCATE (Y1, double, NstarsIn);
-  ALLOCATE (N1, int,    NstarsIn);
+  ALLOCATE (N1, off_t,  NstarsIn);
 
   /** allocate local arrays (catalog) **/
@@ -30,6 +30,6 @@
   ALLOCATE (X2, double, NAVE);
   ALLOCATE (Y2, double, NAVE);
-  ALLOCATE (N2, int, NAVE);
-  ALLOCATE (catalog[0].found, int, NAVE);
+  ALLOCATE (N2, off_t,  NAVE);
+  ALLOCATE (catalog[0].found, off_t, NAVE);
   /* for secfilt j and star i, secfilt[i*Nsecfilt+j] */
 
@@ -164,5 +164,5 @@
     if (Nmeas >= NMEAS) {
       NMEAS = Nmeas + 1000;
-      REALLOCATE (next_meas, int, NMEAS);
+      REALLOCATE (next_meas, off_t, NMEAS);
       REALLOCATE (catalog[0].measure, Measure, NMEAS);
     }
@@ -239,5 +239,5 @@
     if (Nmeas >= NMEAS - NREFSTAR_GROUP) {
       NMEAS = Nmeas + 1000;
-      REALLOCATE (next_meas, int, NMEAS);
+      REALLOCATE (next_meas, off_t, NMEAS);
       REALLOCATE (catalog[0].measure, Measure, NMEAS);
     }
@@ -329,4 +329,7 @@
       Nmeas ++;
     }
+    for (j = 0; j < NREFSTAR_GROUP - 1; j++) {
+	next_meas[Nmeas - NREFSTAR_GROUP + j] = Nmeas - NREFSTAR_GROUP + j + 1;
+    }
     Nave ++;
   }
@@ -351,5 +354,5 @@
   catalog[0].Nmeasure = Nmeas;
   catalog[0].Nsecf_mem = Nave*Nsecfilt;
-  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmatch);
+  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %lld %lld %lld, (%lld matches)\n", (long long) Nstars, (long long) Nave, (long long) Nmeas, (long long) Nmatch);
 
   free (catalog[0].found);
Index: trunk/Ohana/src/addstar/src/find_matches_refstars.c
===================================================================
--- trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 27435)
@@ -1,12 +1,12 @@
 # include "addstar.h"
 
-int find_matches_refstars (SkyRegion *region, Stars **stars, int Nstars, Catalog *catalog, AddstarClientOptions options) {
-
-  int i, j, n, N, J;
+int find_matches_refstars (SkyRegion *region, Stars **stars, unsigned int Nstars, Catalog *catalog, AddstarClientOptions options) {
+
+  off_t i, j, n, N, J;
   double RADIUS, RADIUS2;
   double *X1, *Y1, *X2, *Y2;
   double dX, dY, dR;
-  int *N1, *N2,  *next_meas;
-  int Nave, NAVE, Nmeas, NMEAS, Nmatch;
+  off_t *N1, *N2,  *next_meas;
+  off_t Nave, NAVE, Nmeas, NMEAS, Nmatch;
   unsigned int objID, catID;
   Coords tcoords;
@@ -24,5 +24,5 @@
   ALLOCATE (X1, double, Nstars);
   ALLOCATE (Y1, double, Nstars);
-  ALLOCATE (N1, int,   Nstars);
+  ALLOCATE (N1, off_t,  Nstars);
 
   /** allocate local arrays (catalog) **/
@@ -31,6 +31,6 @@
   ALLOCATE (X2, double, NAVE);
   ALLOCATE (Y2, double, NAVE);
-  ALLOCATE (N2, int, NAVE);
-  ALLOCATE (catalog[0].found, int, NAVE);
+  ALLOCATE (N2, off_t,  NAVE);
+  ALLOCATE (catalog[0].found, off_t, NAVE);
   REALLOCATE (catalog[0].average, Average, NAVE);
   REALLOCATE (catalog[0].secfilt, SecFilt, NAVE*catalog[0].Nsecfilt);
@@ -124,5 +124,5 @@
       if (Nmeas == NMEAS) {
 	NMEAS = Nmeas + 1000;
-	REALLOCATE (next_meas, int, NMEAS);
+	REALLOCATE (next_meas, off_t, NMEAS);
 	REALLOCATE (catalog[0].measure, Measure, NMEAS);
       }
@@ -209,5 +209,5 @@
     if (Nmeas >= NMEAS - NREFSTAR_GROUP) {
       NMEAS = Nmeas + 1000;
-      REALLOCATE (next_meas, int, NMEAS);
+      REALLOCATE (next_meas, off_t, NMEAS);
       REALLOCATE (catalog[0].measure, Measure, NMEAS);
     }
@@ -325,5 +325,5 @@
   catalog[0].Nmeasure = Nmeas;
   catalog[0].Nsecf_mem = Nave*Nsecfilt;
-  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmatch);
+  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %lld %lld %lld, (%lld matches)\n", (long long) Nstars, (long long) Nave, (long long) Nmeas, (long long) Nmatch);
 
   free (catalog[0].found);
Index: trunk/Ohana/src/addstar/src/find_subset.c
===================================================================
--- trunk/Ohana/src/addstar/src/find_subset.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/find_subset.c	(revision 27435)
@@ -2,5 +2,5 @@
 
 /* find stars within this region */
-Stars **find_subset (SkyRegion *region, Stars *stars, int Nstars, int *Nsubset) {
+Stars **find_subset (SkyRegion *region, Stars *stars, unsigned int Nstars, unsigned int *Nsubset) {
 
   int i, N, NSUBSET;
Index: trunk/Ohana/src/addstar/src/get2mass.c
===================================================================
--- trunk/Ohana/src/addstar/src/get2mass.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/get2mass.c	(revision 27435)
@@ -2,5 +2,5 @@
 # include "2mass.h"
 
-Stars *get2mass (SkyRegion *patch, int photcode, int mode, int *NSTARS) {
+Stars *get2mass (SkyRegion *patch, int photcode, int mode, unsigned int *NSTARS) {
   
   char *path;
Index: trunk/Ohana/src/addstar/src/getgsc.c
===================================================================
--- trunk/Ohana/src/addstar/src/getgsc.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/getgsc.c	(revision 27435)
@@ -7,7 +7,7 @@
 static SkyTable *sky = NULL;
 
-Stars *getgsc (SkyRegion *patch, int *NSTARS) {
+Stars *getgsc (SkyRegion *patch, unsigned int *NSTARS) {
   
-  int i, Ngsc, Nstars; 
+  unsigned int i, Ngsc, Nstars; 
   Stars *gsc;
   Stars *stars;
@@ -45,5 +45,5 @@
 }  
 
-Stars *rd_gsc (char *filename, int *nstars) {
+Stars *rd_gsc (char *filename, unsigned int *nstars) {
   
   int i, NSTARS, Nstars, Nbytes, nbytes, Nline, Nbyte;
Index: trunk/Ohana/src/addstar/src/gettycho.c
===================================================================
--- trunk/Ohana/src/addstar/src/gettycho.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/gettycho.c	(revision 27435)
@@ -6,5 +6,5 @@
 static SkyTable *tychoTable = NULL;
 
-Stars *gettycho (SkyRegion *catstats, int photcode, int *nstars) {
+Stars *gettycho (SkyRegion *catstats, int photcode, unsigned int *nstars) {
 
   int i, j, nitems;
@@ -13,5 +13,5 @@
   FILE *f;
   int NTYCHO, Ntycho;
-  int firstRow, firstByte;
+  off_t firstRow, firstByte;
   short int TYCHO_B, TYCHO_V;
   e_time TychoEpoch;
@@ -60,7 +60,7 @@
 			  region[0].Rmin, region[0].Rmax, region[0].Dmin, region[0].Dmax);
 
-    firstRow  = atoi (region[0].name);
+    firstRow  = strtol (region[0].name, NULL, 0);
     firstByte = firstRow * NBYTE;
-    fseek (f, firstByte, SEEK_SET);
+    fseeko (f, firstByte, SEEK_SET);
 
     while (1) {
Index: trunk/Ohana/src/addstar/src/getusno.c
===================================================================
--- trunk/Ohana/src/addstar/src/getusno.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/getusno.c	(revision 27435)
@@ -4,7 +4,7 @@
 # define NELEM  3
 
-Stars *getusno (SkyRegion *catstats, int photcode, int *nstars) {
+Stars *getusno (SkyRegion *catstats, int photcode, unsigned int *nstars) {
 
-  long int offset;
+  off_t offset;
   int i, bin, first, last, nitems, Nitems, Nbins, Nstars;
   float hours[100];
@@ -84,5 +84,5 @@
     /* advance file pointer to first slice */
     offset = NELEM*NBYTE*(start[first] - 1);
-    fseek (f, offset, SEEK_SET);
+    fseeko (f, offset, SEEK_SET);
 
     /* sum the number of stars in data segment of interest */
Index: trunk/Ohana/src/addstar/src/getusnob.c
===================================================================
--- trunk/Ohana/src/addstar/src/getusnob.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/getusnob.c	(revision 27435)
@@ -3,7 +3,7 @@
 # define NELEM  20
 
-Stars *getusnob (SkyRegion *catstats, int photcode, int *nstars) {
+Stars *getusnob (SkyRegion *catstats, int photcode, unsigned int *nstars) {
 
-  long int offset;
+  off_t offset;
   int i, bin, first, last, nitems, Nitems, Nbins, Nitemsum;
   float hours[100];
@@ -93,5 +93,5 @@
     /* advance file pointer to first slice */
     offset = NELEM*NBYTE*(start[first] - 1);
-    fseek (f, offset, SEEK_SET);
+    fseeko (f, offset, SEEK_SET);
 
     /* sum the number of stars in data segment of interest */
Index: trunk/Ohana/src/addstar/src/greference.c
===================================================================
--- trunk/Ohana/src/addstar/src/greference.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/greference.c	(revision 27435)
@@ -3,7 +3,7 @@
 # define LOAD_DR2    1
 
-Stars *greference (char *Refcat, SkyRegion *region, int photcode, int *nstars) {
+Stars *greference (char *Refcat, SkyRegion *region, int photcode, unsigned int *nstars) {
 
-  int Nstars;
+  unsigned int Nstars;
   Stars *stars;
 
Index: trunk/Ohana/src/addstar/src/grefstars.c
===================================================================
--- trunk/Ohana/src/addstar/src/grefstars.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/grefstars.c	(revision 27435)
@@ -2,5 +2,5 @@
 
 /* read ASCII file with ref star data */
-Stars *grefstars (char *file, int photcode, int *Nstars) {
+Stars *grefstars (char *file, int photcode, unsigned int *Nstars) {
 
   FILE *f;
Index: trunk/Ohana/src/addstar/src/gztest.c
===================================================================
--- trunk/Ohana/src/addstar/src/gztest.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/gztest.c	(revision 27435)
@@ -5,5 +5,6 @@
 main (int argc, char **argv) {
 
-  int N, Nread, Nseek, Nback;
+  off_t Nseek, Nback;
+  int N, Nread;
   char *filename, *buffer;
   gzFile gf;
@@ -66,5 +67,5 @@
 
     gettimeofday (&start, NULL);
-    N = fseek (f, Nseek, SEEK_SET);
+    N = fseeko (f, Nseek, SEEK_SET);
     gettimeofday (&stop, NULL);
     if (N) {
@@ -84,5 +85,5 @@
 
     gettimeofday (&start, NULL);
-    N = fseek (f, Nback, SEEK_CUR);
+    N = fseeko (f, Nback, SEEK_CUR);
     gettimeofday (&stop, NULL);
     if (N) {
Index: trunk/Ohana/src/addstar/src/mkcmf.c
===================================================================
--- trunk/Ohana/src/addstar/src/mkcmf.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/mkcmf.c	(revision 27435)
@@ -19,5 +19,5 @@
   // load a text table with X,Y,Mag (instrumental?)
 
-  int i, N, Nstars, NSTARS;
+  int i, N, Nstars, NSTARS, found;
   double *X, *Y, *M;
   double Xmax, Ymax;
@@ -56,6 +56,16 @@
   }
 
+  // add support for all cmf types
+  static char *type = "PS1_DEV_1";
+  if ((N = get_argument (argc, argv, "-type"))) {
+    remove_argument (N, &argc, argv);
+    type = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+    fprintf (stderr, "support for other types is broken: see comment at line 97\n");
+    exit (1);
+  }
+
   if (argc != 3) {
-    fprintf (stderr, "USAGE mkcmf (input) (output) [-date date] [-time time] [-radec ra dec]\n");
+    fprintf (stderr, "USAGE mkcmf (input) (output) [-date date] [-time time] [-radec ra dec] [-cmftype type]\n");
     exit (2);
   }
@@ -86,4 +96,5 @@
 
   // XXX add gaussian-distributed noise based on counts
+  // this needs to make different output 'stars' entries depending on the desired type
   ALLOCATE (stars, PS1_DEV_1, Nstars);
   gauss_init (2048);
@@ -162,8 +173,38 @@
 
   ftable.header = &theader;
-  gfits_table_set_PS1_DEV_1 (&ftable, stars, Nstars);
+
+  // set up desired CMF type:
+  found = FALSE;
+# if 0
+  if (!strcmp(type, "PS1_DEV_0")) {
+    gfits_table_set_PS1_DEV_0 (&ftable, stars, Nstars);
+    gfits_modify (&theader, "EXTTYPE",   "%s", 1, "PS1_DEV_0");
+    found = TRUE;
+  }
+# endif
+  if (!strcmp(type, "PS1_DEV_1")) {
+    gfits_table_set_PS1_DEV_1 (&ftable, stars, Nstars);
+    gfits_modify (&theader, "EXTTYPE",   "%s", 1, "PS1_DEV_1");
+    found = TRUE;
+  }
+# if 0
+  if (!strcmp(type, "PS1_V1")) {
+    gfits_table_set_CMF_PS1_V1 (&ftable, stars, Nstars);
+    gfits_modify (&theader, "EXTTYPE",   "%s", 1, "PS1_V1");
+    found = TRUE;
+  }
+  if (!strcmp(type, "PS1_V2")) {
+    gfits_table_set_CMF_PS1_V2 (&ftable, stars, Nstars);
+    gfits_modify (&theader, "EXTTYPE",   "%s", 1, "PS1_V2");
+    found = TRUE;
+  }
+# endif
+  if (!found) {
+    fprintf (stderr, "ERROR: unknown CMF type %s\n", type);
+    exit (1);
+  }
+
+  gfits_modify (&theader, "EXTHEAD",   "%s", 1, "Chip.hdr");
   gfits_modify (&theader, "EXTNAME",   "%s", 1, "Chip.psf");
-  gfits_modify (&theader, "EXTTYPE",   "%s", 1, "PS1_DEV_1");
-  gfits_modify (&theader, "EXTHEAD",   "%s", 1, "Chip.hdr");
 
   fits = fopen (argv[2], "w");
Index: trunk/Ohana/src/addstar/src/resort_catalog.c
===================================================================
--- trunk/Ohana/src/addstar/src/resort_catalog.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/resort_catalog.c	(revision 27435)
@@ -3,6 +3,6 @@
 void resort_catalog (Catalog *catalog) {
 
-  int *next_meas;
-  int Naves, Nmeas;
+  off_t *next_meas;
+  off_t Naves, Nmeas;
   double dtime;
   struct timeval start, stop;
@@ -24,5 +24,5 @@
   gettimeofday (&stop, NULL);
   dtime = DTIME (stop, start);
-  fprintf (stderr, "  match time %9.4f sec for %7d measures, %6d average\n", dtime, Nmeas, Naves);
+  fprintf (stderr, "  match time %9.4f sec for %7lld measures, %6lld average\n", dtime, (long long) Nmeas, (long long) Naves);
 
   return;
Index: trunk/Ohana/src/addstar/src/sky_tessalation.c
===================================================================
--- trunk/Ohana/src/addstar/src/sky_tessalation.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/sky_tessalation.c	(revision 27435)
@@ -947,9 +947,9 @@
   }
   REALLOCATE (db[0].vtable.buffer, char *, 1);
-  REALLOCATE (db[0].vtable.row, int, 1);
+  REALLOCATE (db[0].vtable.row, off_t, 1);
   db[0].vtable.Nrow   = 0;
 
   // reset db[0].theader(NAXIS1) to match Image
-  gfits_modify (&db[0].theader, "NAXIS1", "%d", 1, sizeof(Image));
+  gfits_modify (&db[0].theader, "NAXIS1", "%lld", 1, (long long) sizeof(Image));
   db[0].theader.Naxis[0] = sizeof(Image);
 
Index: trunk/Ohana/src/addstar/src/update_coords.c
===================================================================
--- trunk/Ohana/src/addstar/src/update_coords.c	(revision 27392)
+++ trunk/Ohana/src/addstar/src/update_coords.c	(revision 27435)
@@ -2,7 +2,7 @@
 
 /* find the average and scatter for R and D - no outlier rejection */
-void update_coords (Average *average, Measure *measure, int *next) {
+void update_coords (Average *average, Measure *measure, off_t *next) {
 
-  int i, m, Npt;
+  off_t i, m, Npt;
   double R, D, r, d;
   double r2, d2, dR2, dD2;
Index: trunk/Ohana/src/addstar/test/addstar.sh
===================================================================
--- trunk/Ohana/src/addstar/test/addstar.sh	(revision 27392)
+++ 	(revision )
@@ -1,58 +1,0 @@
-
-macro test.measure.basic
-  
-  $PASS = 1
-
-  catdir catdir.test
-  skyregion 9 11 19 21
-
-  mextract ra, dec, xccd, yccd, mag:inst, mag, mag:err, time, photcode
-
-  if (ra[] != 242) 
-    $PASS = 0
-    echo "found the wrong number of measurements in db"
-  end
-
-  avextract ra, dec
-
-  if (ra[] != 242) 
-    $PASS = 0
-    echo "found the wrong number of stars in db"
-  end
-
-  ### XXX write down some tests of things we know about the input data values
-  ### XXX probably need to add options to mkcmf to eliminate poisson error
-end
-
-# create a populated catdir with a couple of cmf files
-macro mkcatdir
-
-  exec rm -rf catdir.test
-
-  mkinput
-  exec mkcmf test.in.txt test.1.cmf -date 2008/1/1 -time 01:00:00 -radec 10.0 20.0
-  exec mkcmf test.in.txt test.2.cmf -date 2008/1/1 -time 02:00:00 -radec 10.0 20.0
-
-  exec addstar -D CATDIR catdir.test -D CAMERA simtest test.1.cmf
-  exec addstar -D CATDIR catdir.test -D CAMERA simtest test.2.cmf
-end
-
-# make a simple input file for mkcmf
-macro mkinput
-  exec rm -f test.in.txt
-
-  output test.in.txt
-  for i 10 1024 100
-    for j 10 1024 100
-      fprintf " %4d %4d  %6.2f" $i $j {-15.0 + 2.5*($i + $j)/1000.0}
-    end
-  end
-  output stdout
-end
-
-macro showinput
-   data test.in.txt 
-   read x 1 y 2 m 3
-   lim x y; clear; box; zplot -pt 7 x y m -10 -15
-end
-
Index: trunk/Ohana/src/addstar/test/addstar.tests.txt
===================================================================
--- trunk/Ohana/src/addstar/test/addstar.tests.txt	(revision 27435)
+++ trunk/Ohana/src/addstar/test/addstar.tests.txt	(revision 27435)
@@ -0,0 +1,10 @@
+
+# addstar tests:
+
+1) simple ingest
+   * create a fake input and ingest into a dvo database
+   * check all fields in the input file against the dvo database
+
+2) addstar matches:
+  * ingest fake cmf 2x
+  * check for 
Index: trunk/Ohana/src/addstar/test/dvomerge.dvo
===================================================================
--- trunk/Ohana/src/addstar/test/dvomerge.dvo	(revision 27435)
+++ trunk/Ohana/src/addstar/test/dvomerge.dvo	(revision 27435)
@@ -0,0 +1,256 @@
+# -*-sh-*-
+
+input tap.dvo
+
+# create 2 populated catdirs, each with a couple of cmf files
+macro test.dvomerge.update
+
+  tapPLAN 51
+
+  exec rm -rf catdir.test1
+  exec rm -rf catdir.test2
+  exec rm -rf catdir.test3
+
+  $RA = 10.0
+  $DEC = 20.0
+
+  mkinput
+  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC
+  exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
+
+  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 02:00:00 -radec $RA $DEC
+  exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
+
+  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 03:00:00 -radec $RA $DEC
+  exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
+
+  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 04:00:00 -radec $RA $DEC
+  exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
+
+  exec rsync -auc catdir.test2/ catdir.test3/
+
+  exec dvomerge catdir.test1 into catdir.test3
+
+  catdir catdir.test3
+  skyregion {$RA-1} {$RA+1} {$DEC-1} {$DEC+1} 
+  mextract ra dec mag
+  create n 0 ra[]
+  subset r0 = ra if (n % 4 == 0)
+  subset r1 = ra if (n % 4 == 1)
+  subset r2 = ra if (n % 4 == 2)
+  subset r3 = ra if (n % 4 == 3)
+
+  catdir catdir.test1/
+  mextract RA DEC MAG
+  create N 0 RA[]
+  subset R0 = RA if (N % 2 == 0)
+  subset R1 = RA if (N % 2 == 1)
+
+  set dr0 = r0 - R0
+  vstat -q dr0
+  tapOK {abs($MEAN)  < 0.001} "ra (in - 0) vs ra (out - 0) (MEAN)"
+  tapOK {abs($SIGMA) < 0.001} "ra (in - 0) vs ra (out - 0) (SIGMA)"
+
+  set dr1 = r1 - R1
+  vstat -q dr1
+  tapOK {abs($MEAN)  < 0.001} "ra (in - 0) vs ra (out - 0) (MEAN)"
+  tapOK {abs($SIGMA) < 0.001} "ra (in - 0) vs ra (out - 0) (SIGMA)"
+
+  catdir catdir.test2/
+  mextract RA DEC MAG
+  create N 0 RA[]
+  subset R2 = RA if (N % 2 == 0)
+  subset R3 = RA if (N % 2 == 1)
+
+  set dr2 = r2 - R2
+  vstat -q dr2
+  tapOK {abs($MEAN)  < 0.001} "ra (in - 0) vs ra (out - 0) (MEAN)"
+  tapOK {abs($SIGMA) < 0.001} "ra (in - 0) vs ra (out - 0) (SIGMA)"
+
+  set dr3 = r3 - R3
+  vstat -q dr3
+  tapOK {abs($MEAN)  < 0.001} "ra (in - 0) vs ra (out - 0) (MEAN)"
+  tapOK {abs($SIGMA) < 0.001} "ra (in - 0) vs ra (out - 0) (SIGMA)"
+
+  # check on updates to imageID
+  catdir catdir.test3
+  imextract imageID
+  sort imageID
+  tapOK {imageID[]  == 4} "image IDs exist"
+  tapOK {imageID[0] == 1} "updated image IDs"
+  tapOK {imageID[1] == 2} "updated image IDs"
+  tapOK {imageID[2] == 3} "updated image IDs"
+  tapOK {imageID[3] == 4} "updated image IDs"
+
+  catdir catdir.test3
+  mextract imageID, time
+  set id = imageID
+  set t = time
+  imextract imageID, time
+
+  for i 0 time[]
+    subset T = t if (id == imageID[$i])
+    set dT = T - time[$i]
+    vstat -q dT 
+    tapOK {abs($MEAN)  < 0.00001} "time for measure ID $i (MEAN)"
+    tapOK {abs($SIGMA) < 0.00001} "time for measure ID $i (SIGMA)"
+  end
+
+  # exec rm test.in.txt test.cmf
+  # exec rm -rf catdir.test1
+  # exec rm -rf catdir.test2
+  # exec rm -rf catdir.test3
+
+  tapDONE
+end
+
+# create 2 populated catdirs, each with a couple of cmf files
+macro test.dvomerge.create
+
+  tapPLAN 21
+
+  exec rm -rf catdir.test1
+  exec rm -rf catdir.test2
+  exec rm -rf catdir.test3
+
+  $RA = 10.0
+  $DEC = 20.0
+
+  mkinput
+  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC
+  exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
+
+  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 02:00:00 -radec $RA $DEC
+  exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
+
+  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 03:00:00 -radec $RA $DEC
+  exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
+
+  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 04:00:00 -radec $RA $DEC
+  exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
+
+  exec dvomerge catdir.test1 and catdir.test2 to catdir.test3
+
+  catdir catdir.test3
+  skyregion {$RA-1} {$RA+1} {$DEC-1} {$DEC+1} 
+  mextract ra dec mag
+  create n 0 ra[]
+  subset r0 = ra if (n % 4 == 0)
+  subset r1 = ra if (n % 4 == 1)
+  subset r2 = ra if (n % 4 == 2)
+  subset r3 = ra if (n % 4 == 3)
+
+  catdir catdir.test1/
+  mextract RA DEC MAG
+  create N 0 RA[]
+  subset R0 = RA if (N % 2 == 0)
+  subset R1 = RA if (N % 2 == 1)
+
+  set dr0 = r0 - R0
+  vstat -q dr0
+  tapOK {abs($MEAN)  < 0.001} "ra (in - 0) vs ra (out - 0) (MEAN)"
+  tapOK {abs($SIGMA) < 0.001} "ra (in - 0) vs ra (out - 0) (SIGMA)"
+
+  set dr1 = r1 - R1
+  vstat -q dr1
+  tapOK {abs($MEAN)  < 0.001} "ra (in - 0) vs ra (out - 0) (MEAN)"
+  tapOK {abs($SIGMA) < 0.001} "ra (in - 0) vs ra (out - 0) (SIGMA)"
+
+  catdir catdir.test2/
+  mextract RA DEC MAG
+  create N 0 RA[]
+  subset R2 = RA if (N % 2 == 0)
+  subset R3 = RA if (N % 2 == 1)
+
+  set dr2 = r2 - R2
+  vstat -q dr2
+  tapOK {abs($MEAN)  < 0.001} "ra (in - 0) vs ra (out - 0) (MEAN)"
+  tapOK {abs($SIGMA) < 0.001} "ra (in - 0) vs ra (out - 0) (SIGMA)"
+
+  set dr3 = r3 - R3
+  vstat -q dr3
+  tapOK {abs($MEAN)  < 0.001} "ra (in - 0) vs ra (out - 0) (MEAN)"
+  tapOK {abs($SIGMA) < 0.001} "ra (in - 0) vs ra (out - 0) (SIGMA)"
+
+  # check on updates to imageID
+  catdir catdir.test3
+  imextract imageID
+  sort imageID
+  tapOK {imageID[]  == 4} "image IDs exist"
+  tapOK {imageID[0] == 1} "updated image IDs"
+  tapOK {imageID[1] == 2} "updated image IDs"
+  tapOK {imageID[2] == 3} "updated image IDs"
+  tapOK {imageID[3] == 4} "updated image IDs"
+
+  catdir catdir.test3
+  mextract imageID, time
+  set id = imageID
+  set t = time
+  imextract imageID, time
+
+  for i 0 time[]
+    subset T = t if (id == imageID[$i])
+    set dT = T - time[$i]
+    vstat -q dT 
+    tapOK {abs($MEAN)  < 0.00001} "time for measure ID $i (MEAN)"
+    tapOK {abs($SIGMA) < 0.00001} "time for measure ID $i (SIGMA)"
+  end
+
+  # exec rm test.in.txt test.cmf
+  # exec rm -rf catdir.test1
+  # exec rm -rf catdir.test2
+  # exec rm -rf catdir.test3
+
+  tapDONE
+end
+
+# make a simple input file for mkcmf
+macro mkinput.alt
+  exec rm -f test.in.txt
+
+  output test.in.txt
+  for i 10 1024 400
+    for j 10 1024 400
+      fprintf " %4d %4d  %6.2f" $i $j {-15.0 + 2.5*($i + $j)/1000.0}
+    end
+  end
+  output stdout
+end
+
+# make a simple input file for mkcmf
+macro mkinput
+  exec rm -f test.in.txt
+
+  output test.in.txt
+  for i 10 1024 100
+    for j 10 1024 100
+      fprintf " %4d %4d  %6.2f" $i $j {-15.0 + 2.5*($i + $j)/1000.0}
+    end
+  end
+  output stdout
+end
+
+# list of cmf fields to test matched to mextract fields
+# this list is good for PS1_DEV_1
+list testfields
+  IPP_IDET          : detid
+  X_PSF             : xccd
+  Y_PSF             : yccd
+  X_PSF_SIG         : xccd:err
+  Y_PSF_SIG         : yccd:err
+  PSF_INST_MAG      : mag:inst
+  PSF_INST_MAG_SIG  : mag:err
+  PEAK_FLUX_AS_MAG  : SKIP
+  SKY               : sky
+  SKY_SIG           : sky_err
+  PSF_CHISQ         : psf_chisq
+  CR_NSIGMA         : cr_nsigma
+  EXT_NSIGMA        : ext_nsigma
+  PSF_WIDTH_X       : FWHM_MAJ
+  PSF_WIDTH_Y       : FWHM_MIN
+  PSF_THETA         : THETA
+  PSF_QF            : PSF_QF
+  N_FRAMES          : SKIP
+  FLAGS             : phot_flags
+end
+
Index: trunk/Ohana/src/addstar/test/relastro.dvo
===================================================================
--- trunk/Ohana/src/addstar/test/relastro.dvo	(revision 27435)
+++ trunk/Ohana/src/addstar/test/relastro.dvo	(revision 27435)
@@ -0,0 +1,137 @@
+# -*-sh-*-
+
+input tap.dvo
+
+# this set fails because the match radius does not equal the keep radius:
+list offset
+  0.0
+ -1.0
+  1.0
+  0.5
+  1.0
+  2.99
+end
+
+# offset values are in pixels
+list offset
+  0.0
+ -1.0
+  1.0
+  0.5
+  1.0
+  2.0
+end
+
+# offset values are in pixels
+list offset.small
+  0.5
+ -0.5
+  0.5
+  0.5
+end
+
+# create a populated catdir with a couple of cmf files
+macro test.relastro
+
+  tapPLAN 42
+
+  exec rm -rf catdir.test
+
+  $RA = 10.0
+  $DEC = 20.0
+  $dOFF = 0.15
+
+  for i 0 $offset:n
+    mkinput $offset:$i
+    exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time $i\:00:00 -radec $RA $DEC
+    exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf
+  end
+
+  rd im test.cmf -head
+  keyword im CDELT1 cdelt
+
+  catdir catdir.test
+  skyregion {$RA-1.0} {$RA+1.0} {$DEC-1.0} {$DEC+1.0} 
+
+  mextract RA DEC RA:AVE DEC:AVE dR dD
+  create n 0 RA[]
+
+  echo raw
+  for i 0 $offset:n
+    subset dr = dR if (n % $offset:n == $i)
+    vstat -q dr
+    # echo $offset:0 {$MEAN / (3600*$cdelt)} $offset:$i {abs($offset:0 - $MEAN / (3600*$cdelt) - $offset:$i)} 
+    tapOK {abs($offset:0 - $MEAN / (3600*$cdelt) - $offset:$i) < $dOFF} "raw dX $i = {$MEAN / (3600*$cdelt)} : {abs($offset:0 - $MEAN / (3600*$cdelt) - $offset:$i)}"
+  end
+
+  for N 0 3
+    exec relastro -D CATDIR catdir.test -region {$RA-1.0} {$RA+1.0} {$DEC-1.0} {$DEC+1.0} -update-objects -update -plot -plotdelay 1.0
+    mextract RA DEC RA:AVE DEC:AVE dR dD mag
+    create n 0 RA[]
+  
+    $dXmean = 0
+    for i 0 $offset:n
+      $dXmean = $dXmean + $offset:$i
+    end
+    $dXmean = $dXmean / $offset:n
+  
+    echo objects
+    for i 0 $offset:n
+      subset dr = dR if (n % $offset:n == $i)
+      vstat -q dr
+  
+      $dXexpect = $MEAN / (3600*$cdelt)
+      if ($N == 0)
+        $dXexpect = $dXmean - $MEAN / (3600*$cdelt) - $offset:$i 
+      end
+      # echo $dXmean {$MEAN / (3600*$cdelt)} $offset:$i  {$dXmean - $MEAN / (3600*$cdelt) - $offset:$i}
+      tapOK {abs($dXexpect) < $dOFF} "update objects dX $i = {$MEAN / (3600*$cdelt)} : $dXexpect"
+  
+      # subset ms = mag if (n % $offset:n == $i)
+      # lim ms dr; clear; box; plot ms dr
+      # cursor
+    end
+  
+    exec relastro -D CATDIR catdir.test -region {$RA-1.0} {$RA+1.0} {$DEC-1.0} {$DEC+1.0} -update-simple -update -plot -plotdelay 1.0
+    mextract RA DEC RA:AVE DEC:AVE dR dD
+    create n 0 RA[]
+  
+    echo simple
+    for i 0 $offset:n
+      subset dr = dR if (n % $offset:n == $i)
+      vstat -q dr
+  
+      $dXexpect = $MEAN / (3600*$cdelt)
+      # echo {$MEAN / (3600*$cdelt)}
+      tapOK {abs($dXexpect) < $dOFF} "update simple dX $i = {$MEAN / (3600*$cdelt)}"
+  
+      # subset ms = mag if (n % $offset:n == $i)
+      # lim ms dr; clear; box; plot ms dr
+      # cursor
+    end
+  end
+
+  exec rm test.cmf test.in.txt
+  exec rm -r catdir.test
+
+  tapDONE
+end
+
+# make a simple input file for mkcmf
+macro mkinput
+  if ($0 != 2)
+    echo "mkinput (offset)"
+    break
+  end
+
+  local i j
+  exec rm -f test.in.txt
+
+  output test.in.txt
+  for i 10 1024 100
+    for j 10 1024 100
+      fprintf " %6.1f %6.1f  %7.3f" {$i + $1} $j {-15.0 + 2.5*($i + $j)/1000.0}
+    end
+  end
+  output stdout
+end
Index: trunk/Ohana/src/addstar/test/relphot.dvo
===================================================================
--- trunk/Ohana/src/addstar/test/relphot.dvo	(revision 27435)
+++ trunk/Ohana/src/addstar/test/relphot.dvo	(revision 27435)
@@ -0,0 +1,62 @@
+# -*-sh-*-
+
+input tap.dvo
+
+list offset
+  0.000
+ -0.025
+  0.025
+  0.010
+end
+
+# create a populated catdir with a couple of cmf files
+macro test.relphot
+
+  tapPLAN 4
+
+  exec rm -rf catdir.test
+
+  $RA = 10.0
+  $DEC = 20.0
+
+  for i 0 $offset:n
+    mkinput $offset:$i
+    exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time $i\:00:00 -radec $RA $DEC
+    exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf 
+  end
+
+  exec relphot -D CATDIR catdir.test r -region {$RA-1.0} {$RA+1.0} {$DEC-1.0} {$DEC+1.0} -update -nloop 10.0 >& /dev/null
+
+  catdir catdir.test
+  skyregion {$RA-1.0} {$RA+1.0} {$DEC-1.0} {$DEC+1.0} 
+
+  imextract time Mcal
+
+  for i 0 $offset:n
+    tapOK {abs(Mcal[$i] - Mcal[0] - $offset:$i) < 0.001} "Mcal $i"
+  end
+
+  exec rm test.cmf test.in.txt
+  exec rm -r catdir.test
+
+  tapDONE
+end
+
+# make a simple input file for mkcmf
+macro mkinput
+  if ($0 != 2)
+    echo "mkinput (offset)"
+    break
+  end
+
+  exec rm -f test.in.txt
+
+  local i j
+  output test.in.txt
+  for i 10 1024 100
+    for j 10 1024 100
+      fprintf " %6.1f %6.1f  %7.3f" $i $j {-15.0 + $1 + 2.5*($i + $j)/1000.0}
+    end
+  end
+  output stdout
+end
Index: trunk/Ohana/src/addstar/test/simple.dvo
===================================================================
--- trunk/Ohana/src/addstar/test/simple.dvo	(revision 27435)
+++ trunk/Ohana/src/addstar/test/simple.dvo	(revision 27435)
@@ -0,0 +1,144 @@
+# -*-sh-*-
+
+input tap.dvo
+
+macro test.all
+  test.fields.type PS1_V1
+
+end  
+
+# create a populated catdir with a single cmf -- test each field
+macro test.fields.type
+  if ($0 != 2)
+    echo "USAGE: test.fields.type (cmftype) (dvotype?)"
+    break
+  end
+
+  tapPLAN 51
+
+  exec rm -rf catdir.test
+
+  $RA = 10.0
+  $DEC = 20.0
+
+  mkinput
+  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC -type $1
+  exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf
+
+  catdir catdir.test
+  skyregion {$RA-1.0} {$RA+1.0} {$DEC-1.0} {$DEC+1.0} 
+
+  data test.cmf
+
+  for i 0 $testfields:n
+    list name -split $testfields:$i
+    if ("$name:0" == "SKIP") continue
+    if ("$name:2" == "SKIP") continue
+    read -fits Chip.psf $name:0
+    mextract $name:2
+  end
+
+  # how is the detection ID?
+  list name -split $testfields:0
+  set ID1 = $name:0
+  set ID2 = $name:2
+  tapOK {ID1[] == ID2[]} "lengths for $name:0 vs $name:2"
+  if (not($TAP_LAST)) return
+
+  set d = $name:0 - $name:2
+  vstat -q d
+  tapOK {abs($MEAN)  < 0.001} "$name:0 vs $name:2 (MEAN)"
+  tapOK {abs($SIGMA) < 0.001} "$name:0 vs $name:2 (SIGMA)"
+
+  # detection ID must be first for this to work:
+  for i 1 $testfields:n
+    list name -split $testfields:$i
+    if ("$name:0" == "SKIP") continue
+    if ("$name:2" == "SKIP") continue
+    # must be the same length
+    set v1 = $name:0
+    set v2 = $name:2
+    tapOK {v1[] == v2[]} "lengths for $name:0 vs $name:2"
+    if (not($TAP_LAST)) continue
+
+    set id1 = ID1
+    set id2 = ID2
+    sort id1 v1
+    sort id2 v2
+    set d = v1 - v2
+    vstat -q d
+    
+    #echo tapOK fabs($MEAN)  < 0.001 "$name:0 vs $name:2 (MEAN)"
+    #echo tapOK fabs($SIGMA) < 0.001 "$name:0 vs $name:2 (SIGMA)"
+
+    tapOK {abs($MEAN)  < 0.001} "$name:0 vs $name:2 (MEAN)"
+    tapOK {abs($SIGMA) < 0.001} "$name:0 vs $name:2 (SIGMA)"
+  end    
+
+  exec rm test.cmf test.in.txt
+  exec rm -r catdir.test
+
+  tapDONE
+end
+
+# make a simple input file for mkcmf
+macro mkinput
+  exec rm -f test.in.txt
+
+  output test.in.txt
+  for i 10 1024 100
+    for j 10 1024 100
+      fprintf " %4d %4d  %6.2f" $i $j {-15.0 + 2.5*($i + $j)/1000.0}
+    end
+  end
+  output stdout
+end
+
+# list of cmf fields to test matched to mextract fields
+# this list is good for PS1_DEV_1
+list testfields_PS1_DEV_V1
+  IPP_IDET          : detid
+  X_PSF             : xccd
+  Y_PSF             : yccd
+  X_PSF_SIG         : xccd:err
+  Y_PSF_SIG         : yccd:err
+  PSF_INST_MAG      : mag:inst
+  PSF_INST_MAG_SIG  : mag:err
+  PEAK_FLUX_AS_MAG  : SKIP
+  SKY               : sky
+  SKY_SIG           : sky_err
+  PSF_CHISQ         : psf_chisq
+  CR_NSIGMA         : cr_nsigma
+  EXT_NSIGMA        : ext_nsigma
+  PSF_WIDTH_X       : FWHM_MAJ
+  PSF_WIDTH_Y       : FWHM_MIN
+  PSF_THETA         : THETA
+  PSF_QF            : PSF_QF
+  N_FRAMES          : SKIP
+  FLAGS             : phot_flags
+end
+
+... etc ...
+# this list is good for PS1_DEV_0
+list testfields_PS1_DEV_V0
+  IPP_IDET          : detid
+  X_PSF             : xccd
+  Y_PSF             : yccd
+  X_PSF_SIG         : xccd:err
+  Y_PSF_SIG         : yccd:err
+  PSF_INST_MAG      : mag:inst
+  PSF_INST_MAG_SIG  : mag:err
+  PEAK_FLUX_AS_MAG  : SKIP
+  SKY               : sky
+  SKY_SIG           : sky_err
+  PSF_CHISQ         : psf_chisq
+  CR_NSIGMA         : cr_nsigma
+  EXT_NSIGMA        : ext_nsigma
+  PSF_WIDTH_X       : FWHM_MAJ
+  PSF_WIDTH_Y       : FWHM_MIN
+  PSF_THETA         : THETA
+  PSF_QF            : PSF_QF
+  N_FRAMES          : SKIP
+  FLAGS             : phot_flags
+end
+
Index: trunk/Ohana/src/addstar/test/tap.dvo
===================================================================
--- trunk/Ohana/src/addstar/test/tap.dvo	(revision 27435)
+++ trunk/Ohana/src/addstar/test/tap.dvo	(revision 27435)
@@ -0,0 +1,52 @@
+# -*-sh-*-
+
+macro tapOK
+  if ($0 != 3) 
+    echo "USAGE: tapOK (condition) (message)"
+    break
+  end
+
+  if ($1)
+    echo "ok : $2"
+    $TAP_LAST = 1
+  else
+    echo "not ok : $2"
+    $TAP_NFAIL ++
+    $TAP_LAST = 0
+    if ($TAP_BREAK)
+     break
+    end
+  end
+  $TAP_NDONE ++
+end
+
+macro tapPLAN
+  if ($0 != 2) 
+    echo "USAGE: tapPLAN (Ntests)"
+    break
+  end
+
+  $TAP_NTEST = $1
+  $TAP_NFAIL = 0
+  $TAP_NDONE = 0
+  if (not($?TAP_BREAK)) set TAP_BREAK = 0
+end
+
+macro tapDONE
+  if ($0 != 1) 
+    echo "USAGE: tapDONE"
+    break
+  end
+
+  if ($TAP_NDONE != $TAP_NTEST) 
+    echo "planned tests ($TAP_NTEST) not equal to done tests ($TAP_NDONE)"
+  end
+
+  if ($TAP_NFAIL) 
+    echo "failed $TAP_NFAIL of $TAP_NDONE"
+  end
+
+  if ($TAP_NFAIL == 0) 
+    echo "passed $TAP_NDONE tests"
+  end
+end
Index: trunk/Ohana/src/delstar/include/delstar.h
===================================================================
--- trunk/Ohana/src/delstar/include/delstar.h	(revision 27392)
+++ trunk/Ohana/src/delstar/include/delstar.h	(revision 27435)
@@ -40,9 +40,9 @@
 int        FindDecBand            PROTO((double dec, double *DEC0, double *DEC1));
 FILE      *GetDB                  PROTO((int *state));
-Image     *GetImages              PROTO((int *nimage));
-int        SetImages              PROTO((Image *new, int Nnew));
+Image     *GetImages              PROTO((off_t *nimage));
+int        SetImages              PROTO((Image *new, off_t Nnew));
 void       SetProtect             PROTO((int mode));
 int        SetSignals             PROTO((void));
-int        Shutdown               PROTO((char *format, ...));
+int        Shutdown               PROTO((char *format, ...)) OHANA_FORMAT(printf, 1, 2);
 void       TrapSignal             PROTO((int sig));
 int        args                   PROTO((int *argc, char **argv));
@@ -52,17 +52,17 @@
 void       delete_times           PROTO((FITS_DB *db));
 int        edge_check             PROTO((double *x1, double *y1, double *x2, double *y2));
-int       *find_images_data       PROTO((FITS_DB *db, Image *timage, int *nlist));
-int       *find_images_name       PROTO((FITS_DB *db, char *filename, int *nlist));
-int       *find_images_time       PROTO((FITS_DB *db, time_t start, time_t end, PhotCode *code, int *nlist));
-void       find_matches           PROTO((Catalog *catalog, int photcode, int start, int end));
+off_t     *find_images_data       PROTO((FITS_DB *db, Image *timage, off_t *nlist));
+off_t     *find_images_name       PROTO((FITS_DB *db, char *filename, off_t *nlist));
+off_t     *find_images_time       PROTO((FITS_DB *db, e_time start, e_time end, PhotCode *code, off_t *nlist));
+void       find_matches           PROTO((Catalog *catalog, int photcode, e_time start, e_time end));
 int        gcatalog               PROTO((Catalog *catalog));
 Image     *gimages                PROTO((char *filename));
-Image     *gtimes                 PROTO((int *NIMAGE));
+Image     *gtimes                 PROTO((off_t *NIMAGE));
 void       help                   PROTO((void));
 int        load_image_db          PROTO((FITS_DB *db));
 void       lock_image_db          PROTO((FITS_DB *db, char *filename));
-void       match_images           PROTO((Catalog *catalog, Image *image, int Nimage));
+void       match_images           PROTO((Catalog *catalog, Image *image, off_t Nimage));
 double     opening_angle          PROTO((double x1, double y1, double x2, double y2, double x3, double y3));
-int        parse_time             PROTO((Header *header));
+e_time     parse_time             PROTO((Header *header));
 int        save_image_db          PROTO((void));
 void       sort_lists             PROTO((float *X, float *Y, int *S, int N));
Index: trunk/Ohana/src/delstar/src/delete_imagefile.c
===================================================================
--- trunk/Ohana/src/delstar/src/delete_imagefile.c	(revision 27392)
+++ trunk/Ohana/src/delstar/src/delete_imagefile.c	(revision 27435)
@@ -3,8 +3,8 @@
 void delete_imagefile (FITS_DB *db, char *filename) {
 
-  int i, Nimlist;
-  int *imlist;
+  off_t i, Nimlist;
+  off_t *imlist;
   double trange;
-  time_t start, stop;
+  e_time start, stop;
   Image *image;
   Catalog catalog;
Index: trunk/Ohana/src/delstar/src/delete_imagename.c
===================================================================
--- trunk/Ohana/src/delstar/src/delete_imagename.c	(revision 27392)
+++ trunk/Ohana/src/delstar/src/delete_imagename.c	(revision 27435)
@@ -3,7 +3,7 @@
 void delete_imagename (FITS_DB *db, char *name) {
 
-  int i, j, k;
-  int Nimlist, Nimage, Noutimage;
-  int *imlist;
+  off_t i, j, k;
+  off_t Nimlist, Nimage, Noutimage;
+  off_t *imlist;
   double trange;
   time_t start, stop;
@@ -77,9 +77,9 @@
   Noutimage = Nimage - Nimlist;
   
-  if (VERBOSE) fprintf (stderr, "removing %d images (leaving %d of %d)\n", Nimlist, Noutimage, Nimage);
+  if (VERBOSE) fprintf (stderr, "removing %lld images (leaving %lld of %lld)\n", (long long) Nimlist, (long long) Noutimage, (long long) Nimage);
   // gfits_table_set_Image (&db[0].ftable, outimage, Noutimage);
 
-  gfits_modify (&db[0].theader, "NAXIS2", "%d", 1, Noutimage);
-  gfits_modify (&db[0].header, "NIMAGES", "%d", 1, Noutimage);
+  gfits_modify (&db[0].theader, "NAXIS2", "%lld", 1, (long long) Noutimage);
+  gfits_modify (&db[0].header, "NIMAGES", "%lld", 1, (long long) Noutimage);
   db[0].theader.Naxis[1] = Noutimage;
   db[0].ftable.buffer = (char *) outimage;
Index: trunk/Ohana/src/delstar/src/delete_missed.c
===================================================================
--- trunk/Ohana/src/delstar/src/delete_missed.c	(revision 27392)
+++ trunk/Ohana/src/delstar/src/delete_missed.c	(revision 27435)
@@ -5,6 +5,5 @@
 delete_missed (Catalog *catalog) {
 
-  int i;
-  int Nave, Nmeas, Nmiss;
+  off_t i, Nave, Nmeas, Nmiss;
 
   Nave = catalog[0].Naverage;
@@ -12,5 +11,5 @@
   Nmiss = catalog[0].Nmissing;
   
-  if (VERBOSE) fprintf (stderr, "starting with Nave, Nmeas, Nmiss: %d %d %d\n", Nave, Nmeas, Nmiss);
+  if (VERBOSE) fprintf (stderr, "starting with Nave, Nmeas, Nmiss: %lld %lld %lld\n", (long long) Nave, (long long) Nmeas, (long long) Nmiss);
 
   /* set up references for missing to average */
@@ -20,5 +19,5 @@
   REALLOCATE (catalog[0].missing, Missing, 1);
   catalog[0].Nmissing = 0;
-  if (VERBOSE) fprintf (stderr, "  ending with Nave, Nmeas, Nmiss: %d %d %d\n", Nave, Nmeas, Nmiss);
+  if (VERBOSE) fprintf (stderr, "  ending with Nave, Nmeas, Nmiss: %lld %lld %lld\n", (long long) Nave, (long long) Nmeas, (long long) Nmiss);
 }
 
Index: trunk/Ohana/src/delstar/src/delete_orphans.c
===================================================================
--- trunk/Ohana/src/delstar/src/delete_orphans.c	(revision 27392)
+++ trunk/Ohana/src/delstar/src/delete_orphans.c	(revision 27435)
@@ -3,8 +3,8 @@
 delete_orphans (char *name) {
 
-  int i, j, k, n, m, N, M, found;
-  int *N1, *N2,  *next, *next_miss, *ave_miss, last, last_miss;
-  int Nave, NAVE, Nmeas, NMEAS, Nmiss, NMISS, Nmatch;
-  int start, end, Nmeasfound, Nsecfilt;
+  off_t i, j, k, n, m, Nmeasfound, Nsecfilt, N, M, found;
+  off_t *next_meas, *next_miss, *ave_miss, last, last_miss;
+  off_t Nave, NAVE, Nmeas, NMEAS, Nmiss, NMISS, Nmatch;
+  e_time start, end;
   unsigned int flags;
   Measure *tmpmeasure;
@@ -26,5 +26,5 @@
 
   Nmeas = catalog.Nmeasure;
-  ALLOCATE (next, int, Nmeas);
+  ALLOCATE (next_meas, int, Nmeas);
   
   Nmiss = catalog.Nmissing;
@@ -36,7 +36,7 @@
   /* set up pointers for linked list of measure */
   for (i = 0; i < Nmeas - 1; i++) {
-    next[i] = i+1;
-  }
-  next[i] = -1;
+    next_meas[i] = i+1;
+  }
+  next_meas[i] = -1;
   last = i;
   /* set up pointers for linked list of missing */
@@ -60,18 +60,18 @@
       /* this star is an orphan */
       Nmeasfound ++;
-      next[i] = -2; /* we delete this one */
+      next_meas[i] = -2; /* we delete this one */
       /* fix the list links: connect the previous valid link to the next valid link */
-      for (j = i; (j >= 0) && (next[j] == -2); j--); /* find previous entry to fix link */
+      for (j = i; (j >= 0) && (next_meas[j] == -2); j--); /* find previous entry to fix link */
       if (j >= 0) { /* if j < 0, there is no previous valid link, ignore this step */
-	if (next[j] != i) {
+	if (next_meas[j] != i) {
 	  fprintf (stderr, "error?  this link seems to have been lost\n");
 	  exit (1);
 	}
 	/* find next valid entry to fix link */
-	for (k = i; (k < Nmeas) && (next[k] == -2); k++);
+	for (k = i; (k < Nmeas) && (next_meas[k] == -2); k++);
 	if (k < Nmeas)
-	  next[j] = k;
+	  next_meas[j] = k;
 	else 
-	  next[j] = -1;  /* last link in list gets a -1 */
+	  next_meas[j] = -1;  /* last link in list gets a -1 */
       }
       
@@ -111,5 +111,5 @@
 	m = catalog.average[n].offset;
 	/* find next valid entry -- notice lack of error checking... */
-	for (j = 0; (j < Nmeas) && (next[m+j] == -2); j++);
+	for (j = 0; (j < Nmeas) && (next_meas[m+j] == -2); j++);
 	catalog.average[n].offset = m + j;
       }
@@ -218,5 +218,5 @@
       tmpmeasure[N] = catalog.measure[n]; 
       tmpmeasure[N].averef = i;
-      n = next[n];
+      n = next_meas[n];
     }
   }
Index: trunk/Ohana/src/delstar/src/delete_times.c
===================================================================
--- trunk/Ohana/src/delstar/src/delete_times.c	(revision 27392)
+++ trunk/Ohana/src/delstar/src/delete_times.c	(revision 27435)
@@ -3,8 +3,9 @@
 void delete_times (FITS_DB *db) {
 
-  int i, j, k, n;
-  int Nimage, Nimlist, found, code;
-  int Nregions, NREGIONS;
-  int *imlist;
+  int found, code;
+  off_t i, j, k, n;
+  off_t Nimage, Nimlist;
+  off_t Nregions, NREGIONS;
+  off_t *imlist;
   SkyList *skylist, *skyset;
   SkyTable *sky;
Index: trunk/Ohana/src/delstar/src/find_image_db.c
===================================================================
--- trunk/Ohana/src/delstar/src/find_image_db.c	(revision 27392)
+++ trunk/Ohana/src/delstar/src/find_image_db.c	(revision 27435)
@@ -1,8 +1,8 @@
 # include "delstar.h"
 
-int *find_images_name (FITS_DB *db, char *filename, int *nlist) {
+off_t *find_images_name (FITS_DB *db, char *filename, off_t *nlist) {
 
-  int i, Nimage, Nlist, NLIST;
-  int *list;
+  off_t i, Nimage, Nlist, NLIST;
+  off_t *list;
   char *p, *name;
   Image *image;
@@ -20,5 +20,5 @@
   Nlist = 0;
   NLIST = 100;
-  ALLOCATE (list, int, NLIST);
+  ALLOCATE (list, off_t, NLIST);
 
   for (i = 0; i < Nimage; i++) {
@@ -26,5 +26,5 @@
     list[Nlist] = i;
     Nlist ++;
-    CHECK_REALLOCATE (list, int, NLIST, Nlist, 100);
+    CHECK_REALLOCATE (list, off_t, NLIST, Nlist, 100);
   }
 
@@ -34,8 +34,8 @@
 
 /* find images in db by image data (time/photcode) */
-int *find_images_data (FITS_DB *db, Image *timage, int *nlist) {
+off_t *find_images_data (FITS_DB *db, Image *timage, off_t *nlist) {
 
-  int i, Nimage, Nlist, NLIST; 
-  int *list;
+  off_t i, Nimage, Nlist, NLIST; 
+  off_t *list;
   Image *image;
   time_t start, stop;
@@ -50,5 +50,5 @@
   Nlist = 0;
   NLIST = 100;
-  ALLOCATE (list, int, NLIST);
+  ALLOCATE (list, off_t, NLIST);
 
   for (i = 0; i < Nimage; i++) {
@@ -58,5 +58,5 @@
     list[Nlist] = i;
     Nlist ++;
-    CHECK_REALLOCATE (list, int, NLIST, Nlist, 100);
+    CHECK_REALLOCATE (list, off_t, NLIST, Nlist, 100);
   }
 
@@ -66,8 +66,8 @@
 
 /* find images in db by image data (time/photcode) */
-int *find_images_time (FITS_DB *db, time_t start, time_t end, PhotCode *code, int *nlist) {
+off_t *find_images_time (FITS_DB *db, e_time start, e_time end, PhotCode *code, off_t *nlist) {
 
-  int i, Nimage, Nlist, NLIST;
-  int *list;
+  off_t i, Nimage, Nlist, NLIST;
+  off_t *list;
   Image *image;
 
@@ -76,5 +76,5 @@
   Nlist = 0;
   NLIST = 100;
-  ALLOCATE (list, int, NLIST);
+  ALLOCATE (list, off_t, NLIST);
 
   for (i = 0; i < Nimage; i++) {
@@ -86,5 +86,5 @@
     list[Nlist] = i;
     Nlist ++;
-    CHECK_REALLOCATE (list, int, NLIST, Nlist, 100);
+    CHECK_REALLOCATE (list, off_t, NLIST, Nlist, 100);
   }
 
Index: trunk/Ohana/src/delstar/src/find_matches.c
===================================================================
--- trunk/Ohana/src/delstar/src/find_matches.c	(revision 27392)
+++ trunk/Ohana/src/delstar/src/find_matches.c	(revision 27435)
@@ -1,11 +1,12 @@
 # include "delstar.h"
 
-void find_matches (Catalog *catalog, int photcode, int start, int end) {
-
-  int i, j, k, n, m, N, M, drop, averef;
-  int *next, *next_miss, *ave_miss, last, last_miss;
-  int Nave, Nmeas, NMEAS, Nmiss;
-  int Nmeasfound, Nsecfilt;
-  int this, prev;
+void find_matches (Catalog *catalog, int photcode, e_time start, e_time end) {
+
+  int drop;
+  off_t i, j, k, n, m, N, M, averef;
+  off_t *next_meas, *next_miss, *ave_miss, last, last_miss;
+  off_t Nave, Nmeas, NMEAS, Nmiss;
+  off_t Nmeasfound, Nsecfilt;
+  off_t this, prev;
   Measure *tmpmeasure;
   Missing *tmpmissing;
@@ -15,17 +16,17 @@
 
   Nmeas = catalog[0].Nmeasure;
-  ALLOCATE (next, int, MAX(Nmeas,1));
+  ALLOCATE (next_meas, off_t, MAX(Nmeas,1));
   
   Nmiss = catalog[0].Nmissing;
-  ALLOCATE (next_miss, int, MAX(Nmiss,1));
-  ALLOCATE (ave_miss, int, MAX(Nmiss,1));
+  ALLOCATE (next_miss, off_t, MAX(Nmiss,1));
+  ALLOCATE (ave_miss, off_t, MAX(Nmiss,1));
   
-  if (VERBOSE) fprintf (stderr, "starting with Nave, Nmeas, Nmiss: %d %d %d\n", Nave, Nmeas, Nmiss);
+  if (VERBOSE) fprintf (stderr, "starting with Nave, Nmeas, Nmiss: %lld %lld %lld\n", (long long) Nave, (long long) Nmeas, (long long) Nmiss);
 
   /* set up pointers for linked list of measure */
   for (i = 0; i < Nmeas - 1; i++) {
-    next[i] = i+1;
-  }
-  next[i] = -1;
+    next_meas[i] = i+1;
+  }
+  next_meas[i] = -1;
   last = i;
   /* set up pointers for linked list of missing */
@@ -63,24 +64,24 @@
 
     /* this star is in this image */
-    this = next[i];
-    next[i] = -2; /* we delete this one */
-    if (prev != -1) { next[prev] = this; }
+    this = next_meas[i];
+    next_meas[i] = -2; /* we delete this one */
+    if (prev != -1) { next_meas[prev] = this; }
 
 # if (0) 
     /* why is this section disabled? */
     /* fix the list links: connect the previous valid link to the next valid link */
-    for (j = i; (j >= 0) && (next[j] == -2); j--); /* find previous entry to fix link */
+    for (j = i; (j >= 0) && (next_meas[j] == -2); j--); /* find previous entry to fix link */
     if (j >= 0) { /* if j < 0, there is no previous valid link, ignore this step */
-      if (next[j] != i) {
+      if (next_meas[j] != i) {
 	fprintf (stderr, "error? (1)  this link seems to have been lost\n");
-	fprintf (stderr, "j: %d, next[j]: %d, i: %d\n", j, next[j], i);
+	fprintf (stderr, "j: %lld, next_meas[j]: %lld, i: %lld\n", (long long) j, (long long) next_meas[j], (long long) i);
 	exit (1);
       }
       /* find next valid entry to fix link */
-      for (k = i; (k < Nmeas) && (next[k] == -2); k++);
+      for (k = i; (k < Nmeas) && (next_meas[k] == -2); k++);
       if (k < Nmeas)
-	next[j] = k;
+	next_meas[j] = k;
       else 
-	next[j] = -1;  /* last link in list gets a -1 */
+	next_meas[j] = -1;  /* last link in list gets a -1 */
     }
 # endif      
@@ -107,5 +108,5 @@
 	if (next_miss[j] != m) {
 	  fprintf (stderr, "error? (2) this link seems to have been lost\n");
-	  fprintf (stderr, "j: %d, next_miss[j]: %d, i: %d\n", j, next_miss[j], i);
+	  fprintf (stderr, "j: %lld, next_miss[j]: %lld, i: %lld\n", (long long) j, (long long) next_miss[j], (long long) i);
 	  exit (1);
 	}
@@ -122,5 +123,5 @@
       m = catalog[0].average[n].measureOffset;
       /* find next valid entry -- notice lack of error checking... */
-      for (j = 0; (j < Nmeas) && (next[m+j] == -2); j++);
+      for (j = 0; (j < Nmeas) && (next_meas[m+j] == -2); j++);
       if (catalog[0].measure[m+j].averef != n) {
 	fprintf (stderr, "error? measure.averef and average.measureOffset are mismatched\n");
@@ -130,5 +131,5 @@
     }
   } 
-  fprintf (stderr, "found %d meas to remove\n", Nmeasfound);
+  fprintf (stderr, "found %lld meas to remove\n", (long long) Nmeasfound);
 
   if (VERBOSE) fprintf (stderr, "fixing missing..."); 
@@ -145,5 +146,5 @@
       if (next_miss[j] != i) {
 	fprintf (stderr, "error? (3) this link seems to have been lost\n");
-	fprintf (stderr, "j: %d, next_miss[j]: %d, i: %d\n", j, next_miss[j], i);
+	fprintf (stderr, "j: %lld, next_miss[j]: %lld, i: %lld\n", (long long) j, (long long) next_miss[j], (long long) i);
 	exit (1);
       }
@@ -209,5 +210,5 @@
       tmpmeasure[N] = catalog[0].measure[n]; 
       tmpmeasure[N].averef = i;
-      n = next[n];
+      n = next_meas[n];
       CHECK_REALLOCATE (tmpmeasure, Measure, NMEAS, N, 10000);
     }
@@ -248,7 +249,7 @@
   catalog[0].Nsecf_mem = Nave*Nsecfilt;
 
-  if (VERBOSE) fprintf (stderr, "  ending with Nave, Nmeas, Nmiss: %d %d %d\n", Nave, Nmeas, Nmiss);
-
-  free (next);
+  if (VERBOSE) fprintf (stderr, "  ending with Nave, Nmeas, Nmiss: %lld %lld %lld\n", (long long) Nave, (long long) Nmeas, (long long) Nmiss);
+
+  free (next_meas);
   free (next_miss);
   free (ave_miss);
Index: trunk/Ohana/src/delstar/src/gimages.c
===================================================================
--- trunk/Ohana/src/delstar/src/gimages.c	(revision 27392)
+++ trunk/Ohana/src/delstar/src/gimages.c	(revision 27435)
@@ -25,5 +25,5 @@
     Shutdown ("ERROR: can't find data file %s", filename);
   }
-  fseek (f, header.size, SEEK_SET); 
+  fseeko (f, header.datasize, SEEK_SET); 
 
   /* add file name to image structure */
@@ -53,6 +53,6 @@
   }      
   if (!haveNx && !haveNy) {
-      haveNx = gfits_scan (&header, "ZNAXIS1",   "%d", 1, &image[0].NX);
-      haveNy = gfits_scan (&header, "ZNAXIS2",   "%d", 1, &image[0].NY);
+      haveNx = gfits_scan (&header, "ZNAXIS1",   "%hd", 1, &image[0].NX);
+      haveNy = gfits_scan (&header, "ZNAXIS2",   "%hd", 1, &image[0].NY);
   }
   if (!haveNx || !haveNy) {
Index: trunk/Ohana/src/delstar/src/match_images.c
===================================================================
--- trunk/Ohana/src/delstar/src/match_images.c	(revision 27392)
+++ trunk/Ohana/src/delstar/src/match_images.c	(revision 27435)
@@ -1,8 +1,8 @@
 # include "delstar.h"
 
-void match_images (Catalog *catalog, Image *image, int Nimage) {
+void match_images (Catalog *catalog, Image *image, off_t Nimage) {
   
-  int j, k, found;
-  unsigned int *start, *stop;
+  off_t j, k, found;
+  e_time *start, *stop;
 
   /* this must be allocated so future free will not fail */
Index: trunk/Ohana/src/delstar/src/parse_time.c
===================================================================
--- trunk/Ohana/src/delstar/src/parse_time.c	(revision 27392)
+++ trunk/Ohana/src/delstar/src/parse_time.c	(revision 27435)
@@ -1,5 +1,5 @@
 # include "delstar.h"
 
-int parse_time (Header *header) {
+e_time parse_time (Header *header) {
 
   double jd;
Index: trunk/Ohana/src/dvomerge/Makefile
===================================================================
--- trunk/Ohana/src/dvomerge/Makefile	(revision 27392)
+++ trunk/Ohana/src/dvomerge/Makefile	(revision 27435)
@@ -22,8 +22,13 @@
 DVOMERGE = \
 $(SRC)/dvomerge.$(ARCH).o \
+$(SRC)/dvomergeUpdate.$(ARCH).o \
+$(SRC)/dvomergeCreate.$(ARCH).o \
+$(SRC)/dvo_image_merge_dbs.$(ARCH).o \
 $(SRC)/SetSignals.$(ARCH).o \
 $(SRC)/ConfigInit.$(ARCH).o \
 $(SRC)/Shutdown.$(ARCH).o \
-$(SRC)/usage.$(ARCH).o \
+$(SRC)/help.$(ARCH).o \
+$(SRC)/args.$(ARCH).o \
+$(SRC)/psps_ids.$(ARCH).o \
 $(SRC)/SkyTablePopulatedRange.$(ARCH).o \
 $(SRC)/LoadCatalog.$(ARCH).o \
Index: trunk/Ohana/src/dvomerge/include/dvomerge.h
===================================================================
--- trunk/Ohana/src/dvomerge/include/dvomerge.h	(revision 27392)
+++ trunk/Ohana/src/dvomerge/include/dvomerge.h	(revision 27435)
@@ -22,4 +22,5 @@
 char   CATMODE[16];    /* raw, mef, split, mysql */
 char   CATFORMAT[16];  /* internal, elixir, loneos, panstarrs */
+char   ImageCat[256];
 float  RADIUS;
 int    SKY_DEPTH;
@@ -27,5 +28,13 @@
 SkyRegion UserPatch;  // used by MODE CAT
 
+typedef struct {
+  off_t Nmap;
+  off_t *old;
+  off_t *new;
+} IDmapType;
+
 int        main                   PROTO((int argc, char **argv));
+int        dvomergeCreate         PROTO((int argc, char **argv));
+int        dvomergeUpdate         PROTO((int argc, char **argv));
 
 int        ConfigInit             PROTO((int *argc, char **argv));
@@ -35,11 +44,14 @@
 void       SetProtect             PROTO((int mode));
 void       TrapSignal             PROTO((int sig));
-int        Shutdown               PROTO((char *format, ...));
+int        Shutdown               PROTO((char *format, ...)) OHANA_FORMAT(printf, 1, 2);
 
 void       usage                  PROTO((void));
-int        SkyTablePopulatedRange PROTO((int *ns, int *ne, SkyTable *sky, int Nstart));
+void 	   help 		  PROTO((int argc, char **argv));
+int  	   args 		  PROTO((int *argc, char **argv));
+
+int        SkyTablePopulatedRange PROTO((off_t *ns, off_t *ne, SkyTable *sky, off_t Nstart));
 
 SkyList   *SkyTablePopulatedList  PROTO((SkyTable *sky));
-SkyList   *SkyTablePopulatedList_old  PROTO((SkyTable *sky, int Ns, int Ne));
+SkyList   *SkyTablePopulatedList_old  PROTO((SkyTable *sky, off_t Ns, off_t Ne));
 
 int        LoadCatalog            PROTO((Catalog *catalog, SkyRegion *region, char *filename, char *mode));
@@ -48,9 +60,18 @@
 int        merge_catalogs_old     PROTO((SkyRegion *region, Catalog *output, Catalog *input, double RADIUS));
 
-int 	  *init_measure_links     PROTO((Average *average, int Naverage, Measure *measure, int Nmeasure));
-int 	  *init_missing_links     PROTO((Average *average, int Naverage, Missing *missing, int Nmissing));
-int 	  *build_measure_links    PROTO((Average *average, int Naverage, Measure *measure, int Nmeasure));
-int 	   add_meas_link     	  PROTO((Average *average, int *next, int Nmeasure, int NMEASURE));
-int 	   add_miss_link     	  PROTO((Average *average, int *next, int Nmissing));
-Measure   *sort_measure     	  PROTO((Average *average, int Naverage, Measure *measure, int Nmeasure, int *next));
-Missing   *sort_missing     	  PROTO((Average *average, int Naverage, Missing *missing, int Nmissing, int *next_miss));
+off_t 	  *init_measure_links     PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
+off_t 	  *init_missing_links     PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing));
+off_t 	  *build_measure_links    PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
+int   	   add_meas_link     	  PROTO((Average *average, off_t *next, off_t Nmeasure, off_t NMEASURE));
+int   	   add_miss_link     	  PROTO((Average *average, off_t *next, off_t Nmissing));
+Measure   *sort_measure     	  PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next));
+Missing   *sort_missing     	  PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next_miss));
+
+uint64_t   CreatePSPSDetectionID  PROTO((double tobs, int ccdid, int detID));
+uint64_t   CreatePSPSObjectID     PROTO((double ra, double dec));
+
+int        dvomergeImagesCreate   PROTO((IDmapType *IDmap1, char *input1, IDmapType *IDmap2, char *input2, char *output));
+int        dvomergeImagesUpdate   PROTO((IDmapType *IDmap, char *input, char *output));
+int        dvo_image_merge_dbs    PROTO((IDmapType *IDmap, FITS_DB *out, FITS_DB *in));
+off_t 	   dvo_map_image_ID       PROTO((IDmapType *IDmap, off_t oldID));
+int   	   dvo_update_image_IDs   PROTO((IDmapType *IDmap, Catalog *catalog));
Index: trunk/Ohana/src/dvomerge/src/ConfigInit.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/ConfigInit.c	(revision 27392)
+++ trunk/Ohana/src/dvomerge/src/ConfigInit.c	(revision 27435)
@@ -4,10 +4,10 @@
 
   double ZERO_POINT;
+  char RadiusWord[80];
   char *config, *file;
-  char CatdirPhotcodeFile[256];
-  char MasterPhotcodeFile[256];
 
   /*** load configuration info ***/
   file = SelectConfigFile (argc, argv, "ptolemy");
+
   config = LoadConfigFile (file);
   if (config == (char *) NULL) {
@@ -18,9 +18,8 @@
   if (VERBOSE) fprintf (stderr, "loaded config file: %s\n", file);
 
-  GetConfig (config, "PHOTCODE_FILE",          	"%s",  0, MasterPhotcodeFile);
+
   GetConfig (config, "GSCFILE",                	"%s",  0, GSCFILE);
   ScanConfig (config, "CATMODE",                "%s",  0, CATMODE);
   ScanConfig (config, "CATFORMAT",              "%s",  0, CATFORMAT);
-  ScanConfig (config, "RADIUS",                 "%f",  0, &RADIUS);
   GetConfig (config, "SKY_DEPTH",              "%d",  0, &SKY_DEPTH);
   if (SKY_DEPTH > 4) {
@@ -36,4 +35,9 @@
   SetZeroPoint (ZERO_POINT);
 
+  /* set the default search radius */
+  if (!ScanConfig (config, "ADDSTAR_RADIUS", "%s", 0, RadiusWord)) {
+    GetConfig (config, "RADIUS", "%s", 0, RadiusWord);
+  }
+  RADIUS = atof (RadiusWord);
   if (RADIUS < 1e-6) {
       fprintf (stderr, "non-sensical correlation radius %f\n", RADIUS);
Index: trunk/Ohana/src/dvomerge/src/SkyTablePopulatedRange.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/SkyTablePopulatedRange.c	(revision 27392)
+++ trunk/Ohana/src/dvomerge/src/SkyTablePopulatedRange.c	(revision 27435)
@@ -1,7 +1,7 @@
 # include "dvomerge.h"
 
-int SkyTablePopulatedRange (int *ns, int *ne, SkyTable *sky, int Nstart) {
+int SkyTablePopulatedRange (off_t *ns, off_t *ne, SkyTable *sky, off_t Nstart) {
 
-  int Ns, Ne;
+  off_t Ns, Ne;
 
   // given the starting sky region, find the populated range at or below this region
@@ -26,6 +26,6 @@
 SkyList *SkyTablePopulatedList (SkyTable *sky) {
 
-  int i, N, NREGIONS;
-  SkyList *list, *subset;
+  off_t i, N, NREGIONS;
+  SkyList *list;
 
   N = 0;
@@ -54,7 +54,7 @@
 }
 
-SkyList *SkyTablePopulatedList_old (SkyTable *sky, int Ns, int Ne) {
+SkyList *SkyTablePopulatedList_old (SkyTable *sky, off_t Ns, off_t Ne) {
 
-  int i, ns, ne, N, NREGIONS;
+  off_t i, ns, ne, N, NREGIONS;
   SkyList *list, *subset;
 
Index: trunk/Ohana/src/dvomerge/src/args.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/args.c	(revision 27392)
+++ trunk/Ohana/src/dvomerge/src/args.c	(revision 27435)
@@ -1,16 +1,8 @@
 # include "dvomerge.h"
-static void help (void);
 
-int args (int argc, char **argv) {
+/*** check for command line options ***/
+int args (int *argc, char **argv) {
   
-  int i, N, CONFIRM;
-
-  /* check for help request */
-  if (get_argument (argc, argv, "-help") ||
-      get_argument (argc, argv, "-h")) {
-    help ();
-  }
-
-  /*** check for command line options ***/
+  int N, CONFIRM;
 
   /*** provide additional data ***/ 
@@ -21,14 +13,14 @@
   UserPatch.Dmax = +90;
   CONFIRM = TRUE;
-  if ((N = get_argument (argc, argv, "-region"))) {
-    remove_argument (N, &argc, argv);
+  if ((N = get_argument (*argc, argv, "-region"))) {
+    remove_argument (N, argc, argv);
     UserPatch.Rmin = atof (argv[N]);
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
     UserPatch.Rmax = atof (argv[N]);
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
     UserPatch.Dmin = atof (argv[N]);
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
     UserPatch.Dmax = atof (argv[N]);
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
     CONFIRM = FALSE;
   }
@@ -36,52 +28,10 @@
   /* extra error messages */
   VERBOSE = FALSE;
-  if ((N = get_argument (argc, argv, "-v"))) {
+  if ((N = get_argument (*argc, argv, "-v"))) {
     VERBOSE = TRUE;
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
   }
 
-  if (argc == 2) {
-    if (CONFIRM) {
-      fprintf (stderr, "you are splitting the entire sky in one pass\n");
-      fprintf (stderr, "this could be a time consuming operation.  type Ctrl-C within 5 seconds to cancel\n");
-      for (i = 5; i > 0; i--) {
-	fprintf (stderr, "%d.. ", i);
-	usleep (1000000);
-      }
-      fprintf (stderr, "\n");
-    }    
-    return (TRUE);
-  }
-
-  fprintf (stderr, "USAGE: dvosplit (newlevel) [-region (Rmin) (Rmax) (Dmin) (Dmax)]\n");
-  exit (2);
+  if ((*argc != 6) && (*argc != 4)) usage();
+  return TRUE;
 }
-
-static void help () {
-
-  fprintf (stderr, "USAGE\n");
-  fprintf (stderr, "  dvosplit (newlevel)\n\n");
-  fprintf (stderr, "  optional flags:\n");
-  fprintf (stderr, "  -region ra ra dec dec 	  : migrate catalogs in specified region\n");
-  fprintf (stderr, "  -v                    	  : verbose mode\n");
-  fprintf (stderr, "  -help                 	  : this list\n");
-  fprintf (stderr, "  -h                    	  : this list\n\n");
-  exit (2);
-}
-
-/** addstar modes:
- 
-    addstar (image.smp)  - add cmp/smp image data to db
-    addstar -ref (file.dat) (photcode) 
-    addstar -cat (USNO/2MASS/GSC) -region (ra dec - ra dec)
-
-    -replace : ref/cat - replace existing match (photcode/time)
-    -match   : ref/cat - only add measures to existing averages
-
-    ref types: 
-    ASCII - RA,DEC,M,dM in a table
-
-    addstar 
-
-**/
-
Index: trunk/Ohana/src/dvomerge/src/build_links.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/build_links.c	(revision 27392)
+++ trunk/Ohana/src/dvomerge/src/build_links.c	(revision 27435)
@@ -3,12 +3,12 @@
 /* build the initial links assuming the table is sorted, 
    not partial, and has a correct set of average[].measureOffset,Nmeasure values */
-int *init_measure_links (Average *average, int Naverage, Measure *measure, int Nmeasure) {
-
-  int i, j, N;
-  int *next;
+off_t *init_measure_links (Average *average, off_t Naverage, Measure *measure, off_t Nmeasure) {
+
+  off_t i, j, N;
+  off_t *next;
 
   N = 0;
 
-  ALLOCATE (next, int, Nmeasure);
+  ALLOCATE (next, off_t, Nmeasure);
   for (i = 0; i < Naverage; i++, N++) {
     for (j = 0; j < average[i].Nmeasure - 1; j++, N++) {
@@ -31,13 +31,114 @@
 }
 
+/* average[].measureOffset, average[].Nmeasure are valid within an addstar run */
+int add_meas_link (Average *average, off_t *next, off_t Nmeasure, off_t NMEASURE) {
+
+  off_t k, m;
+
+  /* if we have trouble, check validity of next[m] : m < Nmeasure */
+  m = average[0].measureOffset;  
+
+  for (k = 0; k < average[0].Nmeasure - 1; k++)  {
+    m = next[m];
+    if (m >= NMEASURE) {
+      fprintf (stderr, "WARNING: m out of bounds (3)\n");
+    }
+  }
+
+  /* set up references */
+  next[Nmeasure] = -1;
+  if (Nmeasure >= NMEASURE) {
+    fprintf (stderr, "WARNING: Nmeasure out of bounds (1)\n");
+  }
+
+  if (m == -1) {
+    average[0].measureOffset = Nmeasure;
+  } else {
+    next[m] = Nmeasure;
+    if (m >= NMEASURE) {
+      fprintf (stderr, "WARNING: m out of bounds (4)\n");
+    }
+  }
+
+  return (TRUE);
+}
+
+Measure *sort_measure (Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next) {
+
+  off_t i, k, n, N;
+  Measure *tmpmeasure;
+
+  /* fix order of Measure (memory intensive, but fast) */
+  N = 0; 
+  ALLOCATE (tmpmeasure, Measure, Nmeasure);
+  for (i = 0; i < Naverage; i++) {
+    n = average[i].measureOffset;
+    average[i].measureOffset = N;
+    for (k = 0; k < average[i].Nmeasure; k++, N++) {
+      tmpmeasure[N] = measure[n]; 
+      tmpmeasure[N].averef = i;
+      n = next[n];
+    }
+  }
+  free (measure);
+  return (tmpmeasure);
+}
+
+/* construct measure links which are valid FOR THIS LOAD
+ * - if we have a full load, we will get links which can
+ *   be used by other programs (eg, relphot, etc)
+ * - if we have a partial load, the links are only valid
+ *   for that partial load
+ */ 
+
+off_t *build_measure_links (Average *average, off_t Naverage, Measure *measure, off_t Nmeasure) {
+
+  off_t i, m, k, Nm, averef;
+  off_t *next;
+
+  ALLOCATE (next, off_t, Nmeasure);
+
+  /* reset the Nm, offset values for average */
+  for (i = 0; i < Naverage; i++) {
+    average[i].measureOffset = -1;
+    average[i].Nmeasure     =  0;
+  }
+
+  for (Nm = 0; Nm < Nmeasure; Nm++) {
+    averef = measure[Nm].averef;
+    m = average[averef].measureOffset;  
+    next[Nm] = -1;
+
+    if (m == -1) { /* no links yet for source */
+      average[averef].measureOffset = Nm;
+      average[averef].Nmeasure     = 1;
+      continue;
+    }
+
+    for (k = 0; next[m] != -1; k++) {
+      m = next[m];
+      if (m >= Nmeasure) {
+	fprintf (stderr, "WARNING: m out of bounds (1)\n");
+      }
+    }
+
+    average[averef].Nmeasure = k + 2;
+    next[m] = Nm;
+    if (m >= Nmeasure) {
+      fprintf (stderr, "WARNING: m out of bounds (2)\n");
+    }
+  }
+  return (next);
+}
+
 /* build the initial links assuming the table is sorted */
-int *init_missing_links (Average *average, int Naverage, Missing *missing, int Nmissing) {
-
-  int i, j, N;
-  int *next;
+off_t *init_missing_links (Average *average, off_t Naverage, Missing *missing, off_t Nmissing) {
+
+  off_t i, j, N;
+  off_t *next;
 
   N = 0;
 
-  ALLOCATE (next, int, Nmissing);
+  ALLOCATE (next, off_t, Nmissing);
   for (i = 0; i < Naverage; i++) {
     for (j = 0; j < average[i].Nmissing - 1; j++, N++) {
@@ -57,40 +158,7 @@
 }
 
-/* average[].measureOffset, average[].Nmeasure are valid within an addstar run */
-int add_meas_link (Average *average, int *next, int Nmeasure, int NMEASURE) {
-
-  int k, m;
-
-  /* if we have trouble, check validity of next[m] : m < Nmeasure */
-  m = average[0].measureOffset;  
-
-  for (k = 0; k < average[0].Nmeasure - 1; k++)  {
-    m = next[m];
-    if (m >= NMEASURE) {
-      fprintf (stderr, "WARNING: m out of bounds (3)\n");
-    }
-  }
-
-  /* set up references */
-  next[Nmeasure] = -1;
-  if (Nmeasure >= NMEASURE) {
-    fprintf (stderr, "WARNING: Nmeasure out of bounds (1)\n");
-  }
-
-  if (m == -1) {
-    average[0].measureOffset = Nmeasure;
-  } else {
-    next[m] = Nmeasure;
-    if (m >= NMEASURE) {
-      fprintf (stderr, "WARNING: m out of bounds (4)\n");
-    }
-  }
-
-  return (TRUE);
-}
-
-int add_miss_link (Average *average, int *next, int Nmissing) {
-
-  int k, m;
+int add_miss_link (Average *average, off_t *next, off_t Nmissing) {
+
+  off_t k, m;
 
   /* there may be 0 Nmiss; this is not true for Nmeas */
@@ -109,78 +177,10 @@
 }
 
-/* construct measure links which are valid FOR THIS LOAD
- * - if we have a full load, we will get links which can
- *   be used by other programs (eg, relphot, etc)
- * - if we have a partial load, the links are only valid
- *   for that partial load
- */ 
-
-int *build_measure_links (Average *average, int Naverage, Measure *measure, int Nmeasure) {
-
-  int i, m, k, Nm, averef;
-  int *next;
-
-  ALLOCATE (next, int, Nmeasure);
-
-  /* reset the Nm, offset values for average */
-  for (i = 0; i < Naverage; i++) {
-    average[i].measureOffset = -1;
-    average[i].Nmeasure     =  0;
-  }
-
-  for (Nm = 0; Nm < Nmeasure; Nm++) {
-    averef = measure[Nm].averef;
-    m = average[averef].measureOffset;  
-    next[Nm] = -1;
-
-    if (m == -1) { /* no links yet for source */
-      average[averef].measureOffset = Nm;
-      average[averef].Nmeasure     = 1;
-      continue;
-    }
-
-    for (k = 0; next[m] != -1; k++) {
-      m = next[m];
-      if (m >= Nmeasure) {
-	fprintf (stderr, "WARNING: m out of bounds (1)\n");
-      }
-    }
-
-    average[averef].Nmeasure = k + 2;
-    next[m] = Nm;
-    if (m >= Nmeasure) {
-      fprintf (stderr, "WARNING: m out of bounds (2)\n");
-    }
-  }
-  return (next);
-}
-
 /* Missing does not carry enough information to reconstruct the links
    we must always save the missing table, if it exists */
 
-Measure *sort_measure (Average *average, int Naverage, Measure *measure, int Nmeasure, int *next) {
-
-  int i, k, n, N;
-  Measure *tmpmeasure;
-
-  /* fix order of Measure (memory intensive, but fast) */
-  N = 0; 
-  ALLOCATE (tmpmeasure, Measure, Nmeasure);
-  for (i = 0; i < Naverage; i++) {
-    n = average[i].measureOffset;
-    average[i].measureOffset = N;
-    for (k = 0; k < average[i].Nmeasure; k++, N++) {
-      tmpmeasure[N] = measure[n]; 
-      tmpmeasure[N].averef = i;
-      n = next[n];
-    }
-  }
-  free (measure);
-  return (tmpmeasure);
-}
-
-Missing *sort_missing (Average *average, int Naverage, Missing *missing, int Nmissing, int *next) {
-
-  int i, k, n, N;
+Missing *sort_missing (Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next) {
+
+  off_t i, k, n, N;
   Missing *tmpmissing;
 
Index: trunk/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c	(revision 27435)
+++ trunk/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c	(revision 27435)
@@ -0,0 +1,73 @@
+# include "dvomerge.h"
+
+// merge db2 into db1
+int dvo_image_merge_dbs (IDmapType *IDmap, FITS_DB *out, FITS_DB *in) {
+
+  Image *images;
+  off_t Nimages;
+  off_t Nout;
+  off_t i, IDstart;
+  int status;
+ 
+  images = gfits_table_get_Image (&in[0].ftable, &Nimages, &in[0].swapped);
+  ALLOCATE (IDmap->old, off_t, Nimages);
+  ALLOCATE (IDmap->new, off_t, Nimages);
+  IDmap->Nmap = Nimages;
+
+ /* adjust header */
+  Nout = 0;
+  gfits_scan (&out[0].header, "NIMAGES", "%lld", 1, (long long *) &Nout);
+  status = gfits_scan (&out[0].header, "IMAGEID", "%lld", 1, (long long *) &IDstart);
+  if (!status) {
+    IDstart = 1;
+  }
+
+  for (i = 0; i < Nimages; i++) {
+    IDmap[0].old[i] = images[i].imageID;
+    images[i].imageID = i + IDstart;
+    IDmap[0].new[i] = images[i].imageID;
+  }
+
+  if (!out[0].swapped) {
+    gfits_convert_Image ((Image *) out[0].ftable.buffer, sizeof(Image), Nout);
+    out[0].swapped = TRUE;
+  }
+
+  Nout += Nimages;
+  IDstart += Nimages;
+  gfits_modify (&out[0].header, "NIMAGES", "%lld", 1, (long long) Nout);
+  gfits_modify (&out[0].header, "IMAGEID", "%lld", 1, (long long) IDstart);
+
+  gfits_add_rows (&out[0].ftable, (char *) images, Nimages, sizeof(Image));
+  return TRUE;
+}
+
+// optimize with sort and bisection
+off_t dvo_map_image_ID (IDmapType *IDmap, off_t oldID) {
+
+  off_t i;
+
+  for (i = 0; i < IDmap->Nmap; i++) {
+    if (IDmap->old[i] != oldID) continue;
+    return (IDmap->new[i]);
+  }
+  return 0;
+}
+
+int dvo_update_image_IDs (IDmapType *IDmap, Catalog *catalog) {
+
+  off_t i, oldID, newID;
+
+  for (i = 0; i < catalog[0].Nmeasure; i++) {
+    oldID = catalog[0].measure[i].imageID;
+    if (oldID == 0) continue;
+
+    newID = dvo_map_image_ID (IDmap, oldID);
+    if (newID == 0) {
+      fprintf (stderr, "cannot find image ID %lld\n", (long long) oldID);
+      exit (2);
+    }
+    catalog[0].measure[i].imageID = newID;
+  }
+  return TRUE;
+}
Index: trunk/Ohana/src/dvomerge/src/dvomerge.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/dvomerge.c	(revision 27392)
+++ trunk/Ohana/src/dvomerge/src/dvomerge.c	(revision 27435)
@@ -1,140 +1,21 @@
 # include "dvomerge.h"
 
-// dvomerge (catdir.in1) and (catdir.in2) to (catdir.output) [-region Rmin Rmax Dmin Dmax] [
-// merge sources from (catdir.from) into (catdir.to)
 int main (int argc, char **argv) {
 
-  int i, j, Ns, Ne, depth1, depth2;
-  SkyTable *outsky, *insky1, *insky2;
-  SkyList *inlist;
-  Catalog incatalog, outcatalog;
-  char filename[256], *input1, *input2, *output;
+  SetSignals ();
+  help (argc, argv);
+  ConfigInit (&argc, argv);
+  args (&argc, argv);
 
-  SetSignals ();
-  ConfigInit (&argc, argv);
-
-  if (argc != 6) usage();
-  if (strcasecmp (argv[2], "and")) usage();
-  if (strcasecmp (argv[4], "to")) usage();
-
-  input1 = argv[1];
-  input2 = argv[3];
-  output = argv[5];
-
-  // the first input define the photcode table & db layout
-  sprintf (filename, "%s/Photcodes.dat", input1);
-  if (!LoadPhotcodes (filename, NULL, FALSE)) {
-    fprintf (stderr, "error loading photcode table %s\n", filename);
-    exit (1);
-  }
-  // save the photcodes in the output catdir
-  sprintf (filename, "%s/Photcodes.dat", output);
-  if (!check_file_access (filename, TRUE, TRUE, TRUE)) {
-    fprintf (stderr, "error creating output catdir %s\n", output);
-    exit (1);
-  }
-  if (!SavePhotcodesFITS (filename)) {
-    fprintf (stderr, "error saving photcode table %s\n", filename);
-    exit (1);
-  }
-
-  // load the sky table for the existing database
-  insky1 = SkyTableLoadOptimal (input1, NULL, NULL, FALSE, SKY_DEPTH_HST, VERBOSE);
-  SkyTableSetFilenames (insky1, input1, "cpt");
-
-  insky2 = SkyTableLoadOptimal (input2, NULL, NULL, FALSE, SKY_DEPTH_HST, VERBOSE);
-  SkyTableSetFilenames (insky2, input2, "cpt");
-
-  // generate an output table populated at the desired depth
-  outsky = SkyTableLoadOptimal (output, NULL, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
-  SkyTableSetFilenames (outsky, output, "cpt");
-
-  // loop over the populatable output tables; check for data in input1 and/or input2
-  // in the corresponding regions
-
-  SkyTablePopulatedRange (&Ns, &Ne, insky1, 0);
-  depth1 = insky1[0].regions[Ns].depth;
-  
-  SkyTablePopulatedRange (&Ns, &Ne, insky2, 0);
-  depth2 = insky2[0].regions[Ns].depth;
-
-  // loop over the populatable output regions
-  for (i = 0; i < outsky[0].Nregions; i++) {
-    if (!outsky[0].regions[i].table) continue;
-    fprintf (stderr, "output: %s\n", outsky[0].regions[i].name);
-
-    // load / create output catalog
-    LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w");
-
-    // combine only tables at equal or larger depth
-      
-    // load in all of the tables from input1 for this region
-    inlist = SkyListByBounds (insky1, depth1, outsky[0].regions[i].Rmin, outsky[0].regions[i].Rmax, outsky[0].regions[i].Dmin, outsky[0].regions[i].Dmax);
-    for (j = 0; j < inlist[0].Nregions; j++) {
-      fprintf (stderr, "input 1: %s\n", inlist[0].regions[j][0].name);
-
-      // load input catalog (1)
-      LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r");
-
-      // skip empty input catalogs
-      if (!incatalog.Naves_disk) {
-	dvo_catalog_unlock (&incatalog);
-	dvo_catalog_free (&incatalog);
-	continue;
-      }
-      merge_catalogs_new (&outsky[0].regions[i], &outcatalog, &incatalog);
-      dvo_catalog_unlock (&incatalog);
-      dvo_catalog_free (&incatalog);
-    }
-    SkyListFree (inlist);
-
-    // load in all of the tables from input2 for this region
-    inlist = SkyListByBounds (insky2, depth2, outsky[0].regions[i].Rmin, outsky[0].regions[i].Rmax, outsky[0].regions[i].Dmin, outsky[0].regions[i].Dmax);
-    for (j = 0; j < inlist[0].Nregions; j++) {
-      fprintf (stderr, "input 2: %s\n", inlist[0].regions[j][0].name);
-
-      // load input catalog (1)
-      LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r");
-
-      // skip empty input catalogs
-      if (!incatalog.Naves_disk) {
-	dvo_catalog_unlock (&incatalog);
-	dvo_catalog_free (&incatalog);
-	continue;
-      }
-      merge_catalogs_old (&outsky[0].regions[i], &outcatalog, &incatalog, RADIUS);
-      dvo_catalog_unlock (&incatalog);
-      dvo_catalog_free (&incatalog);
-    }
-    SkyListFree (inlist);
-
-    outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
-    dvo_catalog_save (&outcatalog, VERBOSE);
-    dvo_catalog_unlock (&outcatalog);
-    dvo_catalog_free (&outcatalog);
-  }
-
-  // save the output sky table copy
-  sprintf (filename, "%s/SkyTable.fits", output);
-  check_file_access (filename, TRUE, TRUE, VERBOSE);
-  if (!SkyTableSave (outsky, filename)) {
-    fprintf (stderr, "ERROR: failed to save sky table for %s\n", output);
-    exit (1);
-  }
-
-  exit (0);
+  if (argc == 6) dvomergeCreate (argc, argv);
+  if (argc == 4) dvomergeUpdate (argc, argv);
+  usage();
+  exit (2); // cannot reach here.
 }
 
-/* 
+/* we have two possible modes of operation:
 
-   for the upgrade of the synth database, at a minimum I need to use an output format that uses
-   doubles for the astrometry.  Optionally I should merge in the 2MASS photometry measurements, since that
-   would be quite useful for comparison.  
+   Create : dvomerge (in1) and (in2) to (out) -- create a new db from two input dbs
+   Update : dvomerge (in) into (out)          -- merge a new db into an existing db
 
-   generality questions:
-   * optional
-
-
-
-   */
-
+*/
Index: trunk/Ohana/src/dvomerge/src/dvomergeCreate.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/dvomergeCreate.c	(revision 27435)
+++ trunk/Ohana/src/dvomerge/src/dvomergeCreate.c	(revision 27435)
@@ -0,0 +1,199 @@
+# include "dvomerge.h"
+
+// dvomergeCreate (catdir.in1) and (catdir.in2) to (catdir.output)
+// the output db may have a different SKY_DEPTH from the input dbs
+int dvomergeCreate (int argc, char **argv) {
+
+  int depth1, depth2;
+  off_t i, j, Ns, Ne;
+  SkyTable *outsky, *insky1, *insky2;
+  SkyList *inlist;
+  Catalog incatalog, outcatalog;
+  char filename[256], *input1, *input2, *output;
+  IDmapType IDmap1, IDmap2;
+
+  if (strcasecmp (argv[2], "and")) usage();
+  if (strcasecmp (argv[4], "to")) usage();
+
+  input1 = argv[1];
+  input2 = argv[3];
+  output = argv[5];
+
+  dvomergeImagesCreate (&IDmap1, input1, &IDmap2, input2, output);
+
+  // the first input defines the photcode table & db layout
+  sprintf (filename, "%s/Photcodes.dat", input1);
+  if (!LoadPhotcodes (filename, NULL, FALSE)) {
+    fprintf (stderr, "error loading photcode table %s\n", filename);
+    exit (1);
+  }
+  // save the photcodes in the output catdir
+  sprintf (filename, "%s/Photcodes.dat", output);
+  if (!check_file_access (filename, TRUE, TRUE, VERBOSE)) {
+    fprintf (stderr, "error creating output catdir %s\n", output);
+    exit (1);
+  }
+  if (!SavePhotcodesFITS (filename)) {
+    fprintf (stderr, "error saving photcode table %s\n", filename);
+    exit (1);
+  }
+
+  // load the sky table for the existing database
+  insky1 = SkyTableLoadOptimal (input1, NULL, NULL, FALSE, SKY_DEPTH_HST, VERBOSE);
+  SkyTableSetFilenames (insky1, input1, "cpt");
+
+  insky2 = SkyTableLoadOptimal (input2, NULL, NULL, FALSE, SKY_DEPTH_HST, VERBOSE);
+  SkyTableSetFilenames (insky2, input2, "cpt");
+
+  // generate an output table populated at the desired depth
+  outsky = SkyTableLoadOptimal (output, NULL, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
+  SkyTableSetFilenames (outsky, output, "cpt");
+
+  // loop over the populatable output tables; check for data in input1 and/or input2
+  // in the corresponding regions
+
+  SkyTablePopulatedRange (&Ns, &Ne, insky1, 0);
+  depth1 = insky1[0].regions[Ns].depth;
+  
+  SkyTablePopulatedRange (&Ns, &Ne, insky2, 0);
+  depth2 = insky2[0].regions[Ns].depth;
+
+  // loop over the populatable output regions
+  for (i = 0; i < outsky[0].Nregions; i++) {
+    if (!outsky[0].regions[i].table) continue;
+    if (VERBOSE) fprintf (stderr, "output: %s\n", outsky[0].regions[i].name);
+
+    // load / create output catalog
+    LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w");
+
+    // combine only tables at equal or larger depth
+      
+    // load in all of the tables from input1 for this region
+    inlist = SkyListByBounds (insky1, depth1, outsky[0].regions[i].Rmin, outsky[0].regions[i].Rmax, outsky[0].regions[i].Dmin, outsky[0].regions[i].Dmax);
+    for (j = 0; j < inlist[0].Nregions; j++) {
+      if (VERBOSE) fprintf (stderr, "input 1: %s\n", inlist[0].regions[j][0].name);
+
+      // load input catalog (1)
+      LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r");
+
+      // skip empty input catalogs
+      if (!incatalog.Naves_disk) {
+	dvo_catalog_unlock (&incatalog);
+	dvo_catalog_free (&incatalog);
+	continue;
+      }
+      dvo_update_image_IDs (&IDmap1, &incatalog);
+      merge_catalogs_new (&outsky[0].regions[i], &outcatalog, &incatalog);
+      dvo_catalog_unlock (&incatalog);
+      dvo_catalog_free (&incatalog);
+    }
+    SkyListFree (inlist);
+
+    // load in all of the tables from input2 for this region
+    inlist = SkyListByBounds (insky2, depth2, outsky[0].regions[i].Rmin, outsky[0].regions[i].Rmax, outsky[0].regions[i].Dmin, outsky[0].regions[i].Dmax);
+    for (j = 0; j < inlist[0].Nregions; j++) {
+      if (VERBOSE) fprintf (stderr, "input 2: %s\n", inlist[0].regions[j][0].name);
+
+      // load input catalog (1)
+      LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r");
+
+      // skip empty input catalogs
+      if (!incatalog.Naves_disk) {
+	dvo_catalog_unlock (&incatalog);
+	dvo_catalog_free (&incatalog);
+	continue;
+      }
+      dvo_update_image_IDs (&IDmap2, &incatalog);
+      merge_catalogs_old (&outsky[0].regions[i], &outcatalog, &incatalog, RADIUS);
+      dvo_catalog_unlock (&incatalog);
+      dvo_catalog_free (&incatalog);
+    }
+    SkyListFree (inlist);
+
+    outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
+    dvo_catalog_save (&outcatalog, VERBOSE);
+    dvo_catalog_unlock (&outcatalog);
+    dvo_catalog_free (&outcatalog);
+  }
+
+  // save the output sky table copy
+  sprintf (filename, "%s/SkyTable.fits", output);
+  check_file_access (filename, TRUE, TRUE, VERBOSE);
+  if (!SkyTableSave (outsky, filename)) {
+    fprintf (stderr, "ERROR: failed to save sky table for %s\n", output);
+    exit (1);
+  }
+
+  exit (0);
+}
+
+  /*** update the image table ***/
+int dvomergeImagesCreate (IDmapType *IDmap1, char *input1, IDmapType *IDmap2, char *input2, char *output) { 
+
+    FITS_DB in1DB;
+    FITS_DB in2DB;
+    FITS_DB outDB;
+    int    status;
+
+    /*** load output/Images.dat ***/
+    sprintf (ImageCat, "%s/Images.dat", output);
+    outDB.mode   = dvo_catalog_catmode (CATMODE);
+    outDB.format = dvo_catalog_catformat (CATFORMAT);
+    status       = dvo_image_lock (&outDB, ImageCat, 3600.0, LCK_XCLD);  // shorter timeout?
+    if (!status) Shutdown ("ERROR: failure to lock image catalog %s", outDB.filename);
+
+    // output image table should not already exist
+    if (outDB.dbstate != LCK_EMPTY) {
+      Shutdown ("ERROR: image table %s already exists", outDB.filename);
+    }
+    dvo_image_create (&outDB, GetZeroPoint());
+
+
+    /*** load input1/Images.dat ***/
+    sprintf (ImageCat, "%s/Images.dat", input1);
+    in1DB.mode   = dvo_catalog_catmode (CATMODE);
+    in1DB.format = dvo_catalog_catformat (CATFORMAT);
+    status       = dvo_image_lock (&in1DB, ImageCat, 3600.0, LCK_XCLD);  // shorter timeout?
+    if (!status) Shutdown ("ERROR: failure to lock image catalog %s", in1DB.filename);
+
+    // load the image table 
+    if (in1DB.dbstate == LCK_EMPTY) {
+      Shutdown ("can't find input (1) image catalog %s", in1DB.filename);
+    }
+    if (!dvo_image_load (&in1DB, VERBOSE, TRUE)) {
+      Shutdown ("can't read input (1) image catalog %s", in1DB.filename);
+    }
+
+    // convert database table to internal structure & add to output image db
+    dvo_image_merge_dbs(IDmap1, &outDB, &in1DB);
+    dvo_image_unlock (&in1DB); // unlock input1
+
+
+    /*** load input2/Images.dat ***/
+    sprintf (ImageCat, "%s/Images.dat", input2);
+    in2DB.mode   = dvo_catalog_catmode (CATMODE);
+    in2DB.format = dvo_catalog_catformat (CATFORMAT);
+    status       = dvo_image_lock (&in2DB, ImageCat, 3600.0, LCK_XCLD);  // shorter timeout?
+    if (!status) Shutdown ("ERROR: failure to lock image catalog %s", in2DB.filename);
+
+    /* load the image table */
+    if (in2DB.dbstate == LCK_EMPTY) {
+      Shutdown ("can't find input (2) image catalog %s", in2DB.filename);
+    }
+    if (!dvo_image_load (&in2DB, VERBOSE, TRUE)) {
+      Shutdown ("can't read input (2) image catalog %s", in2DB.filename);
+    }
+
+    // convert database table to internal structure & add to output image db
+    dvo_image_merge_dbs(IDmap2, &outDB, &in2DB);
+    dvo_image_unlock (&in2DB); // unlock input2
+
+    // write out the image table
+    SetProtect (TRUE);
+    dvo_image_save (&outDB, VERBOSE);
+    SetProtect (FALSE);
+    dvo_image_unlock (&outDB); // unlock output
+
+    return TRUE;
+  }
+
Index: trunk/Ohana/src/dvomerge/src/dvomergeUpdate.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/dvomergeUpdate.c	(revision 27435)
+++ trunk/Ohana/src/dvomerge/src/dvomergeUpdate.c	(revision 27435)
@@ -0,0 +1,135 @@
+# include "dvomerge.h"
+
+int dvomergeUpdate (int argc, char **argv) {
+
+  int depth;
+  off_t i, j, Ns, Ne;
+  SkyTable *outsky, *insky;
+  SkyList *inlist;
+  Catalog incatalog, outcatalog;
+  char filename[256], *input, *output;
+  IDmapType IDmap;
+
+  if (strcasecmp (argv[2], "into")) usage();
+
+  input  = argv[1];
+  output = argv[3];
+
+  // the first input defines the photcode table & db layout
+  sprintf (filename, "%s/Photcodes.dat", input);
+  if (!LoadPhotcodes (filename, NULL, FALSE)) {
+    fprintf (stderr, "error loading photcode table %s\n", filename);
+    exit (1);
+  }
+
+  dvomergeImagesUpdate (&IDmap, input, output);
+
+  // load the sky table for the existing database
+  insky = SkyTableLoadOptimal (input, NULL, NULL, FALSE, SKY_DEPTH_HST, VERBOSE);
+  SkyTableSetFilenames (insky, input, "cpt");
+
+  // generate an output table populated at the desired depth
+  outsky = SkyTableLoadOptimal (output, NULL, NULL, TRUE, SKY_DEPTH, VERBOSE);
+  SkyTableSetFilenames (outsky, output, "cpt");
+
+  // loop over the populatable output tables; check for data in input in the corresponding regions
+
+  SkyTablePopulatedRange (&Ns, &Ne, insky, 0);
+  depth = insky[0].regions[Ns].depth;
+  
+  // loop over the populatable output regions
+  for (i = 0; i < outsky[0].Nregions; i++) {
+    if (!outsky[0].regions[i].table) continue;
+    if (VERBOSE) fprintf (stderr, "output: %s\n", outsky[0].regions[i].name);
+
+    // load / create output catalog
+    LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "a");
+
+    // combine only tables at equal or larger depth
+      
+    // load in all of the tables from input for this region
+    inlist = SkyListByBounds (insky, depth, outsky[0].regions[i].Rmin, outsky[0].regions[i].Rmax, outsky[0].regions[i].Dmin, outsky[0].regions[i].Dmax);
+    for (j = 0; j < inlist[0].Nregions; j++) {
+      if (VERBOSE) fprintf (stderr, "input : %s\n", inlist[0].regions[j][0].name);
+
+      // load input catalog
+      LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r");
+
+      // skip empty input catalogs
+      if (!incatalog.Naves_disk) {
+	dvo_catalog_unlock (&incatalog);
+	dvo_catalog_free (&incatalog);
+	continue;
+      }
+      dvo_update_image_IDs (&IDmap, &incatalog);
+      merge_catalogs_old (&outsky[0].regions[i], &outcatalog, &incatalog, RADIUS);
+      dvo_catalog_unlock (&incatalog);
+      dvo_catalog_free (&incatalog);
+    }
+    SkyListFree (inlist);
+
+    outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
+    dvo_catalog_save (&outcatalog, VERBOSE);
+    dvo_catalog_unlock (&outcatalog);
+    dvo_catalog_free (&outcatalog);
+  }
+
+  // save the output sky table copy
+  sprintf (filename, "%s/SkyTable.fits", output);
+  check_file_access (filename, TRUE, TRUE, VERBOSE);
+  if (!SkyTableSave (outsky, filename)) {
+    fprintf (stderr, "ERROR: failed to save sky table for %s\n", output);
+    exit (1);
+  }
+
+  exit (0);
+}
+
+/*** update the image table ***/
+int dvomergeImagesUpdate (IDmapType *IDmap, char *input, char *output) { 
+
+  FITS_DB inDB;
+  FITS_DB outDB;
+  int    status;
+
+  /*** load input1/Images.dat ***/
+  sprintf (ImageCat, "%s/Images.dat", input);
+  inDB.mode   = dvo_catalog_catmode (CATMODE);
+  inDB.format = dvo_catalog_catformat (CATFORMAT);
+  status       = dvo_image_lock (&inDB, ImageCat, 3600.0, LCK_XCLD);  // shorter timeout?
+  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", inDB.filename);
+
+  // load the image table 
+  if (inDB.dbstate == LCK_EMPTY) {
+    Shutdown ("can't find input (1) image catalog %s", inDB.filename);
+  }
+  if (!dvo_image_load (&inDB, VERBOSE, TRUE)) {
+    Shutdown ("can't read input (1) image catalog %s", inDB.filename);
+  }
+
+  /*** load output/Images.dat ***/
+  sprintf (ImageCat, "%s/Images.dat", output);
+  outDB.mode   = dvo_catalog_catmode (CATMODE);
+  outDB.format = dvo_catalog_catformat (CATFORMAT);
+  status       = dvo_image_lock (&outDB, ImageCat, 3600.0, LCK_XCLD);  // shorter timeout?
+  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", outDB.filename);
+
+  /* load the image table */
+  if (outDB.dbstate == LCK_EMPTY) {
+    Shutdown ("can't find input (2) image catalog %s", outDB.filename);
+  }
+  if (!dvo_image_load (&outDB, VERBOSE, TRUE)) {
+    Shutdown ("can't read input (2) image catalog %s", outDB.filename);
+  }
+
+  // convert database table to internal structure & add to output image db
+  dvo_image_merge_dbs(IDmap, &outDB, &inDB);
+  dvo_image_unlock (&inDB); // unlock input
+
+  SetProtect (TRUE);
+  dvo_image_save (&outDB, VERBOSE);
+  SetProtect (FALSE);
+  dvo_image_unlock (&outDB); // unlock output
+
+  return TRUE;
+}
Index: trunk/Ohana/src/dvomerge/src/help.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/help.c	(revision 27435)
+++ trunk/Ohana/src/dvomerge/src/help.c	(revision 27435)
@@ -0,0 +1,42 @@
+# include "dvomerge.h"
+
+void usage (void) {
+  fprintf (stderr, "USAGE: dvomerge (input1) and (input2) to (output)\n");
+  fprintf (stderr, "   OR: dvomerge (input) into (output)\n");
+  exit (2);
+}
+
+void help (int argc, char **argv) {
+
+  /* check for help request */
+  if (get_argument (argc, argv, "-help")) goto show_help;
+  if (get_argument (argc, argv, "-h"))    goto show_help;
+  return;
+
+show_help:
+
+  fprintf (stderr, "USAGE\n");
+  fprintf (stderr, "  dvosplit (newlevel)\n\n");
+  fprintf (stderr, "  optional flags:\n");
+  fprintf (stderr, "  -region ra ra dec dec 	  : migrate catalogs in specified region\n");
+  fprintf (stderr, "  -v                    	  : verbose mode\n");
+  fprintf (stderr, "  -help                 	  : this list\n");
+  fprintf (stderr, "  -h                    	  : this list\n\n");
+  exit (2);
+}
+
+/** addstar modes:
+ 
+    addstar (image.smp)  - add cmp/smp image data to db
+    addstar -ref (file.dat) (photcode) 
+    addstar -cat (USNO/2MASS/GSC) -region (ra dec - ra dec)
+
+    -replace : ref/cat - replace existing match (photcode/time)
+    -match   : ref/cat - only add measures to existing averages
+
+    ref types: 
+    ASCII - RA,DEC,M,dM in a table
+
+    addstar 
+
+**/
Index: trunk/Ohana/src/dvomerge/src/merge_catalogs.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/merge_catalogs.c	(revision 27392)
+++ trunk/Ohana/src/dvomerge/src/merge_catalogs.c	(revision 27435)
@@ -5,6 +5,6 @@
 int merge_catalogs_new (Catalog *output, Catalog *input) {
   
-  int i, j, offset;
-  int NAVERAGE, NMEASURE, Naverage, Nmeasure, Nsecfilt, Nm;
+  off_t i, j, offset;
+  off_t NAVERAGE, NMEASURE, Naverage, Nmeasure, Nsecfilt, Nm;
 
   Naverage = output[0].Naverage;
Index: trunk/Ohana/src/dvomerge/src/merge_catalogs_new.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/merge_catalogs_new.c	(revision 27392)
+++ trunk/Ohana/src/dvomerge/src/merge_catalogs_new.c	(revision 27435)
@@ -9,6 +9,6 @@
 int merge_catalogs_new (SkyRegion *region, Catalog *output, Catalog *input) {
   
-  int i, j, offset;
-  int NAVERAGE, NMEASURE, Naverage, Nmeasure, Nsecfilt, Nm;
+  off_t i, j, offset;
+  off_t NAVERAGE, NMEASURE, Naverage, Nmeasure, Nsecfilt, Nm;
 
   Naverage = output[0].Naverage;
@@ -64,8 +64,16 @@
   output[0].Nmeasure = Nmeasure;
   output[0].Nsecf_mem = Naverage * Nsecfilt;
+
+  // If we are using dvomergeCreate to split an existing catalog, then the max objID in
+  // each of the new subdivisions of the original catalog is the max objID of the original
+  // catalog.  It is not allowed to use dvomerge to unify catalogs to a lower-resolution
+  // partition.
+  output[0].objID = input[0].objID; // new max value, save on catalog close
   
   if (VERBOSE) {
-      fprintf (stderr, "%d: using %d stars (%d measures) for catalog\n", i, 
-	       output[0].Naverage, output[0].Nmeasure);
+      fprintf (stderr, "%lld: using %lld stars (%lld measures) for catalog\n", 
+	       (long long) i, 
+	       (long long) output[0].Naverage, 
+	       (long long) output[0].Nmeasure);
   }
   return (TRUE);
Index: trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c	(revision 27392)
+++ trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c	(revision 27435)
@@ -1,3 +1,4 @@
 # include "dvomerge.h"
+# define PSPS_ID TRUE
 
 # define IN_REGION(R,D) ( \
@@ -9,10 +10,10 @@
 int merge_catalogs_old (SkyRegion *region, Catalog *output, Catalog *input, double RADIUS) {
 
-  int i, j, n, N, Nin, offset, J, Jmin, status, Nstars;
+  off_t i, j, n, N, Nin, offset, J, Jmin, status, Nstars;
   double RADIUS2, Rmin, Rin, Din;
   double *X1, *Y1, *X2, *Y2;
   double dX, dY, dR;
-  int *N1, *N2,  *next_meas;
-  int Nave, NAVE, Nmeas, NMEAS, Nmatch;
+  off_t *N1, *N2,  *next_meas;
+  off_t Nave, NAVE, Nmeas, NMEAS, Nmatch;
   int Nsecfilt;
   unsigned int objID, catID;
@@ -24,6 +25,6 @@
   ALLOCATE (X1, double, input[0].Naverage);
   ALLOCATE (Y1, double, input[0].Naverage);
-  ALLOCATE (N1, int,    input[0].Naverage);
-  ALLOCATE (input[0].found, int, input[0].Naverage);
+  ALLOCATE (N1, off_t,  input[0].Naverage);
+  ALLOCATE (input[0].found, off_t, input[0].Naverage);
 
   /** allocate local arrays (catalog) **/
@@ -31,6 +32,6 @@
   ALLOCATE (X2, double, NAVE);
   ALLOCATE (Y2, double, NAVE);
-  ALLOCATE (N2, int,    NAVE);
-  ALLOCATE (output[0].found, int, NAVE);
+  ALLOCATE (N2, off_t,    NAVE);
+  ALLOCATE (output[0].found, off_t, NAVE);
   /* for secfilt j and star i, secfilt[i*Nsecfilt+j] */
 
@@ -119,10 +120,10 @@
     /* negative dX: j is too large */
     dX = X1[i] - X2[j];
-    if (dX <= -2*RADIUS) {
+    if (dX <= -1.02*RADIUS) {
       i++;
       continue;
     }
     /* positive dX, i is too large */
-    if (dX >= 2*RADIUS) {
+    if (dX >= 1.02*RADIUS) {
       j++;
       continue;
@@ -131,5 +132,5 @@
     Jmin = -1;
     Rmin = RADIUS2;
-    for (J = j; (dX > -2*RADIUS) && (J < Nave); J++) {
+    for (J = j; (dX > -1.02*RADIUS) && (J < Nave); J++) {
       /* find closest match for this detection */
       dX = X1[i] - X2[J];
@@ -157,9 +158,9 @@
     if (Nmeas + input[0].average[N].Nmeasure >= NMEAS) {
       NMEAS = Nmeas + input[0].average[N].Nmeasure + 1000;
-      REALLOCATE (next_meas, int, NMEAS);
+      REALLOCATE (next_meas, off_t, NMEAS);
       REALLOCATE (output[0].measure, Measure, NMEAS);
     }
 
-    /** add measurements for this input average object **/
+    /** add ALL measurements for this input average object **/
     for (Nin = 0; Nin < input[0].average[N].Nmeasure; Nin ++) {
       offset = input[0].average[N].measureOffset + Nin;
@@ -169,5 +170,5 @@
 	
       // set the new measurements
-      output[0].measure[Nmeas]          = input[0].measure[offset];
+      output[0].measure[Nmeas] = input[0].measure[offset];
 
       Rin = input[0].average[N].R - input[0].measure[offset].dR / 3600.0;
@@ -177,8 +178,10 @@
       output[0].measure[Nmeas].dR       = 3600.0*(output[0].average[n].R - Rin);  // XXX update these based on choice of astromety
       output[0].measure[Nmeas].dD       = 3600.0*(output[0].average[n].D - Din);  // XXX update these based on choice of astromety
-      output[0].measure[Nmeas].dbFlags  = 0;
+      output[0].measure[Nmeas].dbFlags  = 0;  // XXX why reset these?
       output[0].measure[Nmeas].averef   = n;
       output[0].measure[Nmeas].objID    = output[0].average[n].objID;
       output[0].measure[Nmeas].catID    = output[0].catID;
+
+      // fprintf (stderr, "Nave : %lld, Nmeas : %lld, dR: %f, dD: %f, catID: %d\n", (long long) n, (long long) Nmeas, output[0].measure[Nmeas].dR, output[0].measure[Nmeas].dD, output[0].measure[i].catID);
 
       // rationalize dR
@@ -197,6 +200,8 @@
 		 output[0].average[n].R, output[0].average[n].D, Rin, Din,
 		 X1[i], X2[Jmin], Y1[i], Y2[Jmin]);
+	// XXX abort on this? -- this is a bad failure...
       }
       input[0].found[N] = Nmeas;
+      output[0].average[n].Nmeasure ++;
       Nmeas ++;
     }
@@ -205,20 +210,21 @@
        Nm is recalculated in build_meas_links if loaded table is not sorted */
     output[0].found[n] = Nmeas;
-    output[0].average[n].Nmeasure ++;
     i++;
   }
+
+# if (0)
+  fprintf (stderr, "--- 1 ---\n");
+  for (i = 0; i < Nmeas; i++) {
+    fprintf (stderr, "Nave : %d, Nmeas : %lld, dR: %f, dD: %f, catID: %d\n", output[0].measure[i].averef, (long long) i, output[0].measure[i].dR, output[0].measure[i].dD, output[0].measure[i].catID);
+  }
+# endif
 
   /** incorporate unmatched image stars, if this star is in field of this catalog **/
   /* these new entries are all written out in UPDATE mode */ 
   for (i = 0; i < Nstars; i++) {
-
-    N = N1[i];
-    if (input[0].found[N] >= 0) continue;
-    if (!IN_REGION (input[0].average[N].R, input[0].average[N].D)) continue;
-
     /* make sure there is space for next entry */
     if (Nmeas + input[0].average[N].Nmeasure >= NMEAS) {
       NMEAS = Nmeas + input[0].average[N].Nmeasure + 1000;
-      REALLOCATE (next_meas, int, NMEAS);
+      REALLOCATE (next_meas, off_t, NMEAS);
       REALLOCATE (output[0].measure, Measure, NMEAS);
     }
@@ -229,4 +235,8 @@
     }
 
+    N = N1[i];
+    if (input[0].found[N] >= 0) continue;
+    if (!IN_REGION (input[0].average[N].R, input[0].average[N].D)) continue;
+
     output[0].average[Nave].R         	   = input[0].average[N].R;
     output[0].average[Nave].D         	   = input[0].average[N].D;
@@ -238,7 +248,7 @@
     output[0].average[Nave].Nextend        = 0;
 
-    output[0].average[Nave].measureOffset = Nmeas;
-    output[0].average[Nave].missingOffset = -1;
-    output[0].average[Nave].extendOffset  = -1;
+    output[0].average[Nave].measureOffset  = Nmeas;
+    output[0].average[Nave].missingOffset  = -1;
+    output[0].average[Nave].extendOffset   = -1;
 
     output[0].average[Nave].uR        	   = 0;
@@ -253,7 +263,12 @@
     output[0].average[Nave].Npos    	   = 0;
 
-    output[0].average[Nave].objID     	   = objID;
-    output[0].average[Nave].catID     	   = catID;
-    output[0].average[Nave].flags         = 0;
+    output[0].average[Nave].objID     	   = objID; // we create objID values in the context of the output db
+    output[0].average[Nave].catID     	   = catID; // we create catID values in the context of the output db
+    output[0].average[Nave].flags          = 0;  // XXX why reset these?
+    if (PSPS_ID) {
+      output[0].average[Nave].extID = CreatePSPSObjectID(output[0].average[Nave].R, output[0].average[Nave].D);
+    } else {
+      output[0].average[Nave].extID = 0;
+    }
 
     objID ++;
@@ -288,4 +303,8 @@
       Nmeas ++;
     }
+    int Ngroup = input[0].average[N].Nmeasure;
+    for (j = 0; j < Ngroup - 1; j++) {
+	next_meas[Nmeas - Ngroup + j] = Nmeas - Ngroup + j + 1;
+    }
     Nave ++;
   }
@@ -294,5 +313,12 @@
   REALLOCATE (output[0].measure, Measure, Nmeas);
  
-# define NOSORT TRUE
+# if (0)
+  fprintf (stderr, "--- 2 ---\n");
+  for (i = 0; i < Nmeas; i++) {
+    fprintf (stderr, "Nave : %d, Nmeas : %lld, dR: %f, dD: %f, catID: %d\n", output[0].measure[i].averef, (long long) i, output[0].measure[i].dR, output[0].measure[i].dD, output[0].measure[i].catID);
+  }
+# endif
+
+# define NOSORT FALSE
   if (NOSORT) {
     output[0].sorted = FALSE;
@@ -301,4 +327,11 @@
     output[0].measure = sort_measure (output[0].average, Nave, output[0].measure, Nmeas, next_meas);
   }
+
+# if (0)
+  fprintf (stderr, "--- 3 ---\n");
+  for (i = 0; i < Nmeas; i++) {
+    fprintf (stderr, "Nave : %d, Nmeas : %lld, dR: %f, dD: %f, catID: %d\n", output[0].measure[i].averef, (long long) i, output[0].measure[i].dR, output[0].measure[i].dD, output[0].measure[i].catID);
+  }
+# endif
 
   /* note stars which have been found in this catalog */
@@ -316,5 +349,5 @@
   output[0].Nmeasure = Nmeas;
   output[0].Nsecf_mem = Nave*Nsecfilt;
-  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmatch);
+  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %lld %lld %lld, (%lld matches)\n", (long long) Nstars, (long long) Nave, (long long) Nmeas, (long long) Nmatch);
 
   free (next_meas);
Index: trunk/Ohana/src/dvomerge/src/psps_ids.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/psps_ids.c	(revision 27435)
+++ trunk/Ohana/src/dvomerge/src/psps_ids.c	(revision 27435)
@@ -0,0 +1,34 @@
+# include "dvomerge.h"
+
+// Compute IDs for PSPS based on recipe they defined
+
+uint64_t
+CreatePSPSDetectionID(double tobs, int ccdid, int detID)
+{
+    // t0 for detection id is 2007-01-01 00:00:00 utc
+    double  t0 = 54101.0;
+    double diff = floor( 100000. * (tobs - t0) );
+    int itmp = diff;
+
+    // ccdid must be < 100
+    uint64_t detectid = 1000000000*((uint64_t) itmp) + 10000000 * ((uint64_t) ccdid) +
+             ((uint64_t) detID);
+
+    return detectid;
+}
+    
+uint64_t
+CreatePSPSObjectID(double ra, double dec)
+{
+    double zh = 0.0083333;
+    double zid = (dec + 90.) / zh;             // 0 - 180*60*2 = 21600 < 15 bits
+    int izone = (int) floor(zid);
+    double zresid = zid -  ((float) izone);    // 0.0 - 1.0
+
+    uint64_t part1, part2, part3;
+    part1 = (uint64_t)( izone  * 10000000000000LL) ; 
+    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/dvomerge/src/usage.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/usage.c	(revision 27392)
+++ 	(revision )
@@ -1,7 +1,0 @@
-# include "dvomerge.h"
-
-void usage (void) {
-  fprintf (stderr, "USAGE: dvomerge (input1) and (input2) to (output)\n");
-  exit (2);
-}
-
Index: trunk/Ohana/src/dvosplit/include/dvosplit.h
===================================================================
--- trunk/Ohana/src/dvosplit/include/dvosplit.h	(revision 27392)
+++ trunk/Ohana/src/dvosplit/include/dvosplit.h	(revision 27435)
@@ -35,5 +35,5 @@
 void       SetProtect             PROTO((int mode));
 void       TrapSignal             PROTO((int sig));
-int        Shutdown               PROTO((char *format, ...));
+int        Shutdown               PROTO((char *format, ...) OHANA_FORMAT(printf, 1, 2));
 int        args                   PROTO((int argc, char **argv));
 
Index: trunk/Ohana/src/elixir/src/DumpStatus.c
===================================================================
--- trunk/Ohana/src/elixir/src/DumpStatus.c	(revision 27392)
+++ trunk/Ohana/src/elixir/src/DumpStatus.c	(revision 27435)
@@ -18,5 +18,5 @@
     f = fsetlockfile (filename, 0.1, LCK_XCLD, &state);
     if (f == NULL) return (2);
-    fseek (f, 0, SEEK_END);
+    fseeko (f, 0, SEEK_END);
   }  
   
Index: trunk/Ohana/src/elixir/src/MachineOps.c
===================================================================
--- trunk/Ohana/src/elixir/src/MachineOps.c	(revision 27392)
+++ trunk/Ohana/src/elixir/src/MachineOps.c	(revision 27435)
@@ -454,5 +454,5 @@
     f = fsetlockfile (filename, 0.1, LCK_XCLD, &state);
     if (f == NULL) return (2);
-    fseek (f, 0, SEEK_END);
+    fseeko (f, 0, SEEK_END);
   }  
 
Index: trunk/Ohana/src/elixir/src/MsgOps.c
===================================================================
--- trunk/Ohana/src/elixir/src/MsgOps.c	(revision 27392)
+++ trunk/Ohana/src/elixir/src/MsgOps.c	(revision 27435)
@@ -99,5 +99,5 @@
 
   /* write message to end of file */
-  fseek (f, 0, SEEK_END);
+  fseeko (f, 0, SEEK_END);
   fprintf (f, "%s\n", message);
 
Index: trunk/Ohana/src/elixir/src/ProcessOps.c
===================================================================
--- trunk/Ohana/src/elixir/src/ProcessOps.c	(revision 27392)
+++ trunk/Ohana/src/elixir/src/ProcessOps.c	(revision 27435)
@@ -203,5 +203,5 @@
   switch (Nterms) {
   case 0:
-    sprintf (line, format); 
+    sprintf (line, "%s", format); 
     break;
   case 1:
Index: trunk/Ohana/src/fixcat/src/aregion.c
===================================================================
--- trunk/Ohana/src/fixcat/src/aregion.c	(revision 27392)
+++ trunk/Ohana/src/fixcat/src/aregion.c	(revision 27435)
@@ -79,5 +79,5 @@
     NLINES += NDecLines[i];
   }
-  fseek (f, 5*2880 + 48*NLINES, SEEK_SET);
+  fseeko (f, 5*2880 + 48*NLINES, SEEK_SET);
       
   done = FALSE;
Index: trunk/Ohana/src/fixcat/src/find_bright_stars.c
===================================================================
--- trunk/Ohana/src/fixcat/src/find_bright_stars.c	(revision 27392)
+++ trunk/Ohana/src/fixcat/src/find_bright_stars.c	(revision 27435)
@@ -6,10 +6,11 @@
 {
 
-  int i, j, n, m, first_j, Nave, Ngsc;
+  int j, n, m, first_j, Ngsc;
   Catalog GSCdata;
   double MinRA, MinDEC, MaxRA, MaxDEC, RaCenter, DecCenter;
   Coords *tcoords;
   double *X1, *Y1, *X2, *Y2;
-  int *N1, *N2;
+  off_t i, Nave;
+  off_t *N1, *N2;
   char *mark;
   double dX, dY, dR, MaxDist, MaxDist1, MaxRadius, radius, radius2;
@@ -27,5 +28,5 @@
   ALLOCATE (X1, double, Ngsc);
   ALLOCATE (Y1, double, Ngsc);
-  ALLOCATE (N1, int, Ngsc);
+  ALLOCATE (N1, off_t, Ngsc);
   ALLOCATE (mark, char, Nave);
   bzero (mark, Nave);
Index: trunk/Ohana/src/fixcat/src/find_images.c
===================================================================
--- trunk/Ohana/src/fixcat/src/find_images.c	(revision 27392)
+++ trunk/Ohana/src/fixcat/src/find_images.c	(revision 27435)
@@ -73,5 +73,5 @@
     exit (0);
   }
-  fseek (f, header.size, SEEK_SET); 
+  fseeko (f, header.datasize, SEEK_SET); 
 
   /* set up buffers for images, temporary storage */
Index: trunk/Ohana/src/fixcat/src/find_matches.c
===================================================================
--- trunk/Ohana/src/fixcat/src/find_matches.c	(revision 27392)
+++ trunk/Ohana/src/fixcat/src/find_matches.c	(revision 27435)
@@ -11,5 +11,5 @@
   double *X1, *Y1, *X2, *Y2;
   double dX, dY, dR;
-  int *N1, *N2;
+  off_t *N1, *N2;
   int Nstar, Nghost, Ng;
   unsigned int flags;
@@ -29,5 +29,5 @@
   ALLOCATE (X1, double, Nghost);
   ALLOCATE (Y1, double, Nghost);
-  ALLOCATE (N1, int, Nghost);
+  ALLOCATE (N1, off_t, Nghost);
 
   /* project ghosts to the frame of the catalog */
Index: trunk/Ohana/src/fixcat/src/gcatalog.c
===================================================================
--- trunk/Ohana/src/fixcat/src/gcatalog.c	(revision 27392)
+++ trunk/Ohana/src/fixcat/src/gcatalog.c	(revision 27435)
@@ -28,5 +28,5 @@
     exit (0);
   }
-  fseek (f, catalog[0].header.size, SEEK_SET); 
+  fseeko (f, catalog[0].header.datasize, SEEK_SET); 
 
   /** find number of stars, measurements **/
Index: trunk/Ohana/src/fixcat/src/gcatstats.c
===================================================================
--- trunk/Ohana/src/fixcat/src/gcatstats.c	(revision 27392)
+++ trunk/Ohana/src/fixcat/src/gcatstats.c	(revision 27435)
@@ -6,9 +6,8 @@
 {
 
-  int i;
+  off_t i;
   double RaCenter, DecCenter;
   double MinRA, MaxRA, MinDEC, MaxDEC;
   double *X1, *Y1;
-  int *N1;
   Coords tcoords;
   
Index: trunk/Ohana/src/fixcat/src/wcatalog.c
===================================================================
--- trunk/Ohana/src/fixcat/src/wcatalog.c	(revision 27392)
+++ trunk/Ohana/src/fixcat/src/wcatalog.c	(revision 27435)
@@ -1,10 +1,8 @@
 # include "markstar.h"
 
-wcatalog (catname, catalog)
-char *catname;
-Catalog catalog[];
-{
+int wcatalog (char *catname, catalog *catalog) {
   
-  int i, Nitems, nitems, status, mode;
+  int status, mode;
+  off_t i, Nitems, nitems;
   char filename[128], line[256];
   FILE *f;
@@ -36,11 +34,11 @@
   chmod (filename, mode);
   
-  gfits_modify (&catalog[0].header, "NSTARS", "%d", 1, catalog[0].Naverage);
-  gfits_modify (&catalog[0].header, "NMEAS", "%d", 1, catalog[0].Nmeasure);
-  gfits_modify (&catalog[0].header, "NMISS", "%d", 1, catalog[0].Nmissing);
+  gfits_modify (&catalog[0].header, "NSTARS", "%lld", 1, catalog[0].Naverage);
+  gfits_modify (&catalog[0].header, "NMEAS",  "%lld", 1, catalog[0].Nmeasure);
+  gfits_modify (&catalog[0].header, "NMISS",  "%lld", 1, catalog[0].Nmissing);
 
-  gfits_modify (&catalog[0].header, "MARKSTAR", "%t", 1, TRUE);
+  gfits_modify_alt (&catalog[0].header, "MARKSTAR", "%t", 1, TRUE);
 
-  nitems = Fwrite (catalog[0].header.buffer, 1, catalog[0].header.size, f, "char");
+  nitems = Fwrite (catalog[0].header.buffer, 1, catalog[0].header.datasize, f, "char");
   if (nitems != catalog[0].header.size) {
     fprintf (stderr, "ERROR: failed to write header\n");
@@ -71,4 +69,4 @@
   fclose (f);
 
+  return TRUE;
 }
-
Index: trunk/Ohana/src/gastro/src/getusno.c
===================================================================
--- trunk/Ohana/src/gastro/src/getusno.c	(revision 27392)
+++ trunk/Ohana/src/gastro/src/getusno.c	(revision 27435)
@@ -11,5 +11,5 @@
 USNOdata *getusno (USNOstats *usnostats, CatStats *catstats, int *Nusno) {
 
-  long int offset;
+  off_t offset;
   int i, bin, first, last, nitems, Nitems, Nbins;
   float hours[100];
@@ -91,5 +91,5 @@
     /* advance file pointer to first slice */
     offset = 3*sizeof(int)*(start[first] - 1);
-    fseek (f, offset, SEEK_SET);
+    fseeko (f, offset, SEEK_SET);
     /* on each loop, load data from an RA slice of the catalog */
     for (bin = first; bin < last; bin++) {
Index: trunk/Ohana/src/gastro/src/gfit.c
===================================================================
--- trunk/Ohana/src/gastro/src/gfit.c	(revision 27392)
+++ trunk/Ohana/src/gastro/src/gfit.c	(revision 27435)
@@ -7,6 +7,6 @@
 int gfit (SStars *stars1, SStars *stars2, int N1, int N2, Coords *coords, int NX, int NY, double *Radius, double *DR, int *Nmatch, int mode) {
   
-  int i, j, iteration, Niter, last, halt, first_j, *Nextra, extras;
-  int *tmpN1, *tmpN2;
+  int i, j, iteration, Niter, last, halt, first_j, extras;
+  off_t *tmpN1, *tmpN2;
   double X_O, X_X, X_Y, dX;
   double Y_O, Y_X, Y_Y, dY;
@@ -42,11 +42,9 @@
   ALLOCATE (tmpX1, double, N1);
   ALLOCATE (tmpY1, double, N1);
-  ALLOCATE (tmpN1, int, N1);
+  ALLOCATE (tmpN1, off_t, N1);
   
   ALLOCATE (tmpX2, double, N2);
   ALLOCATE (tmpY2, double, N2);
-  ALLOCATE (tmpN2, int, N2);
-  ALLOCATE (Nextra, int, N2);
-  bzero (Nextra, sizeof(int) * N2);
+  ALLOCATE (tmpN2, off_t, N2);
 
   dX = dY = N = 0;
Index: trunk/Ohana/src/gastro/src/gfitpoly.c
===================================================================
--- trunk/Ohana/src/gastro/src/gfitpoly.c	(revision 27392)
+++ trunk/Ohana/src/gastro/src/gfitpoly.c	(revision 27435)
@@ -5,5 +5,5 @@
   int i, j, m, n, M, N;
   int first_j, last;
-  int *tmpN1, *tmpN2;
+  off_t *tmpN1, *tmpN2;
   int NORDER, NTERM, NPARS, NPOWR;
   double **sum, **xsum, **ysum;
@@ -52,9 +52,9 @@
   ALLOCATE (tmpX1, double, N1);
   ALLOCATE (tmpY1, double, N1);
-  ALLOCATE (tmpN1, int, N1);
+  ALLOCATE (tmpN1, off_t, N1);
 
   ALLOCATE (tmpX2, double, N2);
   ALLOCATE (tmpY2, double, N2);
-  ALLOCATE (tmpN2, int, N2);
+  ALLOCATE (tmpN2, off_t, N2);
 
   /* assign and sort list */
Index: trunk/Ohana/src/gastro/src/gheader.c
===================================================================
--- trunk/Ohana/src/gastro/src/gheader.c	(revision 27392)
+++ trunk/Ohana/src/gastro/src/gheader.c	(revision 27435)
@@ -5,5 +5,5 @@
   Header header;
   FILE *f, *g;
-  int i, oldsize, nbytes, status;
+  off_t i, oldsize, nbytes, status;
   char line[1024];
 
@@ -12,5 +12,5 @@
     exit(0);
   }
-  oldsize = header.size;
+  oldsize = header.datasize;
 
   /* validating the photcode name should be the job of DVO/addstar */
@@ -22,10 +22,10 @@
   if (Nmatch < 2) {
     gfits_modify (&header, "NASTRO", "%d", 1, 0);
-    gfits_modify (&header, "NASTRO", "%C", 1, "number of stars used for astrometry");
+    gfits_modify_alt (&header, "NASTRO", "%C", 1, "number of stars used for astrometry");
     goto skipstuff;
   }
   
   gfits_modify (&header, "NASTRO", "%d", 1, Nmatch);
-  gfits_modify (&header, "NASTRO", "%C", 1, "number of stars used for astrometry");
+  gfits_modify_alt (&header, "NASTRO", "%C", 1, "number of stars used for astrometry");
 
   /*** use PutCoords to update header ***/
@@ -73,12 +73,12 @@
   }
   gfits_modify (&header, "CERROR", "%lf", 1, dR);
-  gfits_modify (&header, "CERROR", "%C", 1, "scatter in astrometry soln (arcsec)");
+  gfits_modify_alt (&header, "CERROR", "%C", 1, "scatter in astrometry soln (arcsec)");
   gfits_modify (&header, "CPRECISE", "%lf", 1, dR / sqrt(1.0*Nmatch));
-  gfits_modify (&header, "CPRECISE", "%C", 1, "precision of astrometry soln (arcsec)");
+  gfits_modify_alt (&header, "CPRECISE", "%C", 1, "precision of astrometry soln (arcsec)");
   gfits_modify (&header, "EQUINOX", "%lf", 1, 2000.0);
   /* we force equinox to be 2000.0 for all images */
 
 skipstuff:
-  if (header.size > oldsize) {
+  if (header.datasize > oldsize) {
     if (VERBOSE) fprintf (stderr, "header expanded, creating new copy\n");
     sprintf (line, "mv %s %s~", file, file);
@@ -99,7 +99,7 @@
       exit(0);
     }
-    nbytes = fwrite (header.buffer, 1, header.size, g);
-    fseek (f, oldsize, SEEK_SET);
-    for (i = 0; (nbytes = fread (header.buffer, 1, header.size, f)) > 0; i++) {
+    nbytes = fwrite (header.buffer, 1, header.datasize, g);
+    fseeko (f, oldsize, SEEK_SET);
+    for (i = 0; (nbytes = fread (header.buffer, 1, header.datasize, f)) > 0; i++) {
       if (nbytes != fwrite (header.buffer, 1, nbytes, g)) {
 	fprintf (stderr, "ERROR: failure writing output data file\n");
@@ -116,6 +116,6 @@
     }
     
-    fseek (f, 0, SEEK_SET);
-    nbytes = fwrite (header.buffer, 1, header.size, f);
+    fseeko (f, 0, SEEK_SET);
+    nbytes = fwrite (header.buffer, 1, header.datasize, f);
     
     fclose (f);
Index: trunk/Ohana/src/gastro/src/gstars.c
===================================================================
--- trunk/Ohana/src/gastro/src/gstars.c	(revision 27392)
+++ trunk/Ohana/src/gastro/src/gstars.c	(revision 27435)
@@ -162,5 +162,5 @@
     exit(0);
   }
-  fseek (f, header.size, SEEK_SET); 
+  fseeko (f, header.datasize, SEEK_SET); 
 
   N = nstar = 0;
Index: trunk/Ohana/src/gastro2/src/getusno.c
===================================================================
--- trunk/Ohana/src/gastro2/src/getusno.c	(revision 27392)
+++ trunk/Ohana/src/gastro2/src/getusno.c	(revision 27435)
@@ -11,5 +11,5 @@
 int getusno (CatStats *catstats, RefCatalog *Ref) {
 
-  long int offset;
+  off_t offset;
   int i, bin, first, last, nitems, Nitems, Nbins;
   float hours[100];
@@ -86,5 +86,5 @@
     /* advance file pointer to first slice */
     offset = 3*sizeof(int)*(start[first] - 1);
-    fseek (f, offset, SEEK_SET);
+    fseeko (f, offset, SEEK_SET);
     /* on each loop, load data from an RA slice of the catalog */
     for (bin = first; bin < last; bin++) {
Index: trunk/Ohana/src/gastro2/src/getusnob.c
===================================================================
--- trunk/Ohana/src/gastro2/src/getusnob.c	(revision 27392)
+++ trunk/Ohana/src/gastro2/src/getusnob.c	(revision 27435)
@@ -5,5 +5,5 @@
 int getusnob (CatStats *catstats, RefCatalog *Ref, double epoch) {
 
-  long int offset;
+  off_t offset;
   int i, bin, first, last, nitems, Nitems, Nbins;
   float hours[100];
@@ -76,5 +76,5 @@
     /* advance file pointer to first slice */
     offset = NELEM*NBYTE*(start[first] - 1);
-    fseek (f, offset, SEEK_SET);
+    fseeko (f, offset, SEEK_SET);
 
     /* sum the number of stars in data segment of interest */
Index: trunk/Ohana/src/gastro2/src/gheader2.c
===================================================================
--- trunk/Ohana/src/gastro2/src/gheader2.c	(revision 27392)
+++ trunk/Ohana/src/gastro2/src/gheader2.c	(revision 27435)
@@ -6,5 +6,5 @@
   Header header;
   FILE *f, *g;
-  int i, oldsize, nbytes, status;
+  off_t i, oldsize, nbytes, status;
   char line[1024];
 
@@ -13,5 +13,5 @@
     exit(0);
   }
-  oldsize = header.size;
+  oldsize = header.datasize;
 
   /* check for insufficient number of stars */
@@ -21,5 +21,5 @@
       if (Target[0].answer.N < 6) {
 	gfits_modify (&header, "NASTRO", "%d", 1, 0);
-	gfits_modify (&header, "NASTRO", "%C", 1, "number of stars used for astrometry");
+	gfits_modify_alt (&header, "NASTRO", "%C", 1, "number of stars used for astrometry");
 	goto skipstuff;
       }
@@ -28,5 +28,5 @@
       if (Target[0].answer.N < 12) {
 	gfits_modify (&header, "NASTRO", "%d", 1, 0);
-	gfits_modify (&header, "NASTRO", "%C", 1, "number of stars used for astrometry");
+	gfits_modify_alt (&header, "NASTRO", "%C", 1, "number of stars used for astrometry");
 	goto skipstuff;
       }
@@ -35,5 +35,5 @@
       if (Target[0].answer.N < 20) {
 	gfits_modify (&header, "NASTRO", "%d", 1, 0);
-	gfits_modify (&header, "NASTRO", "%C", 1, "number of stars used for astrometry");
+	gfits_modify_alt (&header, "NASTRO", "%C", 1, "number of stars used for astrometry");
 	goto skipstuff;
       }
@@ -45,5 +45,5 @@
   
   gfits_modify (&header, "NASTRO", "%d", 1, Target[0].answer.N);
-  gfits_modify (&header, "NASTRO", "%C", 1, "number of stars used for astrometry");
+  gfits_modify_alt (&header, "NASTRO", "%C", 1, "number of stars used for astrometry");
 
   /*** use PutCoords to update header ***/
@@ -52,12 +52,12 @@
   dR = fabs (Target[0].answer.dR*Target[0].coords.cdelt1*3600.0);
   gfits_modify (&header, "CERROR", "%lf", 1, dR);
-  gfits_modify (&header, "CERROR", "%C", 1, "scatter in astrometry soln (arcsec)");
+  gfits_modify_alt (&header, "CERROR", "%C", 1, "scatter in astrometry soln (arcsec)");
   gfits_modify (&header, "CPRECISE", "%lf", 1, dR / sqrt(1.0*Target[0].answer.N));
-  gfits_modify (&header, "CPRECISE", "%C", 1, "precision of astrometry soln (arcsec)");
+  gfits_modify_alt (&header, "CPRECISE", "%C", 1, "precision of astrometry soln (arcsec)");
   gfits_modify (&header, "EQUINOX", "%lf", 1, 2000.0);
   /* we force equinox to be 2000.0 for all images */
 
 skipstuff:
-  if (header.size > oldsize) {
+  if (header.datasize > oldsize) {
     if (VERBOSE) fprintf (stderr, "header expanded, creating new copy\n");
     sprintf (line, "mv %s %s~", file, file);
@@ -78,7 +78,7 @@
       exit(0);
     }
-    nbytes = fwrite (header.buffer, 1, header.size, g);
-    fseek (f, oldsize, SEEK_SET);
-    for (i = 0; (nbytes = fread (header.buffer, 1, header.size, f)) > 0; i++) {
+    nbytes = fwrite (header.buffer, 1, header.datasize, g);
+    fseeko (f, oldsize, SEEK_SET);
+    for (i = 0; (nbytes = fread (header.buffer, 1, header.datasize, f)) > 0; i++) {
       if (nbytes != fwrite (header.buffer, 1, nbytes, g)) {
 	fprintf (stderr, "ERROR: failure writing output data file\n");
@@ -95,6 +95,6 @@
     }
     
-    fseek (f, 0, SEEK_SET);
-    nbytes = fwrite (header.buffer, 1, header.size, f);
+    fseeko (f, 0, SEEK_SET);
+    nbytes = fwrite (header.buffer, 1, header.datasize, f);
     
     fclose (f);
Index: trunk/Ohana/src/gastro2/src/gstars2.c
===================================================================
--- trunk/Ohana/src/gastro2/src/gstars2.c	(revision 27392)
+++ trunk/Ohana/src/gastro2/src/gstars2.c	(revision 27435)
@@ -6,5 +6,6 @@
   char line[80];
   double det;
-  int NX, NY, Nskip, FoundAstrom, extend, naxis;
+  off_t Nskip;
+  int NX, NY, FoundAstrom, extend, naxis;
   StarData *stars;
   FILE *f;
@@ -21,5 +22,5 @@
   }
   /* this line should not be needed */
-  fseek (f, Target[0].header.size, SEEK_SET); 
+  fseeko (f, Target[0].header.datasize, SEEK_SET); 
 
   NX = Target[0].header.Naxis[0];
@@ -125,8 +126,8 @@
   /* Is NAXIS == 0 a better test?? */
   extend = FALSE;
-  gfits_scan (&Target[0].header, "NAXIS",  "%t", 1, &naxis);
+  gfits_scan_alt (&Target[0].header, "NAXIS",  "%t", 1, &naxis);
   if ((naxis == 0) && !TEXTMODE) {
     Nskip = gfits_data_size (&Target[0].header);
-    fseek (f, Nskip, SEEK_CUR); 
+    fseeko (f, Nskip, SEEK_CUR); 
     stars = rfits (f, &Nstars);
   } else {
Index: trunk/Ohana/src/gastro2/src/rfits.c
===================================================================
--- trunk/Ohana/src/gastro2/src/rfits.c	(revision 27392)
+++ trunk/Ohana/src/gastro2/src/rfits.c	(revision 27435)
@@ -3,5 +3,6 @@
 StarData *rfits (FILE *f, int *nstars) {
 
-  int i, N, Nstars;
+  int N;
+  off_t i, Nstars;
   Header theader;
   FTable table;
Index: trunk/Ohana/src/getstar/include/dvoImageExtract.h
===================================================================
--- trunk/Ohana/src/getstar/include/dvoImageExtract.h	(revision 27392)
+++ trunk/Ohana/src/getstar/include/dvoImageExtract.h	(revision 27435)
@@ -21,5 +21,5 @@
 int  args_extract    	 PROTO((int argc, char **argv));
 int  ConfigInit_extract  PROTO((int *argc, char **argv));
-int  Shutdown         	 PROTO((char *format, ...));
+int  Shutdown         	 PROTO((char *format, ...)) OHANA_FORMAT(printf, 1, 2);
 void TrapSignal       	 PROTO((int sig));
 void SetProtect       	 PROTO((int mode));
@@ -30,4 +30,4 @@
 
 int  WriteImageFITS (FILE *f, Image *image);
-int  WriteImages (char *filename, Image *images, int Nimages, int *matches, int Nmatches);
-int *SelectImages (char *filename, Image *dbImages, int NdbImages, int *Nmatch);
+int  WriteImages (char *filename, Image *images, off_t Nimages, off_t *matches, off_t Nmatches);
+off_t *SelectImages (char *filename, Image *dbImages, off_t NdbImages, off_t *Nmatch);
Index: trunk/Ohana/src/getstar/include/dvoImageOverlaps.h
===================================================================
--- trunk/Ohana/src/getstar/include/dvoImageOverlaps.h	(revision 27392)
+++ trunk/Ohana/src/getstar/include/dvoImageOverlaps.h	(revision 27435)
@@ -24,13 +24,13 @@
 int  args_overlaps    	 PROTO((int argc, char **argv));
 int  ConfigInit_overlaps PROTO((int *argc, char **argv));
-int  Shutdown         PROTO((char *format, ...));
+int  Shutdown         PROTO((char *format, ...) OHANA_FORMAT(printf, 1, 2));
 void TrapSignal       PROTO((int sig));
 void SetProtect       PROTO((int mode));
 int  SetSignals       PROTO((void));
 
-Image *ReadImageFiles (char *filename, int *Nimages);
+Image *ReadImageFiles (char *filename, off_t *Nimages);
 int ReadImageHeader (Header *header, Image *image);
-int *MatchImage (Image *dbImages, int NdbImages, Image *image, int *Nmatch);
-int ListImageOverlaps (Image *dbImages, Image *image, int *matches, int Nmatches);
+off_t *MatchImage (Image *dbImages, off_t NdbImages, Image *image, off_t *Nmatch);
+int ListImageOverlaps (Image *dbImages, Image *image, off_t *matches, off_t Nmatches);
 
 int GetFileMode (Header *header);
Index: trunk/Ohana/src/getstar/include/dvoImagesAtCoords.h
===================================================================
--- trunk/Ohana/src/getstar/include/dvoImagesAtCoords.h	(revision 27392)
+++ trunk/Ohana/src/getstar/include/dvoImagesAtCoords.h	(revision 27435)
@@ -39,12 +39,12 @@
 int  args_coords    	 PROTO((int argc, char **argv));
 int  ConfigInit_coords PROTO((int *argc, char **argv));
-int  Shutdown         PROTO((char *format, ...));
+int  Shutdown         PROTO((char *format, ...) OHANA_FORMAT(printf, 1, 2));
 void TrapSignal       PROTO((int sig));
 void SetProtect       PROTO((int mode));
 int  SetSignals       PROTO((void));
 
-Image *ReadImageFiles (char *filename, int *Nimages);
+Image *ReadImageFiles (char *filename, off_t *Nimages);
 int ReadImageHeader (Header *header, Image *image);
-int MatchCoords(Image *, int, Point *, int);
+off_t MatchCoords (Image *dbImages, off_t NdbImages, Point *points, int Npoints);
 
 int GetFileMode (Header *header);
Index: trunk/Ohana/src/getstar/include/getstar.h
===================================================================
--- trunk/Ohana/src/getstar/include/getstar.h	(revision 27392)
+++ trunk/Ohana/src/getstar/include/getstar.h	(revision 27435)
@@ -37,5 +37,5 @@
 int  args             	     PROTO((int argc, char **argv));
 int  ConfigInit       	     PROTO((int *argc, char **argv));
-int  Shutdown         	     PROTO((char *format, ...));
+int  Shutdown         	     PROTO((char *format, ...)) OHANA_FORMAT(printf, 1, 2);
 int  load_pt_catalog  	     PROTO((Catalog *catalog, SkyRegion *region));
 int  select_by_region 	     PROTO((Catalog *output, Catalog *catalog, SkyRegion *region, int start, int end));
Index: trunk/Ohana/src/getstar/src/ConfigInit_coords.c
===================================================================
--- trunk/Ohana/src/getstar/src/ConfigInit_coords.c	(revision 27392)
+++ trunk/Ohana/src/getstar/src/ConfigInit_coords.c	(revision 27435)
@@ -4,6 +4,4 @@
 
   char *config, *file;
-  char CatdirPhotcodeFile[256];
-  char MasterPhotcodeFile[256];
 
   /*** load configuration info ***/
@@ -21,5 +19,4 @@
   ScanConfig (config, "CATMODE",                "%s",  0, CATMODE);
   ScanConfig (config, "CATFORMAT",              "%s",  0, CATFORMAT);
-  ScanConfig (config, "PHOTCODE_FILE",         	"%s",  0, MasterPhotcodeFile);
   if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) {
     SKY_DEPTH = 2;
Index: trunk/Ohana/src/getstar/src/ConfigInit_extract.c
===================================================================
--- trunk/Ohana/src/getstar/src/ConfigInit_extract.c	(revision 27392)
+++ trunk/Ohana/src/getstar/src/ConfigInit_extract.c	(revision 27435)
@@ -4,6 +4,4 @@
 
   char *config, *file;
-  char CatdirPhotcodeFile[256];
-  char MasterPhotcodeFile[256];
 
   /*** load configuration info ***/
@@ -21,5 +19,4 @@
   ScanConfig (config, "CATMODE",                "%s",  0, CATMODE);
   ScanConfig (config, "CATFORMAT",              "%s",  0, CATFORMAT);
-  ScanConfig (config, "PHOTCODE_FILE",         	"%s",  0, MasterPhotcodeFile);
   if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) {
     SKY_DEPTH = 2;
@@ -33,11 +30,4 @@
   if (*CATFORMAT == 0) strcpy (CATFORMAT, "ELIXIR");
 
-  /* XXX this does not yet write out the master photcode table */
-  sprintf (CatdirPhotcodeFile, "%s/Photcodes.dat", CATDIR);
-  if (!LoadPhotcodes (CatdirPhotcodeFile, MasterPhotcodeFile, TRUE)) {
-    fprintf (stderr, "error loading photcode table %s or master file %s\n", CatdirPhotcodeFile, MasterPhotcodeFile);
-    exit (1);
-  }
-
   free (config);
   free (file);
Index: trunk/Ohana/src/getstar/src/ConfigInit_overlaps.c
===================================================================
--- trunk/Ohana/src/getstar/src/ConfigInit_overlaps.c	(revision 27392)
+++ trunk/Ohana/src/getstar/src/ConfigInit_overlaps.c	(revision 27435)
@@ -4,6 +4,4 @@
 
   char *config, *file;
-  char CatdirPhotcodeFile[256];
-  char MasterPhotcodeFile[256];
 
   /*** load configuration info ***/
@@ -21,5 +19,4 @@
   ScanConfig (config, "CATMODE",                "%s",  0, CATMODE);
   ScanConfig (config, "CATFORMAT",              "%s",  0, CATFORMAT);
-  ScanConfig (config, "PHOTCODE_FILE",         	"%s",  0, MasterPhotcodeFile);
   if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) {
     SKY_DEPTH = 2;
@@ -33,11 +30,4 @@
   if (*CATFORMAT == 0) strcpy (CATFORMAT, "ELIXIR");
 
-  /* XXX this does not yet write out the master photcode table */
-  sprintf (CatdirPhotcodeFile, "%s/Photcodes.dat", CATDIR);
-  if (!LoadPhotcodes (CatdirPhotcodeFile, MasterPhotcodeFile, FALSE)) {
-    fprintf (stderr, "error loading photcode table %s or master file %s\n", CatdirPhotcodeFile, MasterPhotcodeFile);
-    exit (1);
-  }
-
   free (config);
   free (file);
Index: trunk/Ohana/src/getstar/src/GetFileMode.c
===================================================================
--- trunk/Ohana/src/getstar/src/GetFileMode.c	(revision 27392)
+++ trunk/Ohana/src/getstar/src/GetFileMode.c	(revision 27435)
@@ -8,9 +8,9 @@
   int simple, extend, haveNaxis, haveCTYPE;
 
-  gfits_scan (header, "SIMPLE", "%t", 1, &simple);
+  gfits_scan_alt (header, "SIMPLE", "%t", 1, &simple);
   haveNaxis = gfits_scan (header, "NAXIS",  "%d", 1, &Naxis);
   haveCTYPE = gfits_scan (header, "CTYPE1", "%s", 1, ctype);
 
-  gfits_scan (header, "EXTEND", "%t", 1, &extend);
+  gfits_scan_alt (header, "EXTEND", "%t", 1, &extend);
     
   if ((Naxis == 2) || !simple) {
Index: trunk/Ohana/src/getstar/src/ListImageOverlaps.c
===================================================================
--- trunk/Ohana/src/getstar/src/ListImageOverlaps.c	(revision 27392)
+++ trunk/Ohana/src/getstar/src/ListImageOverlaps.c	(revision 27435)
@@ -2,7 +2,7 @@
 
 /* given image, find catalog images which overlap it */
-int ListImageOverlaps (Image *dbImages, Image *image, int *matches, int Nmatches) {
+int ListImageOverlaps (Image *dbImages, Image *image, off_t *matches, off_t Nmatches) {
   
-  int i, N;
+  off_t i, N;
 
   for (i = 0; i < Nmatches; i++) {
Index: trunk/Ohana/src/getstar/src/MatchCoords.c
===================================================================
--- trunk/Ohana/src/getstar/src/MatchCoords.c	(revision 27392)
+++ trunk/Ohana/src/getstar/src/MatchCoords.c	(revision 27435)
@@ -5,12 +5,10 @@
 
 /* given coordinate, find images in list that contain the point */
-int MatchCoords (Image *dbImages, int NdbImages, Point *points, int Npoints) {
+off_t MatchCoords (Image *dbImages, off_t NdbImages, Point *points, int Npoints) {
   
-  int i, j, N;
+  off_t i;
+  int j;
   int totalMatches = 0;
-  Coords tcoords;
-  double r, d;
-  double Xi[4], Yi[4], Xo[4], Yo[4];  /* image and original corners */
-  double Xmin, Xmax, Ymin, Ymax;
+  double Xi[4], Yi[4];  /* image and original corners */
   double xmin, xmax, ymin, ymax;
 
Index: trunk/Ohana/src/getstar/src/MatchImages.c
===================================================================
--- trunk/Ohana/src/getstar/src/MatchImages.c	(revision 27392)
+++ trunk/Ohana/src/getstar/src/MatchImages.c	(revision 27435)
@@ -5,8 +5,8 @@
 
 /* given image, find catalog images which overlap it */
-int *MatchImage (Image *dbImages, int NdbImages, Image *image, int *Nmatch) {
+off_t *MatchImage (Image *dbImages, off_t NdbImages, Image *image, off_t *Nmatch) {
   
-  int i, j, N, addtolist, status;
-  int NMATCH, nmatch, *match;
+  off_t i, NMATCH, nmatch, *match;
+  int j, N, addtolist, status;
   Coords tcoords;
   double r, d;
@@ -64,5 +64,5 @@
   nmatch = 0;
   NMATCH = 20;
-  ALLOCATE (match, int, NMATCH);
+  ALLOCATE (match, off_t, NMATCH);
 
   /* setup links for mosaic WRP and DIS entries */
@@ -128,9 +128,9 @@
     if (nmatch == NMATCH) {
       NMATCH += 20;
-      REALLOCATE (match, int, NMATCH);
+      REALLOCATE (match, off_t, NMATCH);
     }
   }
   
-  if (VERBOSE) fprintf (stderr, "found %d overlapping images\n", nmatch);
+  if (VERBOSE) fprintf (stderr, "found %lld overlapping images\n", (long long) nmatch);
 
   *Nmatch = nmatch;
Index: trunk/Ohana/src/getstar/src/ReadImageFiles.c
===================================================================
--- trunk/Ohana/src/getstar/src/ReadImageFiles.c	(revision 27392)
+++ trunk/Ohana/src/getstar/src/ReadImageFiles.c	(revision 27435)
@@ -2,13 +2,14 @@
 # define DVO_IMAGE_NAME_LEN 128
 
-Image *ReadImageFiles (char *filename, int *Nimages) {
-
-  int i, j, N, Nfile, Nheader, NHEADER, Nimage, NIMAGE;
-  int Nskip, Nhead, Ndata, done, status, mode;
+Image *ReadImageFiles (char *filename, off_t *Nimages) {
+
+  off_t Nskip, *extsize;
+  int i, j, N, Nfile, Nheader, Nimage, NHEADER, NIMAGE;
+  int Nhead, Ndata, done, status, mode;
   char **file, *name;
   FILE *f;
   glob_t globList;
   char **exthead, **extdata, **exttype, tmpword[80];
-  int *extnum_head, *extnum_data, *extsize;
+  int *extnum_head, *extnum_data;
   Header *header, **headers;
   Image *image;
@@ -89,5 +90,5 @@
   headers[0] = header;
   Nskip = gfits_data_size (header);
-  fseek (f, Nskip, SEEK_CUR); 
+  fseeko (f, Nskip, SEEK_CUR); 
 
   // load all headers into memory
@@ -118,5 +119,5 @@
   ALLOCATE (extnum_head, int, NIMAGE);
   ALLOCATE (extnum_data, int, NIMAGE);
-  ALLOCATE (extsize, int, Nheader);
+  ALLOCATE (extsize, off_t, Nheader);
 
   if (mode == MOSAIC_MEF) {
@@ -130,5 +131,5 @@
   // now examine the headers, count the table entries, find corresponding headers
   for (i = 0; i < Nheader; i++) {
-      extsize[i] = headers[i][0].size + gfits_data_size (headers[i]);
+      extsize[i] = headers[i][0].datasize + gfits_data_size (headers[i]);
       gfits_scan (headers[i], "EXTTYPE", "%s", 1, tmpword);
 
@@ -166,6 +167,6 @@
   // extension matched to the header in the PHU
   if (Nimage == 0) {
-      extsize[0] = headers[0][0].size + gfits_data_size (headers[0]);
-      extsize[1] = headers[1][0].size + gfits_data_size (headers[1]);
+      extsize[0] = headers[0][0].datasize + gfits_data_size (headers[0]);
+      extsize[1] = headers[1][0].datasize + gfits_data_size (headers[1]);
       gfits_scan (headers[1], "EXTNAME", "%s", 1, tmpword);
       if (!strcmp (tmpword, "SMPFILE")) {
Index: trunk/Ohana/src/getstar/src/SelectImages.c
===================================================================
--- trunk/Ohana/src/getstar/src/SelectImages.c	(revision 27392)
+++ trunk/Ohana/src/getstar/src/SelectImages.c	(revision 27435)
@@ -2,8 +2,8 @@
 
 /* given image, find catalog images which overlap it */
-int *SelectImages (char *filename, Image *images, int Nimages, int *Nmatch) {
+off_t *SelectImages (char *filename, Image *images, off_t Nimages, off_t *Nmatch) {
   
-  int i, Nchar;
-  int NMATCH, nmatch, *match;
+  int Nchar;
+  off_t i, NMATCH, nmatch, *match;
 
   /* matches here are only based on string comparisons */
@@ -12,5 +12,5 @@
   nmatch = 0;
   NMATCH = 20;
-  ALLOCATE (match, int, NMATCH);
+  ALLOCATE (match, off_t, NMATCH);
 
   /* setup links for mosaic WRP and DIS entries */
@@ -27,9 +27,9 @@
     if (nmatch == NMATCH) {
       NMATCH += 20;
-      REALLOCATE (match, int, NMATCH);
+      REALLOCATE (match, off_t, NMATCH);
     }
   }  
 
-  if (VERBOSE) fprintf (stderr, "found %d matching images\n", nmatch);
+  if (VERBOSE) fprintf (stderr, "found %lld matching images\n", (long long) nmatch);
 
   *Nmatch = nmatch;
Index: trunk/Ohana/src/getstar/src/WriteImages.c
===================================================================
--- trunk/Ohana/src/getstar/src/WriteImages.c	(revision 27392)
+++ trunk/Ohana/src/getstar/src/WriteImages.c	(revision 27435)
@@ -2,5 +2,5 @@
 
 /* given image, find catalog images which overlap it */
-int WriteImages (char *filename, Image *images, int Nimages, int *matches, int Nmatches) {
+int WriteImages (char *filename, Image *images, off_t Nimages, off_t *matches, off_t Nmatches) {
   
   int i, N;
Index: trunk/Ohana/src/getstar/src/dvoImageExtract.c
===================================================================
--- trunk/Ohana/src/getstar/src/dvoImageExtract.c	(revision 27392)
+++ trunk/Ohana/src/getstar/src/dvoImageExtract.c	(revision 27435)
@@ -3,6 +3,6 @@
 int main (int argc, char **argv) {
 
-  int Nimages, status;
-  int Nmatches, *matches;
+  off_t Nimages, Nmatches, *matches;
+  int status;
   Image *images;
   FITS_DB db;
Index: trunk/Ohana/src/getstar/src/dvoImageOverlaps.c
===================================================================
--- trunk/Ohana/src/getstar/src/dvoImageOverlaps.c	(revision 27392)
+++ trunk/Ohana/src/getstar/src/dvoImageOverlaps.c	(revision 27435)
@@ -3,6 +3,7 @@
 int main (int argc, char **argv) {
 
-  int i, Nimages, NdbImages, status;
-  int Nmatches, *matches;
+  off_t NdbImages, Nimages;
+  int status;
+  off_t i, Nmatches, *matches;
   Image *images, *dbImages;
   FITS_DB db;
Index: trunk/Ohana/src/getstar/src/dvoImagesAtCoords.c
===================================================================
--- trunk/Ohana/src/getstar/src/dvoImagesAtCoords.c	(revision 27392)
+++ trunk/Ohana/src/getstar/src/dvoImagesAtCoords.c	(revision 27435)
@@ -12,6 +12,6 @@
 int main (int argc, char **argv) {
 
-  int i, Nimages, NdbImages, status;
-  int Nmatches, *matches;
+  off_t NdbImages;
+  int status;
   Image *dbImages;
   int Npoints;
Index: trunk/Ohana/src/getstar/src/select_by_region.c
===================================================================
--- trunk/Ohana/src/getstar/src/select_by_region.c	(revision 27392)
+++ trunk/Ohana/src/getstar/src/select_by_region.c	(revision 27435)
@@ -156,6 +156,6 @@
   output[0].Nsecf_mem = Nave*Nsecfilt;
 
-  fprintf (stderr, "output catalog has %d stars (%d measures, %d secfilt)\n",
-	   output[0].Naverage, output[0].Nmeasure, output[0].Nsecfilt);
+  fprintf (stderr, "output catalog has %lld stars (%lld measures, %d secfilt)\n",
+	   (long long) output[0].Naverage, (long long) output[0].Nmeasure, output[0].Nsecfilt);
   return (TRUE);
 }
Index: trunk/Ohana/src/gophot/src/gophot.c
===================================================================
--- trunk/Ohana/src/gophot/src/gophot.c	(revision 27392)
+++ trunk/Ohana/src/gophot/src/gophot.c	(revision 27435)
@@ -26,5 +26,5 @@
   /* convert to float, set up noise array and axes */
   gfits_convert_format (&header, &matrix, -32, 1.0, 0.0, 0xffff, 0);
-  ALLOCATE (noise, float, matrix.size);
+  ALLOCATE (noise, float, matrix.datasize);
   big = (float *) matrix.buffer;
   nfast = matrix.Naxis[0];
Index: trunk/Ohana/src/imclean/src/wfits.c
===================================================================
--- trunk/Ohana/src/imclean/src/wfits.c	(revision 27392)
+++ trunk/Ohana/src/imclean/src/wfits.c	(revision 27435)
@@ -10,5 +10,5 @@
   header[0].Naxes = 0;
   gfits_modify (header, "NAXIS",   "%d", 1, 0);
-  gfits_modify (header, "EXTEND",  "%t", 1, TRUE);
+  gfits_modify_alt (header, "EXTEND",  "%t", 1, TRUE);
   gfits_modify (header, "NEXTEND", "%d", 1, 1);
 
Index: trunk/Ohana/src/imclean/src/wstars.c
===================================================================
--- trunk/Ohana/src/imclean/src/wstars.c	(revision 27392)
+++ trunk/Ohana/src/imclean/src/wstars.c	(revision 27435)
@@ -14,5 +14,5 @@
   }
 
-  fwrite (header[0].buffer, 1, header[0].size, g);
+  fwrite (header[0].buffer, 1, header[0].datasize, g);
 
   for (i = 0; i < Nstars; i++) {
Index: trunk/Ohana/src/imregister/base/WriteFIFO.c
===================================================================
--- trunk/Ohana/src/imregister/base/WriteFIFO.c	(revision 27392)
+++ trunk/Ohana/src/imregister/base/WriteFIFO.c	(revision 27435)
@@ -12,5 +12,5 @@
   }
 
-  fseek (f, 0, SEEK_END);
+  fseeko (f, 0LL, SEEK_END);
   fprintf (f, "%s\n", line);
 
Index: trunk/Ohana/src/imregister/detrend/altpath.c
===================================================================
--- trunk/Ohana/src/imregister/detrend/altpath.c	(revision 27392)
+++ trunk/Ohana/src/imregister/detrend/altpath.c	(revision 27435)
@@ -2,13 +2,14 @@
 # include "detrend.h"
 
-int SetAltpath (FITS_DB *db, DetReg *image, int Nimage, Match *match, int Nmatch) {
+int SetAltpath (FITS_DB *db, DetReg *image, off_t Nimage, Match *match, off_t Nmatch) {
   
-  int i, j, n, found, status, Nlist;
-  int *list, *current;
+  int status, found;
+  off_t i, j, n, Nlist;
+  off_t *list, *current;
   char *dBPath, infile[256], outfile[256], line[1024];
   struct stat statbuf;
 
-  ALLOCATE (current, int, Nimage);
-  ALLOCATE (list, int, Nimage);
+  ALLOCATE (current, off_t, Nimage);
+  ALLOCATE (list, off_t, Nimage);
   Nlist = 0;
 
Index: trunk/Ohana/src/imregister/detrend/criteria.c
===================================================================
--- trunk/Ohana/src/imregister/detrend/criteria.c	(revision 27392)
+++ trunk/Ohana/src/imregister/detrend/criteria.c	(revision 27435)
@@ -60,7 +60,7 @@
 */
 
-Match *ExptimeCriteria (DetReg *image, int Nimage, Match *match, int *nmatch) {
-
-  int i, j, Nmatch, Nnew, NNEW, entry;
+Match *ExptimeCriteria (DetReg *image, off_t Nimage, Match *match, off_t *nmatch) {
+
+  off_t i, j, Nmatch, Nnew, NNEW, entry;
   unsigned long dtime;
   float Chi, ChiMin;
@@ -132,7 +132,7 @@
 }
 
-Match *CloseCriteria (DetReg *image, int Nimage, Match *match, int *nmatch) {
-
-  int i, j, Nmatch, Nnew, NNEW, Ngood, entry;
+Match *CloseCriteria (DetReg *image, off_t Nimage, Match *match, off_t *nmatch) {
+
+  off_t i, j, Nmatch, Nnew, NNEW, Ngood, entry;
   unsigned long dmin, dtime;
   Match *new;
Index: trunk/Ohana/src/imregister/detrend/delete.c
===================================================================
--- trunk/Ohana/src/imregister/detrend/delete.c	(revision 27392)
+++ trunk/Ohana/src/imregister/detrend/delete.c	(revision 27435)
@@ -2,13 +2,13 @@
 # include "detrend.h"
 
-void DeleteSubset (FITS_DB *db, DetReg *image, int Nimage, Match *match, int Nmatch) {
+void DeleteSubset (FITS_DB *db, DetReg *image, off_t Nimage, Match *match, off_t Nmatch) {
 
-  int i, j;
-  int *keep, Ndel, Nsubset;
+  off_t i, j;
+  off_t *keep, Ndel, Nsubset;
   DetReg *subset;
 
-  ALLOCATE (keep, int, MAX (Nimage, 1));
+  ALLOCATE (keep, off_t, MAX (Nimage, 1));
   for (i = 0; i < Nimage; i++) keep[i] = TRUE;
-  fprintf (stderr, "total of %d detrend images\n", Nimage);
+  fprintf (stderr, "total of %lld detrend images\n", (long long) Nimage);
 
   Ndel = 0;
@@ -20,5 +20,5 @@
     delete_image (&image[i]);
   }
-  fprintf (stderr, "delete %d images\n", Ndel);
+  fprintf (stderr, "delete %lld images\n", (long long) Ndel);
   if (Ndel == 0) { 
     fprintf (stderr, "SUCCESS\n");
@@ -30,5 +30,5 @@
   Nsubset = Nimage - Ndel;
   ALLOCATE (subset, DetReg, MAX (1, Nsubset));
-  fprintf (stderr, "keeping %d images\n", Nsubset);
+  fprintf (stderr, "keeping %lld images\n", (long long) Nsubset);
   for (j = i = 0; i < Nimage; i++) {
     if (!keep[i]) continue;
Index: trunk/Ohana/src/imregister/detrend/imdef.c
===================================================================
--- trunk/Ohana/src/imregister/detrend/imdef.c	(revision 27392)
+++ trunk/Ohana/src/imregister/detrend/imdef.c	(revision 27435)
@@ -43,5 +43,5 @@
   descriptor[0].mode = M_SPLIT;
   Extend = FALSE;
-  gfits_scan (&header, "EXTEND", "%t", 1, &Extend);
+  gfits_scan_alt (&header, "EXTEND", "%t", 1, &Extend);
   if (Extend) {
     descriptor[0].mode      = M_MEF;
Index: trunk/Ohana/src/imregister/detrend/match.c
===================================================================
--- trunk/Ohana/src/imregister/detrend/match.c	(revision 27392)
+++ trunk/Ohana/src/imregister/detrend/match.c	(revision 27435)
@@ -2,8 +2,8 @@
 # include "detrend.h"
 
-Match *MatchCriteria (DetReg *image, int Nimage, int *nmatch) {
+Match *MatchCriteria (DetReg *image, off_t Nimage, off_t *nmatch) {
 
-  int i;
-  int Nmatch, NMATCH;
+  off_t i;
+  off_t Nmatch, NMATCH;
   Match result, *match;
 
Index: trunk/Ohana/src/imregister/detrend/modify.c
===================================================================
--- trunk/Ohana/src/imregister/detrend/modify.c	(revision 27392)
+++ trunk/Ohana/src/imregister/detrend/modify.c	(revision 27435)
@@ -2,12 +2,12 @@
 # include "detrend.h"
 
-int ModifySubset (FITS_DB *db, DetReg *image, int Nimage, Match *match, int Nmatch) {
+int ModifySubset (FITS_DB *db, DetReg *image, off_t Nimage, Match *match, off_t Nmatch) {
   
-  int i, j, value;
-  int *list;
+  off_t i, j, value;
+  off_t *list;
   
   value = M_UNDEF;
 
-  ALLOCATE (list, int, Nimage);
+  ALLOCATE (list, off_t, Nimage);
   if (!strcasecmp (output.ModifyEntry, "mode")) {
     value = get_image_mode (output.ModifyValue);
Index: trunk/Ohana/src/imregister/detrend/output.c
===================================================================
--- trunk/Ohana/src/imregister/detrend/output.c	(revision 27392)
+++ trunk/Ohana/src/imregister/detrend/output.c	(revision 27435)
@@ -5,5 +5,5 @@
 extern double drand48();
 
-int OutputSubset (DetReg *image, int Nimage, Match *match, int Nmatch) {
+int OutputSubset (DetReg *image, off_t Nimage, Match *match, off_t Nmatch) {
 
   if (output.table != (char *) NULL) {
@@ -19,7 +19,7 @@
 
 /* write out complete binary FITS table in format of db */
-int DumpFitsBintable (char *filename, DetReg *image, Match *match, int Nmatch) {
-
-  int i, j;
+int DumpFitsBintable (char *filename, DetReg *image, Match *match, off_t Nmatch) {
+
+  off_t i, j;
   FILE *f;
   Header header;
@@ -60,5 +60,5 @@
 }
 
-int DumpFitsTable (char *filename, DetReg *detdata, Match *match, int Nmatch) {
+int DumpFitsTable (char *filename, DetReg *detdata, Match *match, off_t Nmatch) {
   
   Header header, theader;
@@ -69,5 +69,5 @@
   char *startstr, *stopstr, *regstr, *line, key[33], ccdinfo[16];
   char *filtstr, *typestr, *modestr, *ccdstr, *datestr, *p;
-  int i;
+  off_t i;
   time_t tsecond;
 
@@ -191,9 +191,10 @@
 
 /* Select, TimeMode are global */
-int PrintSubset (DetReg *detdata, Match *match, int Nmatch) {
+int PrintSubset (DetReg *detdata, Match *match, off_t Nmatch) {
   
   char *dBPath, *Path, *typestr, *filtstr, filename[128];
   char *timestr, *modestr, *ccdstr, ccdinfo[16], ccdformat[16];
-  int i, j, Nc;
+  off_t i, j;
+  int Nc;
   struct timeval now;
   long A;
Index: trunk/Ohana/src/imregister/detrend/select.c
===================================================================
--- trunk/Ohana/src/imregister/detrend/select.c	(revision 27392)
+++ trunk/Ohana/src/imregister/detrend/select.c	(revision 27435)
@@ -2,5 +2,5 @@
 # include "detrend.h"
 
-Match SelectEntry (DetReg *image, int Nimage, Match *list, int Nlist, Criteria *crit) {
+Match SelectEntry (DetReg *image, off_t Nimage, Match *list, off_t Nlist, Criteria *crit) {
 
   /* force a single selection */
@@ -15,6 +15,6 @@
   */
 
-  int i, j, entry, order, matchnum;
-  int nmatch, Nmatch;
+  off_t i, j, entry, order, matchnum;
+  off_t nmatch, Nmatch;
   unsigned int tstart;
   Match *match, *tmatch, answer;
Index: trunk/Ohana/src/imregister/detrend/unique.c
===================================================================
--- trunk/Ohana/src/imregister/detrend/unique.c	(revision 27392)
+++ trunk/Ohana/src/imregister/detrend/unique.c	(revision 27435)
@@ -3,8 +3,9 @@
 
 /* define a list of best images which have unique properties */ 
-Match *UniqueSubset (DetReg *image, int Nimage, Match *match, int *nmatch) {
+Match *UniqueSubset (DetReg *image, off_t Nimage, Match *match, off_t *nmatch) {
 
-  int Nsubset, Nunique, Ncrit, NCRIT;
-  int i, j, N, Nmatch, found;
+  int found;
+  off_t Nsubset, Nunique, Ncrit, NCRIT;
+  off_t i, j, N, Nmatch;
   Criteria *crit;
   Match *subset, *unique, *local;
Index: trunk/Ohana/src/imregister/imphot/dumpfits.c
===================================================================
--- trunk/Ohana/src/imregister/imphot/dumpfits.c	(revision 27392)
+++ trunk/Ohana/src/imregister/imphot/dumpfits.c	(revision 27435)
@@ -3,7 +3,7 @@
 
 /* write out complete binary FITS table in format of db */
-int DumpFitsBintable (char *filename, Image *image, int *match, int Nmatch) {
+int DumpFitsBintable (char *filename, Image *image, off_t *match, off_t Nmatch) {
 
-  int i, j;
+  off_t i, j;
   FILE *f;
   Header header;
@@ -44,5 +44,5 @@
 }
 
-int DumpFitsTable (char *filename, Image *image, int *match, int Nmatch) {
+int DumpFitsTable (char *filename, Image *image, off_t *match, off_t Nmatch) {
   
   Header header;
@@ -53,5 +53,5 @@
   FILE *f;
   char *startstr, *filtstr, *datestr, *line;
-  int i;
+  off_t i;
   double zp, dzp, ra, dec, airmass, sky;
   time_t tsecond;
Index: trunk/Ohana/src/imregister/imphot/modify.c
===================================================================
--- trunk/Ohana/src/imregister/imphot/modify.c	(revision 27392)
+++ trunk/Ohana/src/imregister/imphot/modify.c	(revision 27435)
@@ -2,7 +2,7 @@
 # include "imphot.h"
 
-void ModifySubset (FITS_DB *db, Image *image, int Nimage, int *match, int Nmatch) {
+void ModifySubset (FITS_DB *db, Image *image, off_t Nimage, off_t *match, off_t Nmatch) {
 
-  int i, j;
+  off_t i, j;
 
   /* modify the selected entries */
Index: trunk/Ohana/src/imregister/imphot/output.c
===================================================================
--- trunk/Ohana/src/imregister/imphot/output.c	(revision 27392)
+++ trunk/Ohana/src/imregister/imphot/output.c	(revision 27435)
@@ -2,5 +2,5 @@
 # include "imphot.h"
 
-int output (Image *image, int *match, int Nmatch) {
+int output (Image *image, off_t *match, off_t Nmatch) {
 
   int status;
@@ -22,7 +22,7 @@
 }
 
-int PrintSubset (Image *image, int *match, int Nmatch) {
+int PrintSubset (Image *image, off_t *match, off_t Nmatch) {
 
-  int i, j;
+  off_t i, j;
   char *timestr, *photstr;
   static char PhotError[] = "unknown";
Index: trunk/Ohana/src/imregister/imphot/rtext.c
===================================================================
--- trunk/Ohana/src/imregister/imphot/rtext.c	(revision 27392)
+++ trunk/Ohana/src/imregister/imphot/rtext.c	(revision 27435)
@@ -4,5 +4,5 @@
 int rtext (FITS_DB *db) {
 
-  int Nimage, size, nimage;
+  off_t Nimage, size, nimage;
   struct stat filestatus;
   Image *image;
@@ -10,16 +10,16 @@
   /* check that file size makes sense */
   Nimage = 0;
-  gfits_scan (&db[0].header, "NIMAGES", "%d", 1, &Nimage);
+  gfits_scan (&db[0].header, "NIMAGES", "%lld", 1, (long long *) &Nimage);
   if (stat (db[0].filename, &filestatus) == -1) {
     if (VERBOSE) fprintf (stderr, "ERROR: failed to get status of image catalog\n");
     exit (1);
   }
-  size = Nimage*sizeof(Image) + db[0].header.size;
+  size = Nimage*sizeof(Image) + db[0].header.datasize;
   if (size != filestatus.st_size) {
     int Ndata;
 
-    Ndata = (filestatus.st_size - db[0].header.size) / sizeof (Image);
+    Ndata = (filestatus.st_size - db[0].header.datasize) / sizeof (Image);
     if (VERBOSE) fprintf (stderr, "ERROR: image catalog has inconsistent size\n");
-    if (VERBOSE) fprintf (stderr, "header: %d, data: %d\n", Nimage, Ndata);
+    if (VERBOSE) fprintf (stderr, "header: %lld, data: %d\n", (long long) Nimage, Ndata);
     if (!FORCE_READ) exit (1);
     Nimage = Ndata;
@@ -41,7 +41,7 @@
   } 
   db[0].ftable.buffer = (char *) image;
-  gfits_modify (&db[0].theader, "NAXIS2", "%d", 1, Nimage);
+  gfits_modify (&db[0].theader, "NAXIS2", "%lld", 1, (long long) Nimage);
   db[0].theader.Naxis[1] = Nimage;
-  db[0].ftable.size = gfits_data_size (&db[0].theader);
+  db[0].ftable.datasize = gfits_data_size (&db[0].theader);
   
   return (TRUE);
Index: trunk/Ohana/src/imregister/imphot/subset.c
===================================================================
--- trunk/Ohana/src/imregister/imphot/subset.c	(revision 27392)
+++ trunk/Ohana/src/imregister/imphot/subset.c	(revision 27435)
@@ -2,9 +2,9 @@
 # include "imphot.h"
 
-int *subset (Image *image, int Nimage, int *nsubset) {
+off_t *subset (Image *image, off_t Nimage, off_t *nsubset) {
 
-  int i, j, status;
-  int Nsubset, NameSelectLength;
-  int *index;
+  off_t i, j, status;
+  off_t Nsubset, NameSelectLength;
+  off_t *index;
 
   NameSelectLength = 0;
@@ -12,5 +12,5 @@
   /* allocate space for reference lists */
   Nsubset = 0;
-  ALLOCATE (index, int, Nimage);
+  ALLOCATE (index, off_t, Nimage);
   
   if (criteria.NameSelect) {
Index: trunk/Ohana/src/imregister/imreg/cadc.c
===================================================================
--- trunk/Ohana/src/imregister/imreg/cadc.c	(revision 27392)
+++ trunk/Ohana/src/imregister/imreg/cadc.c	(revision 27435)
@@ -4,7 +4,7 @@
 static int REFCCD;
 
-void DumpCADCTable (char *filename, RegImage *image, int *match, int Nmatch) {
-  
-  int i, Obsid, Nobsid, Nsubset, ref;
+void DumpCADCTable (char *filename, RegImage *image, off_t *match, off_t Nmatch) {
+  
+  off_t i, Obsid, Nobsid, Nsubset, ref;
   char *datestr, *line, hdrname[99];
   time_t tsecond;
@@ -13,7 +13,7 @@
   FTable table;
   RegImage *row;
-  int *index, *entry, *obsid;
+  off_t *index, *entry, *obsid;
   MosaicLayout *layout;
-  int *subset;
+  off_t *subset;
   double left, right, center, outer, top, bottom;
   double iqx, iqy, iqr, iqf, iqo;
@@ -127,13 +127,13 @@
 }
 
-int *GetObsIDSubset (RegImage *image, int start, int *index, int *entry, int Nindex, int *Nsubset) {
-
-  int i, N, NSUBSET;
-  int *subset;
+off_t *GetObsIDSubset (RegImage *image, off_t start, off_t *index, off_t *entry, off_t Nindex, off_t *Nsubset) {
+
+  off_t i, N, NSUBSET;
+  off_t *subset;
 
   /* create output index */
   N = 0;
   NSUBSET = 64;
-  ALLOCATE (subset, int, NSUBSET);
+  ALLOCATE (subset, off_t, NSUBSET);
 
   /* find unique sequences */
@@ -143,5 +143,5 @@
     if (N == NSUBSET) {
       NSUBSET += 64;
-      REALLOCATE (subset, int, NSUBSET);
+      REALLOCATE (subset, off_t, NSUBSET);
     }
   }
@@ -152,13 +152,13 @@
 
 /* return an index list of unique obs id entries at start of sequence */
-int *GetUniqueObsID (RegImage *image, int *index, int *entry, int Nindex, int *Nmatch) {
-  
-  int i, j, N, NMATCH;
-  int *match;
+off_t *GetUniqueObsID (RegImage *image, off_t *index, off_t *entry, off_t Nindex, off_t *Nmatch) {
+  
+  off_t i, j, N, NMATCH;
+  off_t *match;
 
   /* create output index */
   N = 0;
   NMATCH = 1000;
-  ALLOCATE (match, int, NMATCH);
+  ALLOCATE (match, off_t, NMATCH);
 
   /* find unique sequences */
@@ -171,5 +171,5 @@
     if (N == NMATCH) {
       NMATCH += 1000;
-      REALLOCATE (match, int, NMATCH);
+      REALLOCATE (match, off_t, NMATCH);
     }
 
@@ -182,13 +182,13 @@
 
 /* return seeing for ccd == REFCCD */
-int GetREFCCD (RegImage *image, int *index, int *entry, int Nindex, int start) {
-  
-  int i, N, NMATCH;
-  int *match;
+off_t GetREFCCD (RegImage *image, off_t *index, off_t *entry, off_t Nindex, off_t start) {
+  
+  off_t i, N, NMATCH;
+  off_t *match;
 
   /* create output index */
   N = 0;
   NMATCH = 1000;
-  ALLOCATE (match, int, NMATCH);
+  ALLOCATE (match, off_t, NMATCH);
 
   /* find unique sequences */
@@ -199,12 +199,12 @@
 }
 
-void GetObsIDIndex (RegImage *image, int *match, int Nmatch, int **Index, int **Entry) {
-
-  int i;
-  int *index, *entry;
+void GetObsIDIndex (RegImage *image, off_t *match, off_t Nmatch, off_t **Index, off_t **Entry) {
+
+  off_t i;
+  off_t *index, *entry;
 
   /* index = OBSID */
-  ALLOCATE (index, int, Nmatch);
-  ALLOCATE (entry, int, Nmatch);
+  ALLOCATE (index, off_t, Nmatch);
+  ALLOCATE (entry, off_t, Nmatch);
   for (i = 0; i < Nmatch; i++) {
     index[i] = atoi (image[match[i]].filename);
@@ -212,5 +212,5 @@
     entry[i] = match[i];
   }
-  isortpair (index, entry, Nmatch);
+  llsortpair (index, entry, Nmatch);
   *Index = index;
   *Entry = entry;
@@ -218,7 +218,8 @@
 
 /* match is a list of image entries with the same obsid */
-double MosaicIQStats (RegImage *image, int *match, int Nmatch, MosaicRegion *region) {
-
-  int i, j, N, Nccd;
+double MosaicIQStats (RegImage *image, off_t *match, off_t Nmatch, MosaicRegion *region) {
+
+  int i, N, Nccd;
+  off_t j;
   double *list, value;
 
Index: trunk/Ohana/src/imregister/imreg/delete.c
===================================================================
--- trunk/Ohana/src/imregister/imreg/delete.c	(revision 27392)
+++ trunk/Ohana/src/imregister/imreg/delete.c	(revision 27435)
@@ -2,13 +2,13 @@
 # include "imreg.h"
 
-void DeleteSubset (FITS_DB *db, RegImage *image, int Nimage, int *match, int Nmatch) {
+void DeleteSubset (FITS_DB *db, RegImage *image, off_t Nimage, off_t *match, off_t Nmatch) {
 
-  int i, j;
-  int *keep, Ndel, Nsubset;
+  off_t i, j;
+  off_t *keep, Ndel, Nsubset;
   RegImage *subset;
 
-  ALLOCATE (keep, int, MAX (Nimage, 1));
+  ALLOCATE (keep, off_t, MAX (Nimage, 1));
   for (i = 0; i < Nimage; i++) keep[i] = TRUE;
-  fprintf (stderr, "total of %d images\n", Nimage);
+  fprintf (stderr, "total of %lld images\n", (long long) Nimage);
 
   Ndel = 0;
@@ -19,5 +19,5 @@
     Ndel ++;
   }
-  fprintf (stderr, "delete %d images\n", Ndel);
+  fprintf (stderr, "delete %lld images\n", (long long) Ndel);
   if (Ndel == 0) { 
     fprintf (stderr, "SUCCESS\n");
@@ -29,5 +29,5 @@
   Nsubset = Nimage - Ndel;
   ALLOCATE (subset, RegImage, MAX (1, Nsubset));
-  fprintf (stderr, "keeping %d images\n", Nsubset);
+  fprintf (stderr, "keeping %lld images\n", (long long) Nsubset);
   for (j = i = 0; i < Nimage; i++) {
     if (!keep[i]) continue;
Index: trunk/Ohana/src/imregister/imreg/iminfo.c
===================================================================
--- trunk/Ohana/src/imregister/imreg/iminfo.c	(revision 27392)
+++ trunk/Ohana/src/imregister/imreg/iminfo.c	(revision 27435)
@@ -42,5 +42,5 @@
 
   /* determine data layout (SINGLE, SPLIT, MEF, CUBE, SLICE) */
-  gfits_scan (&header, "EXTEND",  "%t", 1, &extend);
+  gfits_scan_alt (&header, "EXTEND",  "%t", 1, &extend);
   gfits_scan (&header, "NAXIS",  "%d", 1, &Naxes);
   if (extend) { /* MEF file */
@@ -68,5 +68,5 @@
 
   /* extract other relevant data from header */
-  gfits_scan (&header, ImagetypeKeyword,  "%s", 1, &Imagetype);
+  gfits_scan (&header, ImagetypeKeyword,  "%s", 1, (char *)&Imagetype);
 
   /* grab the image type : if not defined, set to 'none' */
@@ -108,5 +108,5 @@
       ohana_dms_to_ddd (&tmp, line);
       image[0].ra = 15*tmp;
-      gfits_scan (&header, DECSexigKeyword, "%s", 1, &line);
+      gfits_scan (&header, DECSexigKeyword, "%s", 1, (char *)&line);
       ohana_dms_to_ddd (&tmp, line);
       image[0].dec = tmp;
Index: trunk/Ohana/src/imregister/imreg/match.c
===================================================================
--- trunk/Ohana/src/imregister/imreg/match.c	(revision 27392)
+++ trunk/Ohana/src/imregister/imreg/match.c	(revision 27435)
@@ -2,15 +2,15 @@
 # include "imreg.h"
 
-int *match_criteria (RegImage *image, int Nimage, int *Nmatch) {
+off_t *match_criteria (RegImage *image, off_t Nimage, off_t *Nmatch) {
 
-  int i, j, Nname;
-  int N, NMATCH;
-  int *match;
-  int reject;
+  off_t i, j, Nname;
+  off_t N, NMATCH;
+  off_t *match;
+  off_t reject;
 
   /* create selection index */
   N = 0;
   NMATCH = 1000;
-  ALLOCATE (match, int, NMATCH);
+  ALLOCATE (match, off_t, NMATCH);
 
   Nname = 0;
@@ -36,5 +36,5 @@
     if (N == NMATCH) {
       NMATCH += 1000;
-      REALLOCATE (match, int, NMATCH);
+      REALLOCATE (match, off_t, NMATCH);
     }
   }
@@ -43,11 +43,11 @@
 }
 
-int *match_images (RegImage *image, int Nimage, RegImage *subset, int Nsubset, int *Nmatch) {
+off_t *match_images (RegImage *image, off_t Nimage, RegImage *subset, off_t Nsubset, off_t *Nmatch) {
   
-  int i, j, N, Nfound;
-  int *match;
+  off_t i, j, N, Nfound;
+  off_t *match;
 
   /* find matching images - very inefficient : sort by obstime, find those first? */
-  ALLOCATE (match, int, Nsubset);
+  ALLOCATE (match, off_t, Nsubset);
   for (j = 0; j < Nsubset; j++) {
     match[j] = -1;
Index: trunk/Ohana/src/imregister/imreg/modify.c
===================================================================
--- trunk/Ohana/src/imregister/imreg/modify.c	(revision 27392)
+++ trunk/Ohana/src/imregister/imreg/modify.c	(revision 27435)
@@ -2,7 +2,7 @@
 # include "imreg.h"
 
-void ModifySubset (FITS_DB *db, RegImage *image, int Nimage, int *match, int Nmatch) {
+void ModifySubset (FITS_DB *db, RegImage *image, off_t Nimage, off_t *match, off_t Nmatch) {
 
-  int i, j, Nold;
+  off_t i, j, Nold;
   char *tmppath;
   char *ext, *root, *path, dist;
Index: trunk/Ohana/src/imregister/imreg/newimages.c
===================================================================
--- trunk/Ohana/src/imregister/imreg/newimages.c	(revision 27392)
+++ trunk/Ohana/src/imregister/imreg/newimages.c	(revision 27435)
@@ -2,7 +2,7 @@
 # include "imreg.h"
 
-RegImage *newimages (RegImage *image, int *Nimage) {
+RegImage *newimages (RegImage *image, off_t *Nimage) {
 
-  int i, Nnew;
+  off_t i, Nnew;
   RegImage *regimage;
 
Index: trunk/Ohana/src/imregister/imreg/output.c
===================================================================
--- trunk/Ohana/src/imregister/imreg/output.c	(revision 27392)
+++ trunk/Ohana/src/imregister/imreg/output.c	(revision 27435)
@@ -24,5 +24,5 @@
 
 /* given a subset list, write out the selected images, if desired */
-void OutputSubset (RegImage *image, int Nimage, int *match, int Nmatch) {
+void OutputSubset (RegImage *image, off_t Nimage, off_t *match, off_t Nmatch) {
 
   if (output.table != (char *) NULL) {
@@ -45,7 +45,7 @@
 
 /* write out complete binary FITS table in format of db */
-void DumpFitsBintable (char *filename, RegImage *image, int *match, int Nmatch) {
-
-  int i, j;
+void DumpFitsBintable (char *filename, RegImage *image, off_t *match, off_t Nmatch) {
+
+  off_t i, j;
   FILE *f;
   Header header;
@@ -87,7 +87,7 @@
 }
 
-void DumpFitsTable (char *filename, RegImage *image, int *match, int Nmatch) {
-  
-  int i;
+void DumpFitsTable (char *filename, RegImage *image, off_t *match, off_t Nmatch) {
+  
+  off_t i;
   char *obsstr, *regstr, *line, dummy[64];
   char *modestr, *typestr, *ccdstr, *datestr;
@@ -184,8 +184,8 @@
 
 /* Select, TimeMode are global */
-int PrintSubset (RegImage *image, int *match, int Nmatch) {
+int PrintSubset (RegImage *image, off_t *match, off_t Nmatch) {
   
   char ccdstr[64];  
-  int i, j;
+  off_t i, j;
   char *modestr, *typestr, *timestr, *root, *path;
 
@@ -227,5 +227,5 @@
     } else {
       /* this is somewhat poor: I have predefined a subset of value, and I can't guarantee that 'filter' has no spaces */
-      fprintf (stdout, "%5d %6s %6s %s  ", i, typestr, modestr, ccdstr);
+      fprintf (stdout, "%5lld %6s %6s %s  ", (long long) i, typestr, modestr, ccdstr);
       fprintf (stdout, "%s %s  ", image[i].pathname, image[i].filename);
       fprintf (stdout, "%s %f %s %f %f %f\n", image[i].filter, image[i].exptime, 
@@ -238,7 +238,7 @@
 }
 
-int dump_data (RegImage *image, int Nimage) {
-
-  int i;
+int dump_data (RegImage *image, off_t Nimage) {
+
+  off_t i;
 
   for (i = 0; i < Nimage; i++) {
Index: trunk/Ohana/src/imregister/imreg/unique.c
===================================================================
--- trunk/Ohana/src/imregister/imreg/unique.c	(revision 27392)
+++ trunk/Ohana/src/imregister/imreg/unique.c	(revision 27435)
@@ -2,9 +2,9 @@
 # include "imreg.h"
 
-void sortstr (char **S, int *X, int N) {
+void sortstr (char **S, off_t *X, off_t N) {
 
 # define SWAPFUNC(A,B){ \
-  char *tmp = S[A]; S[A] = S[B]; S[B] = tmp; \
-  int  itmp = X[A]; X[A] = X[B]; X[B] = itmp; \
+  char  *tmp = S[A]; S[A] = S[B]; S[B] = tmp; \
+  off_t itmp = X[A]; X[A] = X[B]; X[B] = itmp; \
 }
 # define COMPARE(A,B)(strcmp(S[A], S[B]) < 0)
@@ -18,9 +18,9 @@
 
 /* input is a subset index of image list, output is a new subset */
-int *unique_entries (RegImage *image, int Nimage, int *subset, int *Nmatch) {
+off_t *unique_entries (RegImage *image, off_t Nimage, off_t *subset, off_t *Nmatch) {
 
-  int i, j, k, m, Nsubset;
-  int N, NMATCH;
-  int *match, *entry;
+  off_t i, j, k, m, Nsubset;
+  off_t N, NMATCH;
+  off_t *match, *entry;
   char idxline[128];
   char **index;
@@ -31,5 +31,5 @@
   N = 0;
   NMATCH = 1000;
-  ALLOCATE (match, int, NMATCH);
+  ALLOCATE (match, off_t, NMATCH);
 
   Nsubset = *Nmatch;
@@ -37,5 +37,5 @@
   /* index = filename.ccd */
   ALLOCATE (index, char *, Nsubset);
-  ALLOCATE (entry, int, Nsubset);
+  ALLOCATE (entry, off_t, Nsubset);
   for (i = 0; i < Nsubset; i++) {
     sprintf (idxline, "%s.%02d", image[subset[i]].filename, image[subset[i]].ccd);
@@ -63,5 +63,5 @@
     if (N == NMATCH) {
       NMATCH += 1000;
-      REALLOCATE (match, int, NMATCH);
+      REALLOCATE (match, off_t, NMATCH);
     }
 
Index: trunk/Ohana/src/imregister/include/detrend.h
===================================================================
--- trunk/Ohana/src/imregister/include/detrend.h	(revision 27392)
+++ trunk/Ohana/src/imregister/include/detrend.h	(revision 27435)
@@ -82,15 +82,15 @@
 char **LoadRecipe (char *filter, int *nrecipe);
 
-Match *MatchCriteria (DetReg *image, int Nimage, int *nmatch);
-Match *UniqueSubset (DetReg *image, int Nimage, Match *match, int *nmatch);
-Match *ExptimeCriteria (DetReg *image, int Nimage, Match *match, int *nmatch);
-Match *CloseCriteria (DetReg *image, int Nimage, Match *match, int *nmatch);
+Match *MatchCriteria (DetReg *image, off_t Nimage, off_t *nmatch);
+Match *UniqueSubset (DetReg *image, off_t Nimage, Match *match, off_t *nmatch);
+Match *ExptimeCriteria (DetReg *image, off_t Nimage, Match *match, off_t *nmatch);
+Match *CloseCriteria (DetReg *image, off_t Nimage, Match *match, off_t *nmatch);
 
 Match CheckCriteria (DetReg *image);
 
-int OutputSubset (DetReg *image, int Nimage, Match *match, int Nmatch);
-int DumpFitsTable (char *filename, DetReg *detdata, Match *match, int Nmatch);
-int PrintSubset (DetReg *detdata, Match *match, int Nmatch);
-Match SelectEntry (DetReg *image, int Nimage, Match *list, int Nlist, Criteria *crit);
+int OutputSubset (DetReg *image, off_t Nimage, Match *match, off_t Nmatch);
+int DumpFitsTable (char *filename, DetReg *detdata, Match *match, off_t Nmatch);
+int PrintSubset (DetReg *detdata, Match *match, off_t Nmatch);
+Match SelectEntry (DetReg *image, off_t Nimage, Match *list, off_t Nlist, Criteria *crit);
 
 int usage (void);
@@ -101,5 +101,5 @@
 
 int escape (int mode, char *message);
-int DumpFitsBintable (char *filename, DetReg *image, Match *match, int Nmatch);
+int DumpFitsBintable (char *filename, DetReg *image, Match *match, off_t Nmatch);
 int cmp_crit (Criteria *crit, DetReg *image);
 int set_crit (Criteria *crit, DetReg *image);
@@ -107,5 +107,5 @@
 int PrintCriteria (void);
 
-int SetAltpath (FITS_DB *db, DetReg *image, int Nimage, Match *match, int Nmatch);
-int ModifySubset (FITS_DB *db, DetReg *image, int Nimage, Match *match, int Nmatch);
-void DeleteSubset (FITS_DB *db, DetReg *image, int Nimage, Match *match, int Nmatch);
+int SetAltpath (FITS_DB *db, DetReg *image, off_t Nimage, Match *match, off_t Nmatch);
+int ModifySubset (FITS_DB *db, DetReg *image, off_t Nimage, Match *match, off_t Nmatch);
+void DeleteSubset (FITS_DB *db, DetReg *image, off_t Nimage, Match *match, off_t Nmatch);
Index: trunk/Ohana/src/imregister/include/imphot.h
===================================================================
--- trunk/Ohana/src/imregister/include/imphot.h	(revision 27392)
+++ trunk/Ohana/src/imregister/include/imphot.h	(revision 27435)
@@ -20,10 +20,10 @@
 int db_load (FITS_DB *db);
 int args (int argc, char **argv);
-int DumpFitsBintable (char *filename, Image *image, int *match, int Nmatch);
-int DumpFitsTable (char *filename, Image *image, int *match, int Nmatch);
-void ModifySubset (FITS_DB *db, Image *image, int Nimage, int *match, int Nmatch);
-int PrintSubset (Image *image, int *match, int Nmatch);
-int output (Image *image, int *match, int Nmatch);
+int DumpFitsBintable (char *filename, Image *image, off_t *match, off_t Nmatch);
+int DumpFitsTable (char *filename, Image *image, off_t *match, off_t Nmatch);
+void ModifySubset (FITS_DB *db, Image *image, off_t Nimage, off_t *match, off_t Nmatch);
+int PrintSubset (Image *image, off_t *match, off_t Nmatch);
+int output (Image *image, off_t *match, off_t Nmatch);
 int rfits (FITS_DB *db);
 int rtext (FITS_DB *db);
-int *subset (Image *image, int Nimage, int *nsubset);
+off_t *subset (Image *image, off_t Nimage, off_t *nsubset);
Index: trunk/Ohana/src/imregister/include/imreg.h
===================================================================
--- trunk/Ohana/src/imregister/include/imreg.h	(revision 27392)
+++ trunk/Ohana/src/imregister/include/imreg.h	(revision 27435)
@@ -74,19 +74,19 @@
 int args (int argc, char **argv);
 
-void DeleteSubset (FITS_DB *db, RegImage *image, int Nimage, int *match, int Nmatch);
+void DeleteSubset (FITS_DB *db, RegImage *image, off_t Nimage, off_t *match, off_t Nmatch);
 RegImage *iminfo (char *filename);
 
-int *match_criteria (RegImage *image, int Nimage, int *Nmatch);
-int *match_images (RegImage *image, int Nimage, RegImage *subset, int Nsubset, int *Nmatch);
+off_t *match_criteria (RegImage *image, off_t Nimage, off_t *Nmatch);
+off_t *match_images (RegImage *image, off_t Nimage, RegImage *subset, off_t Nsubset, off_t *Nmatch);
 
-RegImage *newimages (RegImage *image, int *Nimage);
+RegImage *newimages (RegImage *image, off_t *Nimage);
 
-void ModifySubset (FITS_DB *db, RegImage *image, int Nimage, int *match, int Nmatch);
+void ModifySubset (FITS_DB *db, RegImage *image, off_t Nimage, off_t *match, off_t Nmatch);
 void SetOutputMode (char *mode);
-void OutputSubset (RegImage *image, int Nimage, int *match, int Nmatch);
-void DumpFitsBintable (char *filename, RegImage *image, int *match, int Nmatch);
-void DumpFitsTable (char *filename, RegImage *image, int *match, int Nmatch);
-int PrintSubset (RegImage *image, int *match, int Nmatch);
-int dump_data (RegImage *image, int Nimage);
+void OutputSubset (RegImage *image, off_t Nimage, off_t *match, off_t Nmatch);
+void DumpFitsBintable (char *filename, RegImage *image, off_t *match, off_t Nmatch);
+void DumpFitsTable (char *filename, RegImage *image, off_t *match, off_t Nmatch);
+int PrintSubset (RegImage *image, off_t *match, off_t Nmatch);
+int dump_data (RegImage *image, off_t Nimage);
 int SubmitImages (RegImage *image);
 int load_probes (char *filename, unsigned long tzero, int *wantprobe, double *values, int Nprobe);
@@ -94,13 +94,13 @@
 void set_timezone (double dt);
 
-void DumpCADCTable (char *filename, RegImage *image, int *match, int Nmatch);
-int *GetObsIDSubset (RegImage *image, int start, int *index, int *entry, int Nindex, int *Nsubset);
-int *GetUniqueObsID (RegImage *image, int *index, int *entry, int Nindex, int *Nmatch);
-void GetObsIDIndex (RegImage *image, int *match, int Nmatch, int **Index, int **Entry);
+void DumpCADCTable (char *filename, RegImage *image, off_t *match, off_t Nmatch);
+off_t *GetObsIDSubset (RegImage *image, off_t start, off_t *index, off_t *entry, off_t Nindex, off_t *Nsubset);
+off_t *GetUniqueObsID (RegImage *image, off_t *index, off_t *entry, off_t Nindex, off_t *Nmatch);
+void GetObsIDIndex (RegImage *image, off_t *match, off_t Nmatch, off_t **Index, off_t **Entry);
 double SigmaClipList (double *list, int N);
-double MosaicIQStats (RegImage *image, int *match, int Nmatch, MosaicRegion *region);
+double MosaicIQStats (RegImage *image, off_t *match, off_t Nmatch, MosaicRegion *region);
 MosaicLayout *CreateCFH12K (void);
 MosaicLayout *CreateMegaCam (void);
-int GetREFCCD (RegImage *image, int *index, int *entry, int Nindex, int start);
+off_t GetREFCCD (RegImage *image, off_t *index, off_t *entry, off_t Nindex, off_t start);
 
 int imregclient (char *fitsfile, char *statfile, char *datfile);
@@ -128,3 +128,3 @@
 int memstr (char *m1, char *m2, int n);
 
-int *unique_entries (RegImage *image, int Nimage, int *subset, int *Nmatch);
+off_t *unique_entries (RegImage *image, off_t Nimage, off_t *subset, off_t *Nmatch);
Index: trunk/Ohana/src/imregister/include/imregister.h
===================================================================
--- trunk/Ohana/src/imregister/include/imregister.h	(revision 27392)
+++ trunk/Ohana/src/imregister/include/imregister.h	(revision 27435)
@@ -73,8 +73,5 @@
 
 int parse_time (Header *header);
-void sort (float *value, int N);
-void dsort (double *value, int N);
-void sortstr (char **S, int *X, int N);
-void sortpair (int *X, int *Y, int N);
+void sortstr (char **S, off_t *X, off_t N);
 
 void ConfigCamera (void);
@@ -92,5 +89,5 @@
 
 void warn_scan (Header *header, char *field, char *format, int N, void *var);
-int gfits_scan_nchar (Header *header, int size, char *field, int N,...);
+int gfits_scan_nchar (Header *header, int size, char *field, int N,...) OHANA_FORMAT(scanf, 3, 5);
 void warn_scan_nchar (Header *header, int size, char *field, int N, void *var);
 
Index: trunk/Ohana/src/imregister/include/photreg.h
===================================================================
--- trunk/Ohana/src/imregister/include/photreg.h	(revision 27392)
+++ trunk/Ohana/src/imregister/include/photreg.h	(revision 27435)
@@ -29,12 +29,12 @@
 int regargs (int argc, char **argv, PhotPars *);
 
-void DeleteSubset (FITS_DB *db, PhotPars *photpars, int Nphotpars, int *match, int Nmatch);
-int *match_criteria (PhotPars *photpars, int Nphotpars, int *Nmatch);
+void DeleteSubset (FITS_DB *db, PhotPars *photpars, off_t Nphotpars, off_t *match, off_t Nmatch);
+off_t *match_criteria (PhotPars *photpars, off_t Nphotpars, off_t *Nmatch);
 
-void OutputSubset (PhotPars *photpars, int Nphotpars, int *match, int Nmatch);
+void OutputSubset (PhotPars *photpars, off_t Nphotpars, off_t *match, off_t Nmatch);
 
-void DumpFitsBintable (char *filename, PhotPars *image, int *match, int Nmatch);
-void DumpFitsTable (char *filename, PhotPars *image, int *match, int Nmatch);
-int PrintSubset (PhotPars *image, int *match, int Nmatch);
+void DumpFitsBintable (char *filename, PhotPars *image, off_t *match, off_t Nmatch);
+void DumpFitsTable (char *filename, PhotPars *image, off_t *match, off_t Nmatch);
+int PrintSubset (PhotPars *image, off_t *match, off_t Nmatch);
 
 void set_timezone (double dt);
@@ -42,4 +42,4 @@
 int escape (int mode, char *message);
 
-PhotPars *PhotParsOld_to_PhotPars (PhotParsOld *input, int Nphotpars);
+PhotPars *PhotParsOld_to_PhotPars (PhotParsOld *input, off_t Nphotpars);
 
Index: trunk/Ohana/src/imregister/include/spreg.h
===================================================================
--- trunk/Ohana/src/imregister/include/spreg.h	(revision 27392)
+++ trunk/Ohana/src/imregister/include/spreg.h	(revision 27435)
@@ -78,21 +78,20 @@
 char TelescopeKeyword[64];
 
+int args (int argc, char **argv);
+off_t *match_criteria (Spectrum *spectrum, off_t Nspectrum, off_t *Nmatch);
+off_t *unique_entries (Spectrum *spectrum, off_t Nspectrum, off_t *subset, off_t *Nmatch);
 
-int args (int argc, char **argv);
-int *match_criteria (Spectrum *spectrum, int Nspectrum, int *Nmatch);
-int *unique_entries (Spectrum *spectrum, int Nspectrum, int *subset, int *Nmatch);
-
-void ModifySubset (FITS_DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch);
-void DeleteSubset (FITS_DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch);
-void OutputSubset (Spectrum *spectrum, int Nspectrum, int *match, int Nmatch);
+void ModifySubset (FITS_DB *db, Spectrum *spectrum, off_t Nspectrum, off_t *match, off_t Nmatch);
+void DeleteSubset (FITS_DB *db, Spectrum *spectrum, off_t Nspectrum, off_t *match, off_t Nmatch);
+void OutputSubset (Spectrum *spectrum, off_t Nspectrum, off_t *match, off_t Nmatch);
 
 void SetOutputMode (char *mode);
-void DumpFitsBintable (char *filename, Spectrum *spectrum, int *match, int Nmatch);
-void DumpFitsTable (char *filename, Spectrum *spectrum, int *match, int Nmatch);
-int PrintSubset (Spectrum *spectrum, int *match, int Nmatch);
-int dump_data (Spectrum *spectrum, int Nspectrum);
+void DumpFitsBintable (char *filename, Spectrum *spectrum, off_t *match, off_t Nmatch);
+void DumpFitsTable (char *filename, Spectrum *spectrum, off_t *match, off_t Nmatch);
+int PrintSubset (Spectrum *spectrum, off_t *match, off_t Nmatch);
+int dump_data (Spectrum *spectrum, off_t Nspectrum);
 
 Spectrum *spinfo (char *filename);
-int *match_spectrums (Spectrum *subset, int Nsubset, int *Nmatch);
+off_t *match_spectrums (Spectrum *subset, off_t Nsubset, off_t *Nmatch);
 int SubmitSpectrums (Spectrum *spectrum);
 void set_timezone (double dt);
@@ -100,6 +99,6 @@
 void showinfo (Spectrum *spec);
 int escape (int mode, char *message);
-int set_spectra (Spectrum *new, int Nnew);
-Spectrum *get_spectra (int *N);
+int set_spectra (Spectrum *new, off_t Nnew);
+Spectrum *get_spectra (off_t *N);
 
 void ConfigInitSpec (int *argc, char **argv);
Index: trunk/Ohana/src/imregister/photreg/convert.c
===================================================================
--- trunk/Ohana/src/imregister/photreg/convert.c	(revision 27392)
+++ trunk/Ohana/src/imregister/photreg/convert.c	(revision 27435)
@@ -2,7 +2,7 @@
 # include "photreg.h"
 
-PhotPars *PhotParsOld_to_PhotPars (PhotParsOld *input, int Nphotpars) {
+PhotPars *PhotParsOld_to_PhotPars (PhotParsOld *input, off_t Nphotpars) {
 
-  int i;
+  off_t i;
   PhotPars *output;
 
Index: trunk/Ohana/src/imregister/photreg/delete.c
===================================================================
--- trunk/Ohana/src/imregister/photreg/delete.c	(revision 27392)
+++ trunk/Ohana/src/imregister/photreg/delete.c	(revision 27435)
@@ -2,13 +2,13 @@
 # include "photreg.h"
 
-void DeleteSubset (FITS_DB *db, PhotPars *photdata, int Nphotdata, int *match, int Nmatch) {
+void DeleteSubset (FITS_DB *db, PhotPars *photdata, off_t Nphotdata, off_t *match, off_t Nmatch) {
 
-  int i, j;
-  int *keep, Ndel, Nsubset;
+  off_t i, j;
+  off_t *keep, Ndel, Nsubset;
   PhotPars *subset;
 
-  ALLOCATE (keep, int, MAX (Nphotdata, 1));
+  ALLOCATE (keep, off_t, MAX (Nphotdata, 1));
   for (i = 0; i < Nphotdata; i++) keep[i] = TRUE;
-  fprintf (stderr, "total of %d photdata\n", Nphotdata);
+  fprintf (stderr, "total of %lld photdata\n", (long long) Nphotdata);
 
   Ndel = 0;
@@ -19,5 +19,5 @@
     Ndel ++;
   }
-  fprintf (stderr, "delete %d photdata\n", Ndel);
+  fprintf (stderr, "delete %lld photdata\n", (long long) Ndel);
 
   if (Ndel == 0) { 
@@ -31,5 +31,5 @@
   Nsubset = Nphotdata - Ndel;
   ALLOCATE (subset, PhotPars, MAX (1, Nsubset));
-  fprintf (stderr, "keeping %d photdata\n", Nsubset);
+  fprintf (stderr, "keeping %lld photdata\n", (long long) Nsubset);
   for (j = i = 0; i < Nphotdata; i++) {
     if (!keep[i]) continue;
Index: trunk/Ohana/src/imregister/photreg/match.c
===================================================================
--- trunk/Ohana/src/imregister/photreg/match.c	(revision 27392)
+++ trunk/Ohana/src/imregister/photreg/match.c	(revision 27435)
@@ -2,15 +2,15 @@
 # include "photreg.h"
 
-int *match_criteria (PhotPars *photdata, int Nphotdata, int *Nmatch) {
+off_t *match_criteria (PhotPars *photdata, off_t Nphotdata, off_t *Nmatch) {
 
-  int i, j;
-  int N, NMATCH;
-  int *match;
-  int reject;
+  off_t i, j;
+  off_t N, NMATCH;
+  off_t *match;
+  off_t reject;
 
   /* create selection index */
   N = 0;
   NMATCH = 1000;
-  ALLOCATE (match, int, NMATCH);
+  ALLOCATE (match, off_t, NMATCH);
 
   /* find entries that matches criteria */
@@ -27,5 +27,5 @@
     if (N == NMATCH) {
       NMATCH += 1000;
-      REALLOCATE (match, int, NMATCH);
+      REALLOCATE (match, off_t, NMATCH);
     }
   }
Index: trunk/Ohana/src/imregister/photreg/output.c
===================================================================
--- trunk/Ohana/src/imregister/photreg/output.c	(revision 27392)
+++ trunk/Ohana/src/imregister/photreg/output.c	(revision 27435)
@@ -6,5 +6,5 @@
 
 /* given a subset list, write out the selected images, if desired */
-void OutputSubset (PhotPars *photdata, int Nphotdata, int *match, int Nmatch) {
+void OutputSubset (PhotPars *photdata, off_t Nphotdata, off_t *match, off_t Nmatch) {
 
   if (output.table != (char *) NULL) {
@@ -23,7 +23,7 @@
 
 /* write out complete binary FITS table in format of db */
-void DumpFitsBintable (char *filename, PhotPars *photdata, int *match, int Nmatch) {
-
-  int i, j;
+void DumpFitsBintable (char *filename, PhotPars *photdata, off_t *match, off_t Nmatch) {
+
+  off_t i, j;
   FILE *f;
   Header header;
@@ -71,5 +71,5 @@
 
 /** add ASCII table to autocode? **/
-void DumpFitsTable (char *filename, PhotPars *photdata, int *index, int Nkeep) {
+void DumpFitsTable (char *filename, PhotPars *photdata, off_t *index, off_t Nkeep) {
   
   Header header, theader;
@@ -80,5 +80,5 @@
   char *startstr, *stopstr, *datestr, *line;
   char *c1, *c2, *code, *photsys, *extname;
-  int i;
+  off_t i;
   time_t tsecond;
 
@@ -196,7 +196,7 @@
 
 /* Select, TimeMode are global */
-int PrintSubset (PhotPars *photdata, int *match, int Nmatch) {
-  
-  int i, j;
+int PrintSubset (PhotPars *photdata, off_t *match, off_t Nmatch) {
+  
+  off_t i, j;
   char *photstr, *timestr, *c1, *c2, *refcode;
   
Index: trunk/Ohana/src/imregister/spreg/delete.c
===================================================================
--- trunk/Ohana/src/imregister/spreg/delete.c	(revision 27392)
+++ trunk/Ohana/src/imregister/spreg/delete.c	(revision 27435)
@@ -2,13 +2,13 @@
 # include "spreg.h"
 
-void DeleteSubset (FITS_DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch) {
+void DeleteSubset (FITS_DB *db, Spectrum *spectrum, off_t Nspectrum, off_t *match, off_t Nmatch) {
 
-  int i, j;
-  int *keep, Nbad, Nsubset;
+  off_t i, j;
+  off_t *keep, Nbad, Nsubset;
   Spectrum *subset;
 
-  ALLOCATE (keep, int, MAX (Nspectrum, 1));
+  ALLOCATE (keep, off_t, MAX (Nspectrum, 1));
   for (i = 0; i < Nspectrum; i++) keep[i] = TRUE;
-  fprintf (stderr, "total of %d spectra\n", Nspectrum);
+  fprintf (stderr, "total of %lld spectra\n", (long long) Nspectrum);
 
   Nbad = 0;
@@ -19,5 +19,5 @@
     Nbad ++;
   }
-  fprintf (stderr, "delete %d spectra\n", Nbad);
+  fprintf (stderr, "delete %lld spectra\n", (long long) Nbad);
   if (Nbad == 0) { 
     fprintf (stderr, "SUCCESS\n");
@@ -28,5 +28,5 @@
   Nsubset = Nspectrum - Nbad;
   ALLOCATE (subset, Spectrum, MAX (1, Nsubset));
-  fprintf (stderr, "keeping %d spectra\n", Nsubset);
+  fprintf (stderr, "keeping %lld spectra\n", (long long) Nsubset);
   for (j = i = 0; i < Nspectrum; i++) {
     if (!keep[i]) continue;
Index: trunk/Ohana/src/imregister/spreg/match.c
===================================================================
--- trunk/Ohana/src/imregister/spreg/match.c	(revision 27392)
+++ trunk/Ohana/src/imregister/spreg/match.c	(revision 27435)
@@ -2,16 +2,16 @@
 # include "spreg.h"
 
-int *match_criteria (Spectrum *spectrum, int Nspectrum, int *Nmatch) {
+off_t *match_criteria (Spectrum *spectrum, off_t Nspectrum, off_t *Nmatch) {
 
-  int i, j;
-  int N, NMATCH;
-  int *match;
-  int reject;
-  int Nfilename, Nobject, Ntelescope, Ninstrument;
+  off_t i, j;
+  off_t N, NMATCH;
+  off_t *match;
+  off_t reject;
+  off_t Nfilename, Nobject, Ntelescope, Ninstrument;
 
   /* create selection index */
   N = 0;
   NMATCH = 1000;
-  ALLOCATE (match, int, NMATCH);
+  ALLOCATE (match, off_t, NMATCH);
 
   Nfilename = Nobject = Ntelescope = Ninstrument = 0;
@@ -42,5 +42,5 @@
     if (N == NMATCH) {
       NMATCH += 1000;
-      REALLOCATE (match, int, NMATCH);
+      REALLOCATE (match, off_t, NMATCH);
     }
   }
@@ -51,8 +51,8 @@
 # if (0)
 
-int *match_spectra (Spectrum *subset, int Nsubset, int *Nmatch) {
+off_t *match_spectra (Spectrum *subset, off_t Nsubset, off_t *Nmatch) {
   
-  int i, j, N, Nspectrum, Nfound;
-  int *match;
+  off_t i, j, N, Nspectrum, Nfound;
+  off_t *match;
   Spectrum *spectrum;
 
@@ -60,5 +60,5 @@
 
   /* find matching spectra - very inefficient : sort by obstime, find those first? */
-  ALLOCATE (match, int, Nsubset);
+  ALLOCATE (match, off_t, Nsubset);
   for (j = 0; j < Nsubset; j++) {
     match[j] = -1;
Index: trunk/Ohana/src/imregister/spreg/modify.c
===================================================================
--- trunk/Ohana/src/imregister/spreg/modify.c	(revision 27392)
+++ trunk/Ohana/src/imregister/spreg/modify.c	(revision 27435)
@@ -2,7 +2,7 @@
 # include "spreg.h"
 
-void ModifySubset (FITS_DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch) {
+void ModifySubset (FITS_DB *db, Spectrum *spectrum, off_t Nspectrum, off_t *match, off_t Nmatch) {
 
-  int i, j, Nold;
+  off_t i, j, Nold;
   char *tmppath;
 
Index: trunk/Ohana/src/imregister/spreg/output.c
===================================================================
--- trunk/Ohana/src/imregister/spreg/output.c	(revision 27392)
+++ trunk/Ohana/src/imregister/spreg/output.c	(revision 27435)
@@ -14,5 +14,5 @@
 
 /* given a subset list, write out the selected spectra, if desired */
-void OutputSubset (Spectrum *spectrum, int Nspectra, int *match, int Nmatch) {
+void OutputSubset (Spectrum *spectrum, off_t Nspectra, off_t *match, off_t Nmatch) {
 
   if (output.table != (char *) NULL) {
@@ -29,7 +29,7 @@
 
 /* write out complete binary FITS table in format of db */
-void DumpFitsBintable (char *filename, Spectrum *spectrum, int *match, int Nmatch) {
+void DumpFitsBintable (char *filename, Spectrum *spectrum, off_t *match, off_t Nmatch) {
 
-  int i, j;
+  off_t i, j;
   FILE *f;
   Header header;
@@ -72,7 +72,7 @@
 
 /* write out an ASCII table */
-void DumpFitsTable (char *filename, Spectrum *spectrum, int *match, int Nmatch) {
+void DumpFitsTable (char *filename, Spectrum *spectrum, off_t *match, off_t Nmatch) {
   
-  int i;
+  off_t i;
   char *obsstr, *regstr, *line, *datestr;
   time_t tsecond;
@@ -141,7 +141,7 @@
 
 /* Select, TimeMode are global */
-int PrintSubset (Spectrum *spectrum, int *match, int Nmatch) {
+int PrintSubset (Spectrum *spectrum, off_t *match, off_t Nmatch) {
   
-  int i, j;
+  off_t i, j;
   char *timestr;
 
@@ -153,5 +153,5 @@
 
     /* predefined subset of values */
-    fprintf (stdout, "%5d %20s %s %s %s %s ", i, timestr, spectrum[i].pathname, spectrum[i].filename, spectrum[i].objname, spectrum[i].telescope);
+    fprintf (stdout, "%5lld %20s %s %s %s %s ", (long long) i, timestr, spectrum[i].pathname, spectrum[i].filename, spectrum[i].objname, spectrum[i].telescope);
     fprintf (stdout, "%5.1f %5.3f %.1f %.1f %.2f\n", spectrum[i].exptime, spectrum[i].airmass, spectrum[i].Ws, spectrum[i].We, spectrum[i].dW);
 
@@ -161,7 +161,7 @@
 }
 
-int dump_data (Spectrum *spectrum, int Nspectrum) {
+int dump_data (Spectrum *spectrum, off_t Nspectrum) {
 
-  int i;
+  off_t i;
 
   for (i = 0; i < Nspectrum; i++) {
Index: trunk/Ohana/src/imregister/spreg/unique.c
===================================================================
--- trunk/Ohana/src/imregister/spreg/unique.c	(revision 27392)
+++ trunk/Ohana/src/imregister/spreg/unique.c	(revision 27435)
@@ -2,9 +2,9 @@
 # include "spreg.h"
 
-void sortstr (char **S, int *X, int N) {
+void sortstr (char **S, off_t *X, off_t N) {
 
 # define SWAPFUNC(A,B){ \
   char *tmp = S[A]; S[A] = S[B]; S[B] = tmp; \
-  int  itmp = X[A]; X[A] = X[B]; X[B] = itmp; \
+  off_t  itmp = X[A]; X[A] = X[B]; X[B] = itmp; \
 }
 # define COMPARE(A,B)(strcmp(S[A], S[B]) < 0)
@@ -18,9 +18,9 @@
 
 /* input is a subset index of spectrum list, output is a new subset */
-int *unique_entries (Spectrum *spectrum, int Nspectrum, int *subset, int *Nmatch) {
+off_t *unique_entries (Spectrum *spectrum, off_t Nspectrum, off_t *subset, off_t *Nmatch) {
 
-  int i, j, m, Nsubset;
-  int N, NMATCH;
-  int *match, *entry;
+  off_t i, j, m, Nsubset;
+  off_t N, NMATCH;
+  off_t *match, *entry;
   char idxline[128];
   char **index;
@@ -31,5 +31,5 @@
   N = 0;
   NMATCH = 1000;
-  ALLOCATE (match, int, NMATCH);
+  ALLOCATE (match, off_t, NMATCH);
 
   Nsubset = *Nmatch;
@@ -37,5 +37,5 @@
   /* index = filename */
   ALLOCATE (index, char *, Nsubset);
-  ALLOCATE (entry, int, Nsubset);
+  ALLOCATE (entry, off_t, Nsubset);
   for (i = 0; i < Nsubset; i++) {
     sprintf (idxline, "%s", spectrum[subset[i]].filename);
@@ -55,5 +55,5 @@
     if (N == NMATCH) {
       NMATCH += 1000;
-      REALLOCATE (match, int, NMATCH);
+      REALLOCATE (match, off_t, NMATCH);
     }
 
Index: trunk/Ohana/src/imregister/src/convertimreg.c
===================================================================
--- trunk/Ohana/src/imregister/src/convertimreg.c	(revision 27392)
+++ trunk/Ohana/src/imregister/src/convertimreg.c	(revision 27435)
@@ -8,6 +8,6 @@
   Header header;
   RegImage *pimage;
-  int i, Nimage, status, lockstate, dbstate;
-  int *match;
+  off_t i, Nimage, *match, status;
+  int lockstate, dbstate;
   
   get_version (argc, argv, version);
@@ -41,9 +41,9 @@
 
   /* load existing data from database */
-  gfits_scan (&header, "NIMAGES", "%d", 1, &Nimage);
+  gfits_scan (&header, "NIMAGES", "%lld", 1, (long long *) &Nimage);
   ALLOCATE (pimage, RegImage, Nimage);
   status = fread (pimage, sizeof(RegImage), Nimage, f);
   if (status != Nimage) {
-    fprintf (stderr, "ERROR: header and data in dB don't match (%d vs %d)\n", Nimage, status);
+    fprintf (stderr, "ERROR: header and data in dB don't match (%lld vs %lld)\n", (long long) Nimage, (long long) status);
     fclearlockfile (argv[1], f, lockstate, &dbstate);
     exit (1);
@@ -53,5 +53,5 @@
 
   /* create complete subset */
-  ALLOCATE (match, int, Nimage);
+  ALLOCATE (match, off_t, Nimage);
   for (i = 0; i < Nimage; i++) match[i] = i;
 
Index: trunk/Ohana/src/imregister/src/detsearch.c
===================================================================
--- trunk/Ohana/src/imregister/src/detsearch.c	(revision 27392)
+++ trunk/Ohana/src/imregister/src/detsearch.c	(revision 27435)
@@ -5,5 +5,5 @@
 int main (int argc, char **argv) {
  
-  int Nmatch, Ndetrend;
+  off_t Nmatch, Ndetrend;
   char *dBFile;
   FITS_DB db;
Index: trunk/Ohana/src/imregister/src/imphotmerge.c
===================================================================
--- trunk/Ohana/src/imregister/src/imphotmerge.c	(revision 27392)
+++ trunk/Ohana/src/imregister/src/imphotmerge.c	(revision 27435)
@@ -3,15 +3,16 @@
 /*** this needs to be written using dvo_image functions !!! ***/
 
-Image *LoadImageTable (FILE *f, Header *header, int *nimage);
+Image *LoadImageTable (FILE *f, Header *header, off_t *nimage);
 static char *version = "imphotcopy $Revision: 1.6 $";
 
 int main (int argc, char **argv) {
  
+  int N, Ntimes;
+  off_t status, Nimage;
+  off_t i, j, Ninput, *index;
   Header header, theader;
   Image *image, *input;
   FILE *f, *g;
-  int i, j, status, N;
   char *dBFile;
-  int Nimage, Ninput, *index, Ntimes;
   time_t *tstart, *tstop;
   int VERBOSE, PHOTCODE, dbstate;
@@ -91,5 +92,5 @@
   /* allocate space for reference lists */
   Nin = 0;
-  ALLOCATE (index, int, Ninput);
+  ALLOCATE (index, off_t, Ninput);
   
   /* these filters are applied to input NOT image */
@@ -115,7 +116,7 @@
 
   /* position to begining of file to write header */
-  fseek (f, 0, SEEK_SET);
-  status = Fwrite (header.buffer, 1, header.size, f, "char");
-  if (status != header.size) {
+  fseeko (f, 0, SEEK_SET);
+  status = Fwrite (header.buffer, 1, header.datasize, f, "char");
+  if (status != header.datasize) {
     fprintf (stderr, "ERROR: failed writing data to image header\n");
     exit (0);
@@ -123,5 +124,5 @@
 
   /* position to end of file for new image data */
-  fseek (f, header.size, SEEK_SET);
+  fseeko (f, header.datasize, SEEK_SET);
   status = Fwrite (image, sizeof(Image), Nimage, f, "image");
   if (status != Nimage) {
@@ -137,7 +138,7 @@
 }
 
-Image *LoadImageTable (FILE *f, Header *header, int *nimage) {
+Image *LoadImageTable (FILE *f, Header *header, off_t *nimage) {
 
-  int Nimage, Ndata, Nread, size;
+  off_t Nimage, Ndata, Nread, size;
   struct stat filestatus;
   Image *image;
@@ -151,14 +152,14 @@
   /* check that file size makes sense */
   Nimage = 0;
-  gfits_scan (header, "NIMAGES", "%d", 1, &Nimage);
+  gfits_scan (header, "NIMAGES", "%lld", 1, &Nimage);
   if (fstat (fileno(f), &filestatus) == -1) {
     fprintf (stderr, "ERROR: failed to get status of image catalog\n");
     exit (1);
   }
-  size = Nimage*sizeof(Image) + header[0].size;
+  size = Nimage*sizeof(Image) + header[0].datasize;
   if (size != filestatus.st_size) {
-    Ndata = (filestatus.st_size - header[0].size) / sizeof (Image);
+    Ndata = (filestatus.st_size - header[0].datasize) / sizeof (Image);
     fprintf (stderr, "ERROR: image catalog has inconsistent size\n");
-    fprintf (stderr, "header: %d, data: %d\n", Nimage, Ndata);
+    fprintf (stderr, "header: %lld, data: %lld\n", (long long) Nimage, (long long) Ndata);
     Nimage = Ndata;
   } 
Index: trunk/Ohana/src/imregister/src/imphotsearch.c
===================================================================
--- trunk/Ohana/src/imregister/src/imphotsearch.c	(revision 27392)
+++ trunk/Ohana/src/imregister/src/imphotsearch.c	(revision 27435)
@@ -6,6 +6,6 @@
 int main (int argc, char **argv) {
  
-  int Nmatch, Nimage;
-  int *match;
+  off_t Nmatch, Nimage;
+  off_t *match;
   Image *image;
   FITS_DB db;
Index: trunk/Ohana/src/imregister/src/imregister.c
===================================================================
--- trunk/Ohana/src/imregister/src/imregister.c	(revision 27392)
+++ trunk/Ohana/src/imregister/src/imregister.c	(revision 27435)
@@ -5,5 +5,5 @@
 int main (int argc, char **argv) {
  
-  int Nregimage;
+  off_t Nregimage;
   RegImage *image, *regimage;
   FITS_DB db;
Index: trunk/Ohana/src/imregister/src/imregtable.c
===================================================================
--- trunk/Ohana/src/imregister/src/imregtable.c	(revision 27392)
+++ trunk/Ohana/src/imregister/src/imregtable.c	(revision 27435)
@@ -5,5 +5,5 @@
 int main (int argc, char **argv) {
  
-  int Nimage;
+  off_t Nimage;
   char *infile;
   RegImage *image;
Index: trunk/Ohana/src/imregister/src/imsearch.c
===================================================================
--- trunk/Ohana/src/imregister/src/imsearch.c	(revision 27392)
+++ trunk/Ohana/src/imregister/src/imsearch.c	(revision 27435)
@@ -5,5 +5,5 @@
 int main (int argc, char **argv) {
  
-  int Nmatch, Nimage, *match;
+  off_t Nmatch, Nimage, *match;
   RegImage *image;
   FITS_DB db;
Index: trunk/Ohana/src/imregister/src/imstatreg.c
===================================================================
--- trunk/Ohana/src/imregister/src/imstatreg.c	(revision 27392)
+++ trunk/Ohana/src/imregister/src/imstatreg.c	(revision 27435)
@@ -5,6 +5,6 @@
 int main (int argc, char **argv) {
  
-  int i, child;
-  int *match, Nmatch, Nimage, Nsubset;
+  int child;
+  off_t i, *match, Nmatch, Nimage, Nsubset;
   FILE *f;
   RegImage *image, *subset;
Index: trunk/Ohana/src/imregister/src/photsearch.c
===================================================================
--- trunk/Ohana/src/imregister/src/photsearch.c	(revision 27392)
+++ trunk/Ohana/src/imregister/src/photsearch.c	(revision 27435)
@@ -6,6 +6,6 @@
 
   char *filename;
-  int Nmatch, Nphotpars;
-  int *match;
+  off_t Nmatch, Nphotpars;
+  off_t *match;
   FITS_DB db;
   PhotPars *photpars;
Index: trunk/Ohana/src/imregister/src/spsearch.c
===================================================================
--- trunk/Ohana/src/imregister/src/spsearch.c	(revision 27392)
+++ trunk/Ohana/src/imregister/src/spsearch.c	(revision 27435)
@@ -5,5 +5,5 @@
 int main (int argc, char **argv) {
  
-  int Nmatch, Nspectrum, *match;
+  off_t Nmatch, Nspectrum, *match;
   Spectrum *spectrum;
   FITS_DB db;
Index: trunk/Ohana/src/kapa2/src/Image.c
===================================================================
--- trunk/Ohana/src/kapa2/src/Image.c	(revision 27392)
+++ trunk/Ohana/src/kapa2/src/Image.c	(revision 27435)
@@ -11,5 +11,5 @@
 
   channel->coords.Npolyterms = 0;
-  channel->matrix.size = 0; /* a flag to show there is no data in the matrix */
+  channel->matrix.datasize = 0; /* a flag to show there is no data in the matrix */
   ALLOCATE (channel->matrix.buffer, char, 1);  /* allocate so later free will not crash! */
 
Index: trunk/Ohana/src/kapa2/src/LoadPicture.c
===================================================================
--- trunk/Ohana/src/kapa2/src/LoadPicture.c	(revision 27392)
+++ trunk/Ohana/src/kapa2/src/LoadPicture.c	(revision 27435)
@@ -5,5 +5,5 @@
   Header header;
   char *buff;
-  int status, bytes_left;
+  off_t status, bytes_left;
   Section *section;
   KapaImageWidget *image;
@@ -24,5 +24,5 @@
   Xoffset = 0.0;
   Yoffset = 0.0;
-  if (image[0].image[0].matrix.size) {
+  if (image[0].image[0].matrix.datasize) {
     // XXX enforce int center here?
     Xoffset = image[0].picture.Xc - 0.5*image[0].image[0].matrix.Naxis[0];
@@ -32,5 +32,5 @@
   gfits_init_header (&header);
   header.Naxes = 2;
-  KiiScanMessage (sock, "%d %d", &header.Naxis[0], &header.Naxis[1]);
+  KiiScanMessage (sock, "%lld %lld", (long long *) &header.Naxis[0], (long long *) &header.Naxis[1]);
 
   // internal image are 32 bit floats; sender must send in this format
@@ -41,5 +41,5 @@
 
   KiiScanMessage (sock, "%lf %lf %s %s",  &image[0].image[0].zero, &image[0].image[0].range, image[0].image[0].name, image[0].image[0].file);
-  KiiScanMessage (sock, "%lf %lf %d", &image[0].image[0].min,  &image[0].image[0].max, &header.size);
+  KiiScanMessage (sock, "%lf %lf %lld", &image[0].image[0].min,  &image[0].image[0].max, (long long *) &header.datasize);
   KiiScanMessage (sock, "%lf %f %f %f %f", &image[0].image[0].coords.crval1, &image[0].image[0].coords.crpix1, &image[0].image[0].coords.cdelt1, &image[0].image[0].coords.pc1_1, &image[0].image[0].coords.pc1_2);
   KiiScanMessage (sock, "%lf %f %f %f %f", &image[0].image[0].coords.crval2, &image[0].image[0].coords.crpix2, &image[0].image[0].coords.cdelt2, &image[0].image[0].coords.pc2_1, &image[0].image[0].coords.pc2_2);
@@ -67,6 +67,6 @@
   status = 1;
   buff = image[0].image[0].matrix.buffer;
-  bytes_left = header.size;
-  image[0].image[0].matrix.size = 0;
+  bytes_left = header.datasize;
+  image[0].image[0].matrix.datasize = 0;
   while (bytes_left > 0) {
     status = read (sock, buff, bytes_left);
@@ -77,5 +77,5 @@
     }
     if (status != -1) { /* pipe has data */
-      image[0].image[0].matrix.size += status;
+      image[0].image[0].matrix.datasize += status;
       bytes_left -= status;
       buff = (char *)(buff + status);
@@ -85,8 +85,8 @@
   fcntl (sock, F_SETFL, !O_NONBLOCK);  
 
-  if (DEBUG) fprintf (stderr, "read %d bytes\n", image[0].image[0].matrix.size);
-  /* it it not obvious this condition should kill kii, but ... */
-  if (image[0].image[0].matrix.size != header.size) {  
-    fprintf (stderr, "error: expected %d bytes, but got only %d\n", header.size, image[0].image[0].matrix.size);
+  if (DEBUG) fprintf (stderr, "read %lld bytes\n", (long long) image[0].image[0].matrix.datasize);
+  /* it it not obvious this condition should kill kapa, but ... */
+  if (image[0].image[0].matrix.datasize != header.datasize) {  
+    fprintf (stderr, "error: expected %lld bytes, but got only %lld\n", (long long) header.datasize, (long long) image[0].image[0].matrix.datasize);
     return (FALSE);
   }
Index: trunk/Ohana/src/kapa2/src/PNGit.c
===================================================================
--- trunk/Ohana/src/kapa2/src/PNGit.c	(revision 27392)
+++ trunk/Ohana/src/kapa2/src/PNGit.c	(revision 27435)
@@ -9,5 +9,4 @@
   int Npalette;
   char filename[1024];
-  int Nbytes, status;
   bDrawBuffer *buffer;
   Graphic *graphic;
Index: trunk/Ohana/src/kapa2/src/PPMit.c
===================================================================
--- trunk/Ohana/src/kapa2/src/PPMit.c	(revision 27392)
+++ trunk/Ohana/src/kapa2/src/PPMit.c	(revision 27435)
@@ -5,5 +5,5 @@
   FILE *f;
   char *line, filename[1024];
-  int Nbytes, status, dx, dy, i, j, Npalette, color;
+  int dx, dy, i, j, Npalette, color;
   png_color *palette;
   bDrawBuffer *buffer;
Index: trunk/Ohana/src/kapa2/src/Relocate.c
===================================================================
--- trunk/Ohana/src/kapa2/src/Relocate.c	(revision 27392)
+++ trunk/Ohana/src/kapa2/src/Relocate.c	(revision 27435)
@@ -4,8 +4,6 @@
 int Relocate (int sock) {
  
-  int i, Nsection;
   int x, y, dX, dY;
   Graphic *graphic;
-  Section *section;
 
   graphic = GetGraphic();
Index: trunk/Ohana/src/kapa2/src/SetImageData.c
===================================================================
--- trunk/Ohana/src/kapa2/src/SetImageData.c	(revision 27392)
+++ trunk/Ohana/src/kapa2/src/SetImageData.c	(revision 27435)
@@ -17,5 +17,5 @@
   
   // get image data from client 
-  KiiScanMessage (sock, "%lf %lf %s", 
+  KiiScanMessage (sock, "%lf %lf %s %s", 
 		  &image[0].image[0].zero, 
 		  &image[0].image[0].range, 
Index: trunk/Ohana/src/libautocode/def/autocode.c
===================================================================
--- trunk/Ohana/src/libautocode/def/autocode.c	(revision 27392)
+++ trunk/Ohana/src/libautocode/def/autocode.c	(revision 27435)
@@ -1,11 +1,11 @@
 # include "autocode.h"
 
-int gfits_convert_$STRUCT ($STRUCT *data, int size, int nitems) {
+int gfits_convert_$STRUCT ($STRUCT *data, off_t size, off_t nitems) {
 
-  int i;
+  off_t i;
   unsigned char *byte, tmp;
 
   if (size != $SIZE) { 
-    fprintf (stderr, "WARNING: mismatch in data types $STRUCT: %d vs %d\n", size, $SIZE);
+    fprintf (stderr, "WARNING: mismatch in data types $STRUCT: %lld vs %lld\n", (long long) size, (long long) $SIZE);
     return (FALSE);
   }
@@ -25,12 +25,12 @@
 } 
 
-$STRUCT *gfits_downsize_and_convert_$STRUCT ($STRUCT *data, int size, int nitems) {
+$STRUCT *gfits_downsize_and_convert_$STRUCT ($STRUCT *data, off_t size, off_t nitems) {
 
-  int i;
+  off_t i;
   unsigned char *byte, tmp;
   $STRUCT *output;
 
   if ($SIZE > size) { 
-    fprintf (stderr, "ERROR: uncorrectable mismatch in data types $STRUCT: %d vs %d\n", size, $SIZE);
+    fprintf (stderr, "ERROR: uncorrectable mismatch in data types $STRUCT: %lld vs %lld\n", (long long) size, (long long) $SIZE);
     exit (1);
   }
@@ -58,5 +58,5 @@
 /*** add test of EXTNAME and header-defined columns? ***/
 /* return internal structure representation */
-$STRUCT *gfits_table_get_$STRUCT (FTable *ftable, int *Ndata, int *swapped) {
+$STRUCT *gfits_table_get_$STRUCT (FTable *ftable, off_t *Ndata, char *swapped) {
 
   $STRUCT *data, *output;
@@ -68,5 +68,5 @@
       output = gfits_downsize_and_convert_$STRUCT (data, sizeof ($STRUCT), *Ndata);
       free (ftable[0].buffer);
-      ftable[0].buffer = output;
+      ftable[0].buffer = (char *) output;
       // XXX do I need to change NX?
     }
@@ -77,5 +77,5 @@
 }
 
-int gfits_table_set_$STRUCT (FTable *ftable, $STRUCT *data, int Ndata) {
+int gfits_table_set_$STRUCT (FTable *ftable, $STRUCT *data, off_t Ndata) {
 
   Header *header;
Index: trunk/Ohana/src/libautocode/def/autocode.h
===================================================================
--- trunk/Ohana/src/libautocode/def/autocode.h	(revision 27392)
+++ trunk/Ohana/src/libautocode/def/autocode.h	(revision 27435)
@@ -2,8 +2,8 @@
 /** STRUCT DEFINITION **/
 
-$STRUCT *gfits_table_get_$STRUCT (FTable *table, int *Ndata, int *swapped);
-int      gfits_table_set_$STRUCT (FTable *ftable, $STRUCT *data, int Ndata);
+$STRUCT *gfits_table_get_$STRUCT (FTable *table, off_t *Ndata, char *swapped);
+int      gfits_table_set_$STRUCT (FTable *ftable, $STRUCT *data, off_t Ndata);
 int      gfits_table_mkheader_$STRUCT (Header *header);
-int      gfits_convert_$STRUCT ($STRUCT *data, int size, int nitems);
-int Send_$STRUCT (int device, $STRUCT *data, int Ndata, int copy);
-int Recv_$STRUCT (int device, $STRUCT **data, int *Ndata);
+int      gfits_convert_$STRUCT ($STRUCT *data, off_t size, off_t nitems);
+int      Send_$STRUCT (int device, $STRUCT *data, int Ndata, int copy);
+int      Recv_$STRUCT (int device, $STRUCT **data, int *Ndata);
Index: trunk/Ohana/src/libdvo/include/dvo.h
===================================================================
--- trunk/Ohana/src/libdvo/include/dvo.h	(revision 27392)
+++ trunk/Ohana/src/libdvo/include/dvo.h	(revision 27435)
@@ -10,15 +10,16 @@
 
 /* DVO table formats */
-typedef enum {DVO_FORMAT_UNDEF, 
-	      DVO_FORMAT_INTERNAL, 
-	      DVO_FORMAT_ELIXIR, 
-	      DVO_FORMAT_LONEOS, 
-	      DVO_FORMAT_PANSTARRS_DEV_0,
-	      DVO_FORMAT_PANSTARRS_DEV_1,
-	      DVO_FORMAT_PS1_DEV_1,
-	      DVO_FORMAT_PS1_DEV_2,
-	      DVO_FORMAT_PS1_DEV_3,
-	      DVO_FORMAT_PS1_V1,
-	      DVO_FORMAT_PS1_REF
+typedef enum {
+  DVO_FORMAT_UNDEF, 
+  DVO_FORMAT_INTERNAL, 
+  DVO_FORMAT_ELIXIR, 
+  DVO_FORMAT_LONEOS, 
+  DVO_FORMAT_PANSTARRS_DEV_0,
+  DVO_FORMAT_PANSTARRS_DEV_1,
+  DVO_FORMAT_PS1_DEV_1,
+  DVO_FORMAT_PS1_DEV_2,
+  DVO_FORMAT_PS1_DEV_3,
+  DVO_FORMAT_PS1_V1,
+  DVO_FORMAT_PS1_REF
 } DVOTableFormat;
 
@@ -155,6 +156,4 @@
   FILE  *f;
   char  *filename;
-  int    dbstate;
-  int    lockstate;
   double timeout;
   Header header;
@@ -163,8 +162,10 @@
   FTable ftable;
   VTable vtable;
-  int    mode;          /* what data storage mode is used for disk file? */
-  int    format;        /* what data format is used for disk file? */
-  int    virtual;       /* is table in ftable or vtable? */
-  int    swapped;       /* is table in internal byte-order? */
+  int    dbstate;
+  char   lockstate;
+  char   mode;          /* what data storage mode is used for disk file? */
+  char   format;        /* what data format is used for disk file? */
+  char   virtual;       /* is table in ftable or vtable? */
+  char   swapped;       /* is table in internal byte-order? */
 } FITS_DB;
 
@@ -174,5 +175,5 @@
 /* SkyRegion : better implementation than GSCRegion */
 typedef struct {
-  int Nregions;
+  off_t Nregions;
   char **filename;
   SkyRegion *regions;
@@ -180,5 +181,5 @@
 
 typedef struct {
-  int Nregions;
+  off_t Nregions;
   int ownElements; 				  /* does this list own filename, regions? */
   char **filename;
@@ -187,13 +188,5 @@
 
 // special-case function:
-CMF_PS1_V2 *gfits_table_get_CMF_PS1_V1_Alt (FTable *ftable, int *Ndata, int *swapped);
-
-# if (0)
-/* structure for data on a catalog region */
-typedef struct {
-  char filename[256];
-  double DEC[2], RA[2];
-} GSCRegion;
-# endif
+CMF_PS1_V2 *gfits_table_get_CMF_PS1_V1_Alt (FTable *ftable, off_t *Ndata, char *swapped);
 
 typedef struct {
@@ -219,7 +212,9 @@
 
   int Nsecfilt;  /* number of secfilt entries for each average entry */
-  int Naverage,   Nmeasure,   Nmissing,   Nsecf_mem;  /* current number of each component in memory */
-  int Naves_disk, Nmeas_disk, Nmiss_disk, Nsecf_disk; /* current number of each component on disk */
-  int Naves_off,  Nmeas_off,  Nmiss_off,  Nsecf_off;  /* index of first loaded data value */
+  off_t Naverage,   Nmeasure,   Nmissing,   Nsecf_mem;  /* current number of each component in memory */
+  off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nsecf_disk; /* current number of each component on disk */
+  off_t Naves_off,  Nmeas_off,  Nmiss_off,  Nsecf_off;  /* index of first loaded data value */
+
+  /* the Nsecf_* values above are number of table rows (eg, Naverage*Nsecfilt) */
 
   /* note the different counting for Nsecfilt:
@@ -239,14 +234,14 @@
 
   /* extra catalog information */
-  int lockmode;
-  int catmode;				/* storage mode (raw, mef, split, mysql) */
-  int catformat;			/* storage format (elixir, panstarrs, etc) */
-  int catflags;				/* choices to be loaded */
-  int sorted;				/* is measure table average-sorted? */
+  char lockmode;
+  char catmode;				/* storage mode (raw, mef, split, mysql) */
+  char catformat;			/* storage format (elixir, panstarrs, etc) */
+  char catflags;				/* choices to be loaded */
+  char sorted;				/* is measure table average-sorted? */
   
   /* pointers for data manipulation */
-  int *found;
-  int *image;
-  int *mosaic;
+  off_t *found;
+  off_t *image;
+  off_t *mosaic;
   float *X;
   float *Y;
@@ -261,5 +256,5 @@
 int   gfits_db_lock                PROTO((FITS_DB *db, char *filename));
 int   gfits_db_load                PROTO((FITS_DB *db));
-int   gfits_db_load_segment        PROTO((FITS_DB *db, int start, int Nrows));
+int   gfits_db_load_segment        PROTO((FITS_DB *db, off_t start, off_t Nrows));
 int   gfits_db_save                PROTO((FITS_DB *db));
 int   gfits_db_update              PROTO((FITS_DB *db));
@@ -287,10 +282,10 @@
 
 int isRegisteredMosaic (void);
-int GetRegisteredMosaic (void);
+off_t GetRegisteredMosaic (void);
 int GetMosaicCoords (Coords *coords);
-int FindMosaicForImage (Image *images, int Nimages, int entry);
-int FindMosaicForImage_TableSearch (Image *images, int Nimages, int entry);
-int FindMosaicForImage_MatchSearch (Image *images, int Nimages, int entry);
-int BuildChipMatch (Image *images, int Nimages);
+int FindMosaicForImage (Image *images, off_t Nimages, off_t entry);
+int FindMosaicForImage_TableSearch (Image *images, off_t Nimages, off_t entry);
+int FindMosaicForImage_MatchSearch (Image *images, off_t Nimages, off_t entry);
+int BuildChipMatch (Image *images, off_t Nimages);
 void SetImageCorners (double *X, double *Y, Image *image);
 
@@ -347,13 +342,4 @@
 int get_image_mode (char *name);
 char *get_mode_name (int mode);
-
-/* these functions refer to the DVO structures defined in the includes above
- *  they are being replaced with autocode entries (drop when totally autocoded)
- */
-
-int   Fread (void *ptr, int size, int nitems, FILE *f, char *type);
-int   Fwrite (void *ptr, int size, int nitems, FILE *f, char *type);
-int   ByteSwap (char *ptr, int size, int nitems, char *type);
-int   ConvertStruct (char *buffer, int size, int Nbytes, char *type);
 
 /** dvo_catalog APIs */
@@ -384,25 +370,25 @@
 int dvo_catalog_save_split_complete (Catalog *catalog, char VERBOSE);
 
-int dvo_catalog_load_segment (Catalog *catalog, int VERBOSE, int start, int Nrows);
-int dvo_catalog_load_segment_split (Catalog *catalog, int VERBOSE, int start, int Nrows);
+int dvo_catalog_load_segment (Catalog *catalog, int VERBOSE, off_t start, off_t Nrows);
+int dvo_catalog_load_segment_split (Catalog *catalog, int VERBOSE, off_t start, off_t Nrows);
 
 /*** conversion functions / I/O conversions ***/
-Average *ReadRawAverage (FILE *f, int Naverage, int format, SecFilt **primary);
-Measure *ReadRawMeasure (FILE *f, int Nmeasure, int format);
-SecFilt *ReadRawSecFilt (FILE *f, int Nsecfilt, int format);
-int WriteRawAverage (FILE *f, Average *average, int Naverage, int format, SecFilt *primary);
-int WriteRawMeasure (FILE *f, Measure *measure, int Nmeasure, int format);
-int WriteRawSecFilt (FILE *f, SecFilt *secfilt, int Nsecfilt, int format);
-
-Average *FtableToAverage (FTable *ftable, int *Naverage, int *format, SecFilt **primary);
-Measure *FtableToMeasure (FTable *ftable, int *Nmeasure, int *format);
-SecFilt *FtableToSecFilt (FTable *ftable, int *Nsecfilt, int *format);
-int FtableToImage (FTable *ftable, Header *theader, int *format);
-
-int AverageToFtable (FTable *ftable, Average *average, int Naverage, int format, SecFilt *primary);
-int MeasureToFtable (FTable *ftable, Measure *measure, int Nmeasure, int format);
-int SecFiltToFtable (FTable *ftable, SecFilt *secfilt, int Nsecfilt, int format);
-int ImageToFtable (FTable *ftable, Header *theader, int format);
-int ImageToVtable (VTable *vtable, Header *theader, int format);
+Average *ReadRawAverage (FILE *f, off_t Naverage, char format, SecFilt **primary);
+Measure *ReadRawMeasure (FILE *f, off_t Nmeasure, char format);
+SecFilt *ReadRawSecFilt (FILE *f, off_t Nsecfilt, char format);
+int WriteRawAverage (FILE *f, Average *average, off_t Naverage, char format, SecFilt *primary);
+int WriteRawMeasure (FILE *f, Measure *measure, off_t Nmeasure, char format);
+int WriteRawSecFilt (FILE *f, SecFilt *secfilt, off_t Nsecfilt, char format);
+
+Average *FtableToAverage (FTable *ftable, off_t *Naverage, char *format, SecFilt **primary);
+Measure *FtableToMeasure (FTable *ftable, off_t *Nmeasure, char *format);
+SecFilt *FtableToSecFilt (FTable *ftable, off_t *Nsecfilt, char *format);
+int      FtableToImage   (FTable *ftable, Header *theader, char *format);
+
+int AverageToFtable (FTable *ftable, Average *average, off_t Naverage, char format, SecFilt *primary);
+int MeasureToFtable (FTable *ftable, Measure *measure, off_t Nmeasure, char format);
+int SecFiltToFtable (FTable *ftable, SecFilt *secfilt, off_t Nsecfilt, char format);
+int ImageToFtable (FTable *ftable, Header *theader, char format);
+int ImageToVtable (VTable *vtable, Header *theader, char format);
 
 # include "loneos_defs.h"
@@ -425,5 +411,5 @@
 int dvo_image_update_raw (FITS_DB *db, int VERBOSE);
 int dvo_image_save_raw (FITS_DB *db, int VERBOSE);
-int dvo_image_addrows (FITS_DB *db, Image *new, int Nnew);
+int dvo_image_addrows (FITS_DB *db, Image *new, off_t Nnew);
 void dvo_image_create (FITS_DB *db, double ZeroPoint);
 
@@ -454,8 +440,8 @@
 
 /* dvo-specific sorting functions */
-void sortave (Average *ave, int N);
-void sort_image_subset (Image *image, int *subset, int N);
-void sort_coords_index (double *X, double *Y, int *S, int N);
-void sort_regions (SkyRegion *region, int N);
+void sortave (Average *ave, off_t N);
+void sort_image_subset (Image *image, off_t *subset, off_t N);
+void sort_coords_index (double *X, double *Y, off_t *S, off_t N);
+void sort_regions (SkyRegion *region, off_t N);
 
 # endif
Index: trunk/Ohana/src/libdvo/include/dvo.update.h
===================================================================
--- trunk/Ohana/src/libdvo/include/dvo.update.h	(revision 27392)
+++ 	(revision )
@@ -1,399 +1,0 @@
-# include <ohana.h>
-# include <gfitsio.h>
-# include <autocode.h>
-
-# ifndef DVO_H
-# define DVO_H
-
-/*
-  # define ELIXIR 1
-  # define PANSTARRS 0
-  # define LONEOS 0
-*/
-
-/*** named data values (convert all to enums?) ***/
-
-/* DVO table modes */
-enum {DVO_MODE_UNDEF, DVO_MODE_RAW, DVO_MODE_MEF, DVO_MODE_SPLIT, DVO_MODE_MYSQL} DVOTableMode;
-
-/* DVO table formats */
-enum {DVO_FORMAT_UNDEF, DVO_FORMAT_INTERNAL, DVO_FORMAT_ELIXIR, DVO_FORMAT_LONEOS, DVO_FORMAT_PANSTARRS, DVO_FORMAT_PMTEST} DVOTableFormat;
-
-/* image data modes in RegImage */
-enum {T_UNDEF = -1, T_NONE, T_OBJECT, T_DARK, T_BIAS, T_FLAT, T_MASK, T_FRINGE, T_SCATTER, T_MODES, T_FRINGEPTS, T_ANY, N_TYPE};
-enum {M_UNDEF = -1, M_NONE, M_MEF, M_SPLIT, M_SINGLE, M_CUBE, M_SLICE, M_MODES, N_MODE};
-
-typedef enum {
-    PROJ_NONE, // undefined
-    PROJ_ZEA, // zenithal
-    PROJ_ZPL, // zenithal
-    PROJ_ARC, // zenithal
-    PROJ_STG, // zenithal
-    PROJ_SIN, // zenithal
-    PROJ_TAN, // zenithal
-    PROJ_DIS, // zenithal (TAN + polyterms)
-    PROJ_LIN, // cartesian
-    PROJ_PLY, // cartesian
-    PROJ_WRP, // cartesian
-    PROJ_AIT, // pseudocyl
-    PROJ_GLS, // pseudocyl
-    PROJ_PAR, // pseudocyl
-} OhanaProjections;
-
-typedef enum {
-  PROJ_MODE_NONE,
-  PROJ_MODE_CARTESIAN,
-  PROJ_MODE_ZENITHAL,
-  PROJ_MODE_PSEUDOCYL,
-} OhanaProjectionModes;
-
-/* RegImage.flag values */
-# define IMREG_DIST  0x01 /* image distributed, only imregister-3.0 */
-
-/* catalog values to be loaded */
-# define LOAD_AVES 	0x01
-# define LOAD_MEAS 	0x02
-# define LOAD_MISS 	0x04
-# define LOAD_SECF 	0x08 
-# define LOAD_MEAS_META 0x10
-
-/* invalid mag value */
-# define NO_MAG    0x7fff
-# define NO_ERR    0xff
-
-/* photometry code types */
-# define PHOT_PRI 0x01
-# define PHOT_SEC 0x02
-# define PHOT_DEP 0x03
-# define PHOT_REF 0x04
-# define PHOT_ALT 0x05  /* never stored, only for look-ups */
-
-/* Image.code values.  these are codes to note bad images */
-# define ID_IMAGE_NEW   0x0000  /* no nrphot attempted */
-# define ID_IMAGE_NOCAL 0x0001  /* used within nrphot to mean "don't apply fit" */
-# define ID_IMAGE_POOR  0x0002  /* relphot says image is bad */
-# define ID_IMAGE_SKIP  0x0004  /* external information image is bad */
-# define ID_IMAGE_FEW   0x0008  /* currently too few measurements for good value */
-
-/* Measure.flags values */
-# define ID_MEAS_NOCAL        0x0001
-# define ID_MEAS_POOR         0x0002
-# define ID_MEAS_SKIP         0x0004
-# define ID_MEAS_AREA         0x0008
-# define BLEND_IMAGE          0x0100 
-# define BLEND_CATALOG        0x0200
-# define BLEND_IMAGE_NEIGHBOR 0x1000
-# define ID_MEAS_TRAIL        0x2000
-# define ID_MEAS_GHOST        0x4000
-
-/* some subtle distinctions between the blend flags:
-   BLEND_IMAGE: the star on an image is matched with more 
-   than one star in the catalog (image has worse seeing than catalog)
-   BLEND_CATALOG: the star in the catalog is matched with more 
-   than one star on the image (image has better seeing than catalog)
-   CALIBRATED: relative photometry has been performed on this measurement
-   BLEND_IMAGE_NEIGHBOR: the star on an image is matched with more 
-   than one star in the catalog, but not in the same catalog file.
-*/
-
-/* Average.code values */
-# define ID_STAR_FEW   0x0001 /* used within relphot: skip star */
-# define ID_STAR_POOR  0x0002 /* used within relphot: skip star */
-# define ID_PROPER     0x0400 /* star with large proper motion */
-# define ID_TRANSIENT  0x1000 /* is this mutually exclusive with USNO?  */
-# define ID_VARIABLE   0x2000 /* not currently set? */
-# define ID_ASTEROID   0x2000 /* identified with an asteroid */
-# define ID_BAD_OBJECT 0x4000 /* if all measurements are bad, set this bit */
-# define ID_MOVING     0x8000
-# define ID_ROCK       0xa000 /* 0x8000 + 0x2000 */
-# define ID_GHOST      0xc001 /* 0x8000 + 0x4000 + 0x0001 */
-# define ID_TRAIL      0xc002 /* 0x8000 + 0x4000 + 0x0002 */
-# define ID_BLEED      0xc003 /* 0x8000 + 0x4000 + 0x0003 */ 
-# define ID_COSMIC     0xc004 /* 0x8000 + 0x4000 + 0x0004 */ 
-
-/*** general dvo structures (internal use only / not IO) ***/
-
-/* FITS DB structure */
-typedef struct {
-  FILE  *f;
-  char  *filename;
-  int    dbstate;
-  int    lockstate;
-  double timeout;
-  Header header;
-  Matrix matrix;
-  Header theader;
-  FTable ftable;
-  VTable vtable;
-  int    mode;          /* what data storage mode is used for disk file? */
-  int    format;        /* what data format is used for disk file? */
-  int    virtual;       /* is table in ftable or vtable? */
-  int    swapped;       /* is table in internal byte-order? */
-} FITS_DB;
-
-/* the basic HST GSC layout corresponds to a depth of 3 */
-# define SKY_DEPTH_HST 3
-
-/* SkyRegion : better implementation than GSCRegion */
-typedef struct {
-  int Nregions;
-  char **filename;
-  SkyRegion *regions;
-} SkyTable;
-
-typedef struct {
-  int Nregions;
-  char **filename;
-  SkyRegion **regions;
-} SkyList;
-
-# if (0)
-/* structure for data on a catalog region */
-typedef struct {
-  char filename[256];
-  double DEC[2], RA[2];
-} GSCRegion;
-# endif
-
-typedef struct {
-  int Ncode;
-  int Nsecfilt;
-  int hashcode[0x10000];
-  int hashNsec[0x10000];
-  PhotCode *code;
-} PhotCodeData;
-
-/* a catalog contains this data */
-typedef struct Catalog {
-  char *filename;			/* catalog file */
-  FILE *f;  				/* file descriptor */
-  Header  header;
-
-  /* data in the catalog file */
-  Average *average;
-  Measure *measure; 
-  Missing *missing; 
-  SecFilt *secfilt;
-  int Naverage, Nmeasure, Nmissing, Nsecfilt;   /* current number of each component */
-  int Nave_disk, Nmeas_disk, Nmiss_disk;        /* number of component on disk */
-  int Nmeas_off;			        /* dist seq of first loaded data value */
-  /* note the different counting for Nsecfilt */
-
-  /* pointers to split data files */
-  struct Catalog *measure_catalog;		/* measure catalog data (split) */
-  struct Catalog *missing_catalog;		/* missing catalog data (split) */
-  struct Catalog *secfilt_catalog;		/* secfilt catalog data (split) */
-
-  /* extra catalog information */
-  int lockmode;
-  int catmode;				/* storage mode (raw, mef, split, mysql) */
-  int catformat;			/* storage format (elixir, panstarrs, etc) */
-  int catflags;				/* choices to be loaded */
-  int sorted;				/* is measure table average-sorted? */
-  
-  /* pointers for data manipulation */
-  int *found;
-  int *image;
-  int *mosaic;
-  float *X;
-  float *Y;
-
-} Catalog;
-
-/*** prototypes ***/
-
-/* in gfits_db.c */
-int   gfits_db_init                PROTO((FITS_DB *db));
-int   gfits_db_create              PROTO((FITS_DB *db));
-int   gfits_db_lock                PROTO((FITS_DB *db, char *filename));
-int   gfits_db_load                PROTO((FITS_DB *db));
-int   gfits_db_load_segment        PROTO((FITS_DB *db, int start, int Nrows));
-int   gfits_db_save                PROTO((FITS_DB *db));
-int   gfits_db_update              PROTO((FITS_DB *db));
-int   gfits_db_close               PROTO((FITS_DB *db));
-int   gfits_db_free                PROTO((FITS_DB *db));
-
-/* in coords.c, using libautocode/def/coords.d */
-int  XY_to_RD (double *ra, double *dec, double x,  double y,   Coords *coords);
-int  RD_to_XY (double *x,  double *y,   double ra, double dec, Coords *coords);
-int  fXY_to_RD (float *ra, float *dec, double x,  double y,   Coords *coords);
-int  fRD_to_XY (float *x,  float *y,   double ra, double dec, Coords *coords);
-int  GetCoords (Coords *coords, Header *header);
-int  PutCoords (Coords *coords, Header *header);
-void RegisterMosaic (Coords *coords);
-void coords_precess (double *ra, double *dec, double in_epoch, double out_epoch);
-
-int FindMosaicForImage (Image *images, int Nimages, int entry);
-int FindMosaicForImage_TableSearch (Image *images, int Nimages, int entry);
-int FindMosaicForImage_MatchSearch (Image *images, int Nimages, int entry);
-int BuildChipMatch (Image *images, int Nimages);
-void SetImageCorners (double *X, double *Y, Image *image);
-
-short int putMi (double value);
-double getMi (short int value);
-void returnMcal (Image *image, double *c);
-void assignMcal (Image *image, double *c, int order);
-double applyMcal (Image *image, double x, double y);
-double findscatter (double *X, double *Y, double *M, double *dM, int N, double *c, int order);
-
-PhotCode *GetPhotcodebyName (char *name);
-PhotCode *GetPhotcodeEquivbyName (char *name);
-PhotCode *GetPhotcodebyCode (int code);
-PhotCode *GetPhotcodebyNsec (int Nsec);
-PhotCode *GetPhotcodeEquivbyCode (int code);
-char     *GetPhotcodeNamebyCode (int code);
-
-float PhotInst (Measure *measure);
-float PhotCat (Measure *measure);
-float PhotSys (Measure *measure, Average *average, SecFilt *secfilt);
-float PhotRel (Measure *measure, Average *average, SecFilt *secfilt);
-float PhotCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code);
-float PhotAve (PhotCode *code, Average *average, SecFilt *secfilt);
-float PhotRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure);
-float PhotXm (PhotCode *code, Average *average, SecFilt *secfilt);
-float PhotdM (PhotCode *code, Average *average, SecFilt *secfilt);
-
-# if (0)
-short iPhotInst (Measure *measure);
-short iPhotAbs (Measure *measure);
-short iPhotCat (Measure *measure);
-short iPhotSys (Measure *measure, Average *average, SecFilt *secfilt);
-short iPhotRel (Measure *measure, Average *average, SecFilt *secfilt);
-short iPhotCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code);
-short iPhotAve (PhotCode *code, Average *average, SecFilt *secfilt);
-short iPhotRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure);
-short iPhotXm (PhotCode *code, Average *average, SecFilt *secfilt);
-short iPhotdM (PhotCode *code, Average *average, SecFilt *secfilt);
-# endif
-
-float iPhotColor (Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code);
-int PhotColor (Average *average, SecFilt *secfilt, Measure *measure, int c1, int c2, double *color);
-
-int LoadPhotcodes (char *filename);
-int GetPhotcodeCodebyName (char *name);
-int GetPhotcodeEquivCodebyName (char *name);
-int GetPhotcodeEquivCodebyCode (int code);
-int GetPhotcodeNsec (int code);
-int GetPhotcodeNsecfilt (void);
-void SetZeroPoint (double ZP);
-int *GetPhotcodeEquivList (int code, int *nlist);
-void ParseColorTerms (char *terms, float *X, int *N);
-
-int get_image_type (char *name);
-char *get_type_name (int type);
-int get_image_mode (char *name);
-char *get_mode_name (int mode);
-
-/* these functions refer to the DVO structures defined in the includes above
- *  they are being replaced with autocode entries (drop when totally autocoded)
- */
-
-int   Fread (void *ptr, int size, int nitems, FILE *f, char *type);
-int   Fwrite (void *ptr, int size, int nitems, FILE *f, char *type);
-int   ByteSwap (char *ptr, int size, int nitems, char *type);
-int   ConvertStruct (char *buffer, int size, int Nbytes, char *type);
-
-/** dvo_catalog APIs */
-void dvo_catalog_init (Catalog *catalog, int complete);
-void dvo_catalog_create (SkyRegion *region, Catalog *catalog);
-void dvo_catalog_free (Catalog *catalog);
-int dvo_catalog_check (Catalog *catalog, int Nsecfilt, int extend);
-int dvo_catalog_lock (Catalog *catalog, int lockmode);
-int dvo_catalog_unlock (Catalog *catalog);
-int dvo_catalog_load (Catalog *catalog, int VERBOSE);
-int dvo_catalog_open (Catalog *catalog, SkyRegion *region, int VERBOSE, char *iomode);
-int dvo_catalog_save (Catalog *catalog, char VERBOSE);
-int dvo_catalog_update (Catalog *catalog, char VERBOSE);
-int dvo_catalog_catformat (char *catformat);
-int dvo_catalog_catmode (char *catmode);
-void dvo_catalog_test (Catalog *catalog, int halt);
-
-/* catmode-specific APIs */
-int dvo_catalog_load_raw (Catalog *catalog, int VERBOSE);
-int dvo_catalog_save_raw (Catalog *catalog, char VERBOSE);
-int dvo_catalog_load_mef (Catalog *catalog, int VERBOSE);
-int dvo_catalog_save_mef (Catalog *catalog, char VERBOSE);
-int dvo_catalog_load_split (Catalog *catalog, int VERBOSE);
-int dvo_catalog_save_split (Catalog *catalog, char VERBOSE);
-int dvo_catalog_update_split (Catalog *catalog, char VERBOSE);
-
-/*** conversion functions / I/O conversions ***/
-Average *ReadRawAverage (FILE *f, int Naverage, int format);
-Measure *ReadRawMeasure (FILE *f, int Nmeasure, int format);
-SecFilt *ReadRawSecFilt (FILE *f, int Nsecfilt, int format);
-int WriteRawAverage (FILE *f, Average *average, int Naverage, int format);
-int WriteRawMeasure (FILE *f, Measure *measure, int Nmeasure, int format);
-int WriteRawSecFilt (FILE *f, SecFilt *secfilt, int Nsecfilt, int format);
-
-Average *FtableToAverage (FTable *ftable, int *Naverage, int *format);
-Average *AverageLoneosToInternal (AverageLoneos *in, int Nvalues);
-Average *AverageElixirToInternal (AverageElixir *in, int Nvalues);
-Average *AveragePanstarrsToInternal (AveragePanstarrs *in, int Nvalues);
-Average *AveragePMtestToInternal (AveragePMtest *in, int Nvalues);
-AverageLoneos *AverageInternalToLoneos (Average *in, int Nvalues);
-AverageElixir *AverageInternalToElixir (Average *in, int Nvalues);
-AveragePanstarrs *AverageInternalToPanstarrs (Average *in, int Nvalues);
-AveragePMtest *AverageInternalToPMtest (Average *in, int Nvalues);
-
-Measure *FtableToMeasure (FTable *ftable, int *Nmeasure, int *format);
-Measure *MeasureLoneosToInternal (MeasureLoneos *in, int Nvalues);
-Measure *MeasureElixirToInternal (MeasureElixir *in, int Nvalues);
-Measure *MeasurePanstarrsToInternal (MeasurePanstarrs *in, int Nvalues);
-MeasureLoneos *MeasureInternalToLoneos (Measure *in, int Nvalues);
-MeasureElixir *MeasureInternalToElixir (Measure *in, int Nvalues);
-MeasurePanstarrs *MeasureInternalToPanstarrs (Measure *in, int Nvalues);
-
-SecFilt *FtableToSecFilt (FTable *ftable, int *Nsecfilt, int *format);
-SecFilt *SecFiltLoneosToInternal (SecFiltLoneos *in, int Nvalues);
-SecFilt *SecFiltElixirToInternal (SecFiltElixir *in, int Nvalues);
-SecFilt *SecFiltPanstarrsToInternal (SecFiltPanstarrs *in, int Nvalues);
-SecFiltLoneos *SecFiltInternalToLoneos (SecFilt *in, int Nvalues);
-SecFiltElixir *SecFiltInternalToElixir (SecFilt *in, int Nvalues);
-SecFiltPanstarrs *SecFiltInternalToPanstarrs (SecFilt *in, int Nvalues);
-
-int AverageToFtable (FTable *ftable, Average *average, int Naverage, int format);
-int MeasureToFtable (FTable *ftable, Measure *measure, int Nmeasure, int format);
-int SecFiltToFtable (FTable *ftable, SecFilt *secfilt, int Nsecfilt, int format);
-
-/*** DVO image db I/O Functions ***/
-int dvo_image_lock (FITS_DB *db, char *filename, double timeout, int lockstate);
-int dvo_image_unlock (FITS_DB *db);
-int dvo_image_load (FITS_DB *db, int VERBOSE, int FORCE_READ);
-int dvo_image_save (FITS_DB *db, int VERBOSE);
-int dvo_image_update (FITS_DB *db, int VERBOSE);
-int dvo_image_load_raw (FITS_DB *db, int VERBOSE, int FORCE_READ);
-int dvo_image_update_raw (FITS_DB *db, int VERBOSE);
-int dvo_image_save_raw (FITS_DB *db, int VERBOSE);
-int dvo_image_addrows (FITS_DB *db, Image *new, int Nnew);
-void dvo_image_create (FITS_DB *db, double ZeroPoint);
-
-int FtableToImage (FTable *ftable, Header *theader, int *format);
-int ImageToFtable (FTable *ftable, Header *theader, int format);
-int ImageToVtable (VTable *vtable, Header *theader, int format);
-Image *ImageElixirToInternal (ImageElixir *in, int Nvalues);
-ImageElixir *ImageInternalToElixir (Image *in, int Nvalues);
-Image *ImageLoneosToInternal (ImageLoneos *in, int Nvalues);
-ImageLoneos *ImageInternalToLoneos (Image *in, int Nvalues);
-Image *ImagePanstarrsToInternal (ImagePanstarrs *in, int Nvalues);
-ImagePanstarrs *ImageInternalToPanstarrs (Image *in, int Nvalues);
-
-/* skyregion APIs */
-int        SkyTableSave        	   PROTO((SkyTable *table, char *filename));
-SkyTable  *SkyTableLoad        	   PROTO((char *filename, int VERBOSE));
-SkyTable  *SkyTableFromGSC     	   PROTO((char *filename, int depth, int VERBOSE));
-SkyTable  *SkyTableLoadOptimal 	   PROTO((char *catdir, char *SKYFILE, char *GSCFILE, int depth, int VERBOSE));
-int        SkyTableSetDepth    	   PROTO((SkyTable *sky, int depth));
-SkyList   *SkyRegionByPoint    	   PROTO((SkyTable *table, int depth, double ra, double dec));
-SkyList   *SkyListByPoint      	   PROTO((SkyTable *table, double ra, double dec));
-SkyList   *SkyListByRadius     	   PROTO((SkyTable *table, int depth, double RA, double DEC, double radius));
-SkyList   *SkyListByPatch      	   PROTO((SkyTable *table, int depth, SkyRegion *patch));
-SkyList   *SkyListByName      	   PROTO((SkyTable *table, char *name));
-SkyList   *SkyListByImage      	   PROTO((SkyTable *table, int depth, Image *image));
-SkyList   *SkyListByBounds     	   PROTO((SkyTable *table, int depth, double Rmin, double Rmax, double Dmin, double Dmax));
-SkyList   *SkyListChildrenByBounds PROTO((SkyTable *table, int No, int depth, double Rmin, double Rmax, double Dmin, double Dmax));
-int        SkyListFree             PROTO((SkyList *list, int ELEMENTS));
-int        SkyTableFree            PROTO((SkyTable *table));
-int        SkyListSetFilenames     PROTO((SkyList *list, char *path, char *ext));
-int        SkyTableSetFilenames    PROTO((SkyTable *sky, char *path, char *ext));
-
-# endif
Index: trunk/Ohana/src/libdvo/include/dvo_util.h
===================================================================
--- trunk/Ohana/src/libdvo/include/dvo_util.h	(revision 27392)
+++ trunk/Ohana/src/libdvo/include/dvo_util.h	(revision 27435)
@@ -9,19 +9,19 @@
 
 typedef struct {
-    char        gscfile[256];
-    char        catdir[256];
-    char        catmode[256];
-    char        catformat[256];
-    char        photcodeFile[256];
-    char        skyTableFile[256];
-    int         skyDepth;
-    FITS_DB     imageDB;
-    Image       *images;
-    int         nImages;
-    SkyTable    *skyTable;
+  char        gscfile[256];
+  char        catdir[256];
+  char        catmode[256];
+  char        catformat[256];
+  char        photcodeFile[256];
+  char        skyTableFile[256];
+  int         skyDepth;
+  FITS_DB     imageDB;
+  Image      *images;
+  off_t       nImages;
+  SkyTable   *skyTable;
 #if (DVO_UTIL_READ_CAMERA_CONFIG)
-    char        cameraConfig[256];
-    int         *ccdNum;
-    int         nCCD;
+  char        cameraConfig[256];
+  int        *ccdNum;
+  int         nCCD;
 #endif
 } dvoConfig;
@@ -29,13 +29,13 @@
 // This structure needs to be fleshed out
 typedef struct {
-    int         valid;
-    Average     ave;
-    Measure     meas;
+  int         valid;
+  Average     ave;
+  Measure     meas;
 #ifdef notdef
-    int         objID;
-    int         catID;
-    int         detID;
-    uint64_t    pspsObjID;
-    uint64_t    pspsDetID;
+  int         objID;
+  int         catID;
+  int         detID;
+  uint64_t    pspsObjID;
+  uint64_t    pspsDetID;
 #endif
 } dvoDetection;
@@ -52,5 +52,5 @@
 dvoConfig *dvoConfigRead(int *argc, char **argv);
 
-// free's memory associated with the dvoConfig structure
+// frees memory associated with the dvoConfig structure
 void dvoConfigFree(dvoConfig *dvoConfig);
 
@@ -70,7 +70,7 @@
 SkyList *dvoSkyListByExternID(dvoConfig *dvoConfig, int sourceID, int externID, Image **ppImage);
 
-// return a list of detectsions from a particular image id
+// return a list of detections from a particular image id
 // Use dvoFree() to free the memory pointed to by results
-int dvoGetDetections(SkyList *skylist, int imageID, dvoDetection **results, int *pMaxDetID);
+off_t dvoGetDetections(SkyList *skylist, int imageID, dvoDetection **results, int *pMaxDetID);
 
 // free memory returned by various dvo util functions
Index: trunk/Ohana/src/libdvo/include/elixir_defs.h
===================================================================
--- trunk/Ohana/src/libdvo/include/elixir_defs.h	(revision 27392)
+++ trunk/Ohana/src/libdvo/include/elixir_defs.h	(revision 27435)
@@ -1,11 +1,11 @@
-Image 		       	*Image_Elixir_ToInternal (Image_Elixir *in, int Nvalues);
-Image_Elixir 	       	*ImageInternalTo_Elixir (Image *in, int Nvalues);
-Average 	       	*Average_Elixir_ToInternal (Average_Elixir *in, int Nvalues, SecFilt **primary);
-Average_Elixir 	        *AverageInternalTo_Elixir (Average *in, int Nvalues, SecFilt *primary);
-Measure 	       	*Measure_Elixir_ToInternal (Measure_Elixir *in, int Nvalues);
-Measure_Elixir 	        *MeasureInternalTo_Elixir (Measure *in, int Nvalues);
-SecFilt 	       	*SecFilt_Elixir_ToInternal (SecFilt_Elixir *in, int Nvalues);
-SecFilt_Elixir 	       	*SecFiltInternalTo_Elixir (SecFilt *in, int Nvalues);
+Image 		       	*Image_Elixir_ToInternal (Image_Elixir *in, off_t Nvalues);
+Image_Elixir 	       	*ImageInternalTo_Elixir (Image *in, off_t Nvalues);
+Average 	       	*Average_Elixir_ToInternal (Average_Elixir *in, off_t Nvalues, SecFilt **primary);
+Average_Elixir 	        *AverageInternalTo_Elixir (Average *in, off_t Nvalues, SecFilt *primary);
+Measure 	       	*Measure_Elixir_ToInternal (Measure_Elixir *in, off_t Nvalues);
+Measure_Elixir 	        *MeasureInternalTo_Elixir (Measure *in, off_t Nvalues);
+SecFilt 	       	*SecFilt_Elixir_ToInternal (SecFilt_Elixir *in, off_t Nvalues);
+SecFilt_Elixir 	       	*SecFiltInternalTo_Elixir (SecFilt *in, off_t Nvalues);
 
-PhotCode *PhotCode_Elixir_To_Internal (PhotCode_Elixir *in, int Nvalues);
-PhotCode_Elixir *PhotCode_Internal_To_Elixir (PhotCode *in, int Nvalues);
+PhotCode *PhotCode_Elixir_To_Internal (PhotCode_Elixir *in, off_t Nvalues);
+PhotCode_Elixir *PhotCode_Internal_To_Elixir (PhotCode *in, off_t Nvalues);
Index: trunk/Ohana/src/libdvo/include/loneos_defs.h
===================================================================
--- trunk/Ohana/src/libdvo/include/loneos_defs.h	(revision 27392)
+++ trunk/Ohana/src/libdvo/include/loneos_defs.h	(revision 27435)
@@ -1,8 +1,8 @@
-Image 		       	*Image_Loneos_ToInternal (Image_Loneos *in, int Nvalues);
-Image_Loneos 	       	*ImageInternalTo_Loneos (Image *in, int Nvalues);
-Average                	*Average_Loneos_ToInternal (Average_Loneos *in, int Nvalues, SecFilt **primary);
-Average_Loneos 	        *AverageInternalTo_Loneos (Average *in, int Nvalues, SecFilt *primary);
-Measure                	*Measure_Loneos_ToInternal (Measure_Loneos *in, int Nvalues);
-Measure_Loneos 	        *MeasureInternalTo_Loneos (Measure *in, int Nvalues);
-SecFilt 	       	*SecFilt_Loneos_ToInternal (SecFilt_Loneos *in, int Nvalues);
-SecFilt_Loneos 	       	*SecFiltInternalTo_Loneos (SecFilt *in, int Nvalues);
+Image 		       	*Image_Loneos_ToInternal (Image_Loneos *in, off_t Nvalues);
+Image_Loneos 	       	*ImageInternalTo_Loneos (Image *in, off_t Nvalues);
+Average                	*Average_Loneos_ToInternal (Average_Loneos *in, off_t Nvalues, SecFilt **primary);
+Average_Loneos 	        *AverageInternalTo_Loneos (Average *in, off_t Nvalues, SecFilt *primary);
+Measure                	*Measure_Loneos_ToInternal (Measure_Loneos *in, off_t Nvalues);
+Measure_Loneos 	        *MeasureInternalTo_Loneos (Measure *in, off_t Nvalues);
+SecFilt 	       	*SecFilt_Loneos_ToInternal (SecFilt_Loneos *in, off_t Nvalues);
+SecFilt_Loneos 	       	*SecFiltInternalTo_Loneos (SecFilt *in, off_t Nvalues);
Index: trunk/Ohana/src/libdvo/include/panstarrs_dev_0_defs.h
===================================================================
--- trunk/Ohana/src/libdvo/include/panstarrs_dev_0_defs.h	(revision 27392)
+++ trunk/Ohana/src/libdvo/include/panstarrs_dev_0_defs.h	(revision 27435)
@@ -1,8 +1,8 @@
-Image 		       	*Image_Panstarrs_DEV_0_ToInternal (Image_Panstarrs_DEV_0 *in, int Nvalues);
-Image_Panstarrs_DEV_0  	*ImageInternalTo_Panstarrs_DEV_0 (Image *in, int Nvalues);
-Average 	       	*Average_Panstarrs_DEV_0_ToInternal (Average_Panstarrs_DEV_0 *in, int Nvalues, SecFilt **primary);
-Average_Panstarrs_DEV_0 *AverageInternalTo_Panstarrs_DEV_0 (Average *in, int Nvalues, SecFilt *primary);
-Measure 	       	*Measure_Panstarrs_DEV_0_ToInternal (Measure_Panstarrs_DEV_0 *in, int Nvalues);
-Measure_Panstarrs_DEV_0 *MeasureInternalTo_Panstarrs_DEV_0 (Measure *in, int Nvalues);
-SecFilt 	       	*SecFilt_Panstarrs_DEV_0_ToInternal (SecFilt_Panstarrs_DEV_0 *in, int Nvalues);
-SecFilt_Panstarrs_DEV_0 *SecFiltInternalTo_Panstarrs_DEV_0 (SecFilt *in, int Nvalues);
+Image 		       	*Image_Panstarrs_DEV_0_ToInternal (Image_Panstarrs_DEV_0 *in, off_t Nvalues);
+Image_Panstarrs_DEV_0  	*ImageInternalTo_Panstarrs_DEV_0 (Image *in, off_t Nvalues);
+Average 	       	*Average_Panstarrs_DEV_0_ToInternal (Average_Panstarrs_DEV_0 *in, off_t Nvalues, SecFilt **primary);
+Average_Panstarrs_DEV_0 *AverageInternalTo_Panstarrs_DEV_0 (Average *in, off_t Nvalues, SecFilt *primary);
+Measure 	       	*Measure_Panstarrs_DEV_0_ToInternal (Measure_Panstarrs_DEV_0 *in, off_t Nvalues);
+Measure_Panstarrs_DEV_0 *MeasureInternalTo_Panstarrs_DEV_0 (Measure *in, off_t Nvalues);
+SecFilt 	       	*SecFilt_Panstarrs_DEV_0_ToInternal (SecFilt_Panstarrs_DEV_0 *in, off_t Nvalues);
+SecFilt_Panstarrs_DEV_0 *SecFiltInternalTo_Panstarrs_DEV_0 (SecFilt *in, off_t Nvalues);
Index: trunk/Ohana/src/libdvo/include/panstarrs_dev_1_defs.h
===================================================================
--- trunk/Ohana/src/libdvo/include/panstarrs_dev_1_defs.h	(revision 27392)
+++ trunk/Ohana/src/libdvo/include/panstarrs_dev_1_defs.h	(revision 27435)
@@ -1,8 +1,8 @@
-Image 		       	*Image_Panstarrs_DEV_1_ToInternal (Image_Panstarrs_DEV_1 *in, int Nvalues);
-Image_Panstarrs_DEV_1  	*ImageInternalTo_Panstarrs_DEV_1 (Image *in, int Nvalues);
-Average 	       	*Average_Panstarrs_DEV_1_ToInternal (Average_Panstarrs_DEV_1 *in, int Nvalues, SecFilt **primary);
-Average_Panstarrs_DEV_1 *AverageInternalTo_Panstarrs_DEV_1 (Average *in, int Nvalues, SecFilt *primary);
-Measure 	       	*Measure_Panstarrs_DEV_1_ToInternal (Measure_Panstarrs_DEV_1 *in, int Nvalues);
-Measure_Panstarrs_DEV_1 *MeasureInternalTo_Panstarrs_DEV_1 (Measure *in, int Nvalues);
-SecFilt 	       	*SecFilt_Panstarrs_DEV_1_ToInternal (SecFilt_Panstarrs_DEV_1 *in, int Nvalues);
-SecFilt_Panstarrs_DEV_1 *SecFiltInternalTo_Panstarrs_DEV_1 (SecFilt *in, int Nvalues);
+Image 		       	*Image_Panstarrs_DEV_1_ToInternal (Image_Panstarrs_DEV_1 *in, off_t Nvalues);
+Image_Panstarrs_DEV_1  	*ImageInternalTo_Panstarrs_DEV_1 (Image *in, off_t Nvalues);
+Average 	       	*Average_Panstarrs_DEV_1_ToInternal (Average_Panstarrs_DEV_1 *in, off_t Nvalues, SecFilt **primary);
+Average_Panstarrs_DEV_1 *AverageInternalTo_Panstarrs_DEV_1 (Average *in, off_t Nvalues, SecFilt *primary);
+Measure 	       	*Measure_Panstarrs_DEV_1_ToInternal (Measure_Panstarrs_DEV_1 *in, off_t Nvalues);
+Measure_Panstarrs_DEV_1 *MeasureInternalTo_Panstarrs_DEV_1 (Measure *in, off_t Nvalues);
+SecFilt 	       	*SecFilt_Panstarrs_DEV_1_ToInternal (SecFilt_Panstarrs_DEV_1 *in, off_t Nvalues);
+SecFilt_Panstarrs_DEV_1 *SecFiltInternalTo_Panstarrs_DEV_1 (SecFilt *in, off_t Nvalues);
Index: trunk/Ohana/src/libdvo/include/ps1_dev_1_defs.h
===================================================================
--- trunk/Ohana/src/libdvo/include/ps1_dev_1_defs.h	(revision 27392)
+++ trunk/Ohana/src/libdvo/include/ps1_dev_1_defs.h	(revision 27435)
@@ -1,11 +1,11 @@
-Image 		       	*Image_PS1_DEV_1_ToInternal (Image_PS1_DEV_1 *in, int Nvalues);
-Image_PS1_DEV_1  	*ImageInternalTo_PS1_DEV_1 (Image *in, int Nvalues);
-Average 	       	*Average_PS1_DEV_1_ToInternal (Average_PS1_DEV_1 *in, int Nvalues, SecFilt **primary);
-Average_PS1_DEV_1       *AverageInternalTo_PS1_DEV_1 (Average *in, int Nvalues, SecFilt *primary);
-Measure 	       	*Measure_PS1_DEV_1_ToInternal (Measure_PS1_DEV_1 *in, int Nvalues);
-Measure_PS1_DEV_1       *MeasureInternalTo_PS1_DEV_1 (Measure *in, int Nvalues);
-SecFilt 	       	*SecFilt_PS1_DEV_1_ToInternal (SecFilt_PS1_DEV_1 *in, int Nvalues);
-SecFilt_PS1_DEV_1       *SecFiltInternalTo_PS1_DEV_1 (SecFilt *in, int Nvalues);
+Image 		       	*Image_PS1_DEV_1_ToInternal (Image_PS1_DEV_1 *in, off_t Nvalues);
+Image_PS1_DEV_1  	*ImageInternalTo_PS1_DEV_1 (Image *in, off_t Nvalues);
+Average 	       	*Average_PS1_DEV_1_ToInternal (Average_PS1_DEV_1 *in, off_t Nvalues, SecFilt **primary);
+Average_PS1_DEV_1       *AverageInternalTo_PS1_DEV_1 (Average *in, off_t Nvalues, SecFilt *primary);
+Measure 	       	*Measure_PS1_DEV_1_ToInternal (Measure_PS1_DEV_1 *in, off_t Nvalues);
+Measure_PS1_DEV_1       *MeasureInternalTo_PS1_DEV_1 (Measure *in, off_t Nvalues);
+SecFilt 	       	*SecFilt_PS1_DEV_1_ToInternal (SecFilt_PS1_DEV_1 *in, off_t Nvalues);
+SecFilt_PS1_DEV_1       *SecFiltInternalTo_PS1_DEV_1 (SecFilt *in, off_t Nvalues);
 
-PhotCode *PhotCode_PS1_DEV_1_To_Internal (PhotCode_PS1_DEV_1 *in, int Nvalues);
-PhotCode_PS1_DEV_1 *PhotCode_Internal_To_PS1_DEV_1 (PhotCode *in, int Nvalues);
+PhotCode *PhotCode_PS1_DEV_1_To_Internal (PhotCode_PS1_DEV_1 *in, off_t Nvalues);
+PhotCode_PS1_DEV_1 *PhotCode_Internal_To_PS1_DEV_1 (PhotCode *in, off_t Nvalues);
Index: trunk/Ohana/src/libdvo/include/ps1_dev_2_defs.h
===================================================================
--- trunk/Ohana/src/libdvo/include/ps1_dev_2_defs.h	(revision 27392)
+++ trunk/Ohana/src/libdvo/include/ps1_dev_2_defs.h	(revision 27435)
@@ -1,11 +1,11 @@
-Image 		       	*Image_PS1_DEV_2_ToInternal (Image_PS1_DEV_2 *in, int Nvalues);
-Image_PS1_DEV_2  	*ImageInternalTo_PS1_DEV_2 (Image *in, int Nvalues);
-Average 	       	*Average_PS1_DEV_2_ToInternal (Average_PS1_DEV_2 *in, int Nvalues, SecFilt **primary);
-Average_PS1_DEV_2       *AverageInternalTo_PS1_DEV_2 (Average *in, int Nvalues, SecFilt *primary);
-Measure 	       	*Measure_PS1_DEV_2_ToInternal (Measure_PS1_DEV_2 *in, int Nvalues);
-Measure_PS1_DEV_2       *MeasureInternalTo_PS1_DEV_2 (Measure *in, int Nvalues);
-SecFilt 	       	*SecFilt_PS1_DEV_2_ToInternal (SecFilt_PS1_DEV_2 *in, int Nvalues);
-SecFilt_PS1_DEV_2       *SecFiltInternalTo_PS1_DEV_2 (SecFilt *in, int Nvalues);
+Image 		       	*Image_PS1_DEV_2_ToInternal (Image_PS1_DEV_2 *in, off_t Nvalues);
+Image_PS1_DEV_2  	*ImageInternalTo_PS1_DEV_2 (Image *in, off_t Nvalues);
+Average 	       	*Average_PS1_DEV_2_ToInternal (Average_PS1_DEV_2 *in, off_t Nvalues, SecFilt **primary);
+Average_PS1_DEV_2       *AverageInternalTo_PS1_DEV_2 (Average *in, off_t Nvalues, SecFilt *primary);
+Measure 	       	*Measure_PS1_DEV_2_ToInternal (Measure_PS1_DEV_2 *in, off_t Nvalues);
+Measure_PS1_DEV_2       *MeasureInternalTo_PS1_DEV_2 (Measure *in, off_t Nvalues);
+SecFilt 	       	*SecFilt_PS1_DEV_2_ToInternal (SecFilt_PS1_DEV_2 *in, off_t Nvalues);
+SecFilt_PS1_DEV_2       *SecFiltInternalTo_PS1_DEV_2 (SecFilt *in, off_t Nvalues);
 
-PhotCode *PhotCode_PS1_DEV_2_To_Internal (PhotCode_PS1_DEV_2 *in, int Nvalues);
-PhotCode_PS1_DEV_2 *PhotCode_Internal_To_PS1_DEV_2 (PhotCode *in, int Nvalues);
+PhotCode *PhotCode_PS1_DEV_2_To_Internal (PhotCode_PS1_DEV_2 *in, off_t Nvalues);
+PhotCode_PS1_DEV_2 *PhotCode_Internal_To_PS1_DEV_2 (PhotCode *in, off_t Nvalues);
Index: trunk/Ohana/src/libdvo/include/ps1_dev_3_defs.h
===================================================================
--- trunk/Ohana/src/libdvo/include/ps1_dev_3_defs.h	(revision 27392)
+++ trunk/Ohana/src/libdvo/include/ps1_dev_3_defs.h	(revision 27435)
@@ -1,5 +1,5 @@
-Image 		       	*Image_PS1_DEV_3_ToInternal (Image_PS1_DEV_3 *in, int Nvalues);
-Image_PS1_DEV_3  	*ImageInternalTo_PS1_DEV_3 (Image *in, int Nvalues);
+Image 		       	*Image_PS1_DEV_3_ToInternal (Image_PS1_DEV_3 *in, off_t Nvalues);
+Image_PS1_DEV_3  	*ImageInternalTo_PS1_DEV_3 (Image *in, off_t Nvalues);
 
-PhotCode *PhotCode_PS1_DEV_3_To_Internal (PhotCode_PS1_DEV_3 *in, int Nvalues);
-PhotCode_PS1_DEV_3 *PhotCode_Internal_To_PS1_DEV_3 (PhotCode *in, int Nvalues);
+PhotCode *PhotCode_PS1_DEV_3_To_Internal (PhotCode_PS1_DEV_3 *in, off_t Nvalues);
+PhotCode_PS1_DEV_3 *PhotCode_Internal_To_PS1_DEV_3 (PhotCode *in, off_t Nvalues);
Index: trunk/Ohana/src/libdvo/include/ps1_ref_defs.h
===================================================================
--- trunk/Ohana/src/libdvo/include/ps1_ref_defs.h	(revision 27392)
+++ trunk/Ohana/src/libdvo/include/ps1_ref_defs.h	(revision 27435)
@@ -1,11 +1,11 @@
-Image 		       	*Image_PS1_REF_ToInternal (Image_PS1_REF *in, int Nvalues);
-Image_PS1_REF    	*ImageInternalTo_PS1_REF (Image *in, int Nvalues);
-Average 	       	*Average_PS1_REF_ToInternal (Average_PS1_REF *in, int Nvalues, SecFilt **primary);
-Average_PS1_REF          *AverageInternalTo_PS1_REF (Average *in, int Nvalues, SecFilt *primary);
-Measure 	       	*Measure_PS1_REF_ToInternal (Measure_PS1_REF *in, int Nvalues);
-Measure_PS1_REF          *MeasureInternalTo_PS1_REF (Measure *in, int Nvalues);
-SecFilt 	       	*SecFilt_PS1_REF_ToInternal (SecFilt_PS1_REF *in, int Nvalues);
-SecFilt_PS1_REF          *SecFiltInternalTo_PS1_REF (SecFilt *in, int Nvalues);
+Image 		       	*Image_PS1_REF_ToInternal (Image_PS1_REF *in, off_t Nvalues);
+Image_PS1_REF    	*ImageInternalTo_PS1_REF (Image *in, off_t Nvalues);
+Average 	       	*Average_PS1_REF_ToInternal (Average_PS1_REF *in, off_t Nvalues, SecFilt **primary);
+Average_PS1_REF          *AverageInternalTo_PS1_REF (Average *in, off_t Nvalues, SecFilt *primary);
+Measure 	       	*Measure_PS1_REF_ToInternal (Measure_PS1_REF *in, off_t Nvalues);
+Measure_PS1_REF          *MeasureInternalTo_PS1_REF (Measure *in, off_t Nvalues);
+SecFilt 	       	*SecFilt_PS1_REF_ToInternal (SecFilt_PS1_REF *in, off_t Nvalues);
+SecFilt_PS1_REF          *SecFiltInternalTo_PS1_REF (SecFilt *in, off_t Nvalues);
 
-PhotCode                *PhotCode_PS1_REF_To_Internal (PhotCode_PS1_REF *in, int Nvalues);
-PhotCode_PS1_REF         *PhotCode_Internal_To_PS1_REF (PhotCode *in, int Nvalues);
+PhotCode                *PhotCode_PS1_REF_To_Internal (PhotCode_PS1_REF *in, off_t Nvalues);
+PhotCode_PS1_REF         *PhotCode_Internal_To_PS1_REF (PhotCode *in, off_t Nvalues);
Index: trunk/Ohana/src/libdvo/include/ps1_v1_defs.h
===================================================================
--- trunk/Ohana/src/libdvo/include/ps1_v1_defs.h	(revision 27392)
+++ trunk/Ohana/src/libdvo/include/ps1_v1_defs.h	(revision 27435)
@@ -1,11 +1,11 @@
-Image 		       	*Image_PS1_V1_ToInternal (Image_PS1_V1 *in, int Nvalues);
-Image_PS1_V1    	*ImageInternalTo_PS1_V1 (Image *in, int Nvalues);
-Average 	       	*Average_PS1_V1_ToInternal (Average_PS1_V1 *in, int Nvalues, SecFilt **primary);
-Average_PS1_V1          *AverageInternalTo_PS1_V1 (Average *in, int Nvalues, SecFilt *primary);
-Measure 	       	*Measure_PS1_V1_ToInternal (Measure_PS1_V1 *in, int Nvalues);
-Measure_PS1_V1          *MeasureInternalTo_PS1_V1 (Measure *in, int Nvalues);
-SecFilt 	       	*SecFilt_PS1_V1_ToInternal (SecFilt_PS1_V1 *in, int Nvalues);
-SecFilt_PS1_V1          *SecFiltInternalTo_PS1_V1 (SecFilt *in, int Nvalues);
+Image 		       	*Image_PS1_V1_ToInternal (Image_PS1_V1 *in, off_t Nvalues);
+Image_PS1_V1    	*ImageInternalTo_PS1_V1 (Image *in, off_t Nvalues);
+Average 	       	*Average_PS1_V1_ToInternal (Average_PS1_V1 *in, off_t Nvalues, SecFilt **primary);
+Average_PS1_V1          *AverageInternalTo_PS1_V1 (Average *in, off_t Nvalues, SecFilt *primary);
+Measure 	       	*Measure_PS1_V1_ToInternal (Measure_PS1_V1 *in, off_t Nvalues);
+Measure_PS1_V1          *MeasureInternalTo_PS1_V1 (Measure *in, off_t Nvalues);
+SecFilt 	       	*SecFilt_PS1_V1_ToInternal (SecFilt_PS1_V1 *in, off_t Nvalues);
+SecFilt_PS1_V1          *SecFiltInternalTo_PS1_V1 (SecFilt *in, off_t Nvalues);
 
-PhotCode                *PhotCode_PS1_V1_To_Internal (PhotCode_PS1_V1 *in, int Nvalues);
-PhotCode_PS1_V1         *PhotCode_Internal_To_PS1_V1 (PhotCode *in, int Nvalues);
+PhotCode                *PhotCode_PS1_V1_To_Internal (PhotCode_PS1_V1 *in, off_t Nvalues);
+PhotCode_PS1_V1         *PhotCode_Internal_To_PS1_V1 (PhotCode *in, off_t Nvalues);
Index: trunk/Ohana/src/libdvo/src/LoadPhotcodesFITS.c
===================================================================
--- trunk/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 27435)
@@ -11,5 +11,6 @@
   char extname[80];
 
-  int i, code, Ncode, Nsec, Nsecfilt;
+  int i, code, Nsec, Nsecfilt;
+  off_t Ncode;
 
   /* XXX choose more sensible lock timeouts! */
Index: trunk/Ohana/src/libdvo/src/cmf-ps1-v1-alt.c
===================================================================
--- trunk/Ohana/src/libdvo/src/cmf-ps1-v1-alt.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/cmf-ps1-v1-alt.c	(revision 27435)
@@ -1,7 +1,7 @@
 # include "dvo.h"
 
-CMF_PS1_V2 *gfits_table_get_CMF_PS1_V1_Alt (FTable *ftable, int *Ndata, int *swapped) {
+CMF_PS1_V2 *gfits_table_get_CMF_PS1_V1_Alt (FTable *ftable, off_t *Ndata, char *swapped) {
 
-  int i, nitems;
+  off_t i, nitems;
   unsigned char *byte, *inbyte, *otbyte, tmp;
   CMF_PS1_V2 *output;
@@ -13,5 +13,5 @@
   // this function is a special case : it must have Nx = 136
   if (ftable[0].header[0].Naxis[0] != 136) { 
-    fprintf (stderr, "ERROR: wrong format for CMF_PS1_V1_Alt: %d vs %d\n", ftable[0].header[0].Naxis[0], 136);
+    fprintf (stderr, "ERROR: wrong format for CMF_PS1_V1_Alt: %lld vs %d\n", (long long) ftable[0].header[0].Naxis[0], 136);
     exit (2);
   }
@@ -83,5 +83,5 @@
 
   free (ftable[0].buffer);
-  ftable[0].buffer = output;
+  ftable[0].buffer = (char *) output;
 
   // XXX other mods to make ftable consistent with CMF_PS1_V2? (Nx, EXTNAME?)
Index: trunk/Ohana/src/libdvo/src/coordops.c
===================================================================
--- trunk/Ohana/src/libdvo/src/coordops.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/coordops.c	(revision 27435)
@@ -307,5 +307,5 @@
   int i;
   double Ro, Xo, Yo;
-  double dX, dY, X, Y, Lo, Mo, dL, dM;
+  double dX, dY, Lo, Mo, dL, dM;
   double dLdX, dLdY, dMdX, dMdY, Do;
 
Index: trunk/Ohana/src/libdvo/src/dvo_catalog.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_catalog.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_catalog.c	(revision 27435)
@@ -141,5 +141,5 @@
   if (catalog[0].f == NULL)   return (DVO_CAT_OPEN_FAIL);
 
-  fseek (catalog[0].f, 0, SEEK_SET);
+  fseeko (catalog[0].f, 0, SEEK_SET);
   return (DVO_CAT_OPEN_OK);
 }
@@ -253,5 +253,5 @@
   }
   // check if the table has been sorted or not 
-  status = gfits_scan (&catalog[0].header, "SORTED", "%t", 1, &catalog[0].sorted);
+  status = gfits_scan_alt (&catalog[0].header, "SORTED", "%t", 1, &catalog[0].sorted);
   if (!status) catalog[0].sorted = TRUE;
 
@@ -302,5 +302,5 @@
 
   // set the 'sorted' header keyword
-  gfits_modify (&catalog[0].header, "SORTED",  "%t", 1, catalog[0].sorted);
+  gfits_modify_alt (&catalog[0].header, "SORTED",  "%t", 1, catalog[0].sorted);
 
   // XXX handle return status
@@ -327,5 +327,5 @@
 
   // set the 'sorted' header keyword
-  gfits_modify (&catalog[0].header, "SORTED",  "%t", 1, catalog[0].sorted);
+  gfits_modify_alt (&catalog[0].header, "SORTED",  "%t", 1, catalog[0].sorted);
 
   // XXX handle return status
@@ -353,5 +353,5 @@
   // set the 'sorted' header keyword
   catalog[0].sorted = FALSE;
-  gfits_modify (&catalog[0].header, "SORTED",  "%t", 1, catalog[0].sorted);
+  gfits_modify_alt (&catalog[0].header, "SORTED",  "%t", 1, catalog[0].sorted);
 
   /* update is only valid for catmode SPLIT */
@@ -376,5 +376,6 @@
 int dvo_catalog_check (Catalog *catalog, int Nsecfilt, int extend) {
 
-  int i, j, Nextra, in, out;
+  off_t in, out, i;
+  int j, Nextra;
   SecFilt *insec, *outsec;
 
@@ -409,5 +410,25 @@
 
 void dvo_catalog_free (Catalog *catalog) {
+
+  if (catalog[0].catmode == DVO_MODE_SPLIT) {
+
+    if (catalog[0].measure_catalog) {
+      free (catalog[0].measure_catalog[0].filename);
+      dvo_catalog_free (catalog[0].measure_catalog);
+      free (catalog[0].measure_catalog);
+    }
+    if (catalog[0].missing_catalog) {
+      free (catalog[0].missing_catalog[0].filename);
+      dvo_catalog_free (catalog[0].missing_catalog);
+      free (catalog[0].missing_catalog);
+    }
+    if (catalog[0].secfilt_catalog) {
+      free (catalog[0].secfilt_catalog[0].filename);
+      dvo_catalog_free (catalog[0].secfilt_catalog);
+      free (catalog[0].secfilt_catalog);
+    }
+  }
   dvo_catalog_free_data (catalog);
+
   gfits_free_header (&catalog[0].header);
 }
@@ -444,5 +465,5 @@
 */
 
-int dvo_catalog_load_segment (Catalog *catalog, int VERBOSE, int start, int Nrows) {
+int dvo_catalog_load_segment (Catalog *catalog, int VERBOSE, off_t start, off_t Nrows) {
 
   switch (catalog[0].catmode) {
Index: trunk/Ohana/src/libdvo/src/dvo_catalog_create.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_catalog_create.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_catalog_create.c	(revision 27435)
@@ -27,5 +27,5 @@
   }
   gfits_create_header (&catalog[0].header);
-  
+
   if (catalog[0].catmode == DVO_MODE_SPLIT) {
     path = pathname (catalog[0].filename);
@@ -39,5 +39,7 @@
     /* create basic data for measure catalog file */
     gfits_create_header (&catalog[0].measure_catalog[0].header);
+
     ALLOCATE (catalog[0].measure_catalog[0].filename, char, length);
+
     sprintf (catalog[0].measure_catalog[0].filename, "%s/%s.cpm", path, root);
     file = filebasename (catalog[0].measure_catalog[0].filename);
@@ -85,5 +87,4 @@
       exit (2);
     }
-
   }    
 
Index: trunk/Ohana/src/libdvo/src/dvo_catalog_mef.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_catalog_mef.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_catalog_mef.c	(revision 27435)
@@ -3,5 +3,6 @@
 int dvo_catalog_load_mef (Catalog *catalog, int VERBOSE) {
   
-  int Nitems, Nbytes, Nexpect, Naverage, Nmeasure, Nmissing, Nsecfilt;
+  int Nsecfilt;
+  off_t Nitems, Nbytes, Nexpect, Naverage, Nmeasure, Nmissing;
   FILE *f;
 
@@ -15,5 +16,5 @@
 
   /* move pointer past header -- must be already read (load_catalog) */
-  fseek (f, catalog[0].header.size, SEEK_SET);
+  fseeko (f, catalog[0].header.datasize, SEEK_SET);
 
   /* matrix should be empty */
@@ -23,8 +24,8 @@
   }
   /* get the components from the header */
-  if (!gfits_scan (&catalog[0].header, "NSTARS",   "%d", 1, &Naverage)) return (FALSE);
-  if (!gfits_scan (&catalog[0].header, "NMEAS",    "%d", 1, &Nmeasure)) return (FALSE);
-  if (!gfits_scan (&catalog[0].header, "NMISS",    "%d", 1, &Nmissing)) return (FALSE);
-  if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d", 1, &Nsecfilt)) Nsecfilt = 0;
+  if (!gfits_scan (&catalog[0].header, "NSTARS",   "%lld", 1, (long long *) &Naverage)) return (FALSE);
+  if (!gfits_scan (&catalog[0].header, "NMEAS",    "%lld", 1, (long long *) &Nmeasure)) return (FALSE);
+  if (!gfits_scan (&catalog[0].header, "NMISS",    "%lld", 1, (long long *) &Nmissing)) return (FALSE);
+  if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d",   1,               &Nsecfilt)) Nsecfilt = 0;
 
   /* the OBJID is a counter that uniquely defines an average entry and never changes.  if
@@ -72,5 +73,5 @@
     catalog[0].average = FtableToAverage (&ftable, &Naverage, &catalog[0].catformat, &primary);
     if (Naverage != catalog[0].Naves_disk) {
-      fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers (%d vs %d)\n", Naverage, catalog[0].Naves_disk);
+      fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers (%lld vs %lld)\n", (long long) Naverage, (long long) catalog[0].Naves_disk);
     }
     catalog[0].Naverage = catalog[0].Naves_disk;
@@ -78,5 +79,5 @@
   } else {
     Nbytes = gfits_data_size (&header);
-    fseek (f, Nbytes, SEEK_CUR);
+    fseeko (f, Nbytes, SEEK_CUR);
     ALLOCATE (catalog[0].average, Average, 1);
     catalog[0].Naverage = 0;
@@ -99,5 +100,5 @@
     catalog[0].measure = FtableToMeasure (&ftable, &catalog[0].Nmeasure, &catalog[0].catformat);
     if (Nmeasure != catalog[0].Nmeas_disk) {
-      fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%d vs %d)\n", Nmeasure, catalog[0].Nmeas_disk);
+      fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%lld vs %lld)\n", (long long) Nmeasure, (long long) catalog[0].Nmeas_disk);
     }
     catalog[0].Nmeasure = catalog[0].Nmeas_disk;
@@ -105,5 +106,5 @@
   } else {
     Nbytes = gfits_data_size (&header);
-    fseek (f, Nbytes, SEEK_CUR);
+    fseeko (f, Nbytes, SEEK_CUR);
     ALLOCATE (catalog[0].measure, Measure, 1);
     catalog[0].Nmeasure = 0;
@@ -125,5 +126,5 @@
     catalog[0].missing = gfits_table_get_Missing (&ftable, &catalog[0].Nmissing, NULL);
     if (Nmissing != catalog[0].Nmiss_disk) {
-      fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%d vs %d)\n", Nmissing, catalog[0].Nmiss_disk);
+      fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%lld vs %lld)\n", (long long) Nmissing, (long long) catalog[0].Nmiss_disk);
     }
     catalog[0].Nmissing = catalog[0].Nmiss_disk;
@@ -131,5 +132,5 @@
   } else {
     Nbytes = gfits_data_size (&header);
-    fseek (f, Nbytes, SEEK_CUR);
+    fseeko (f, Nbytes, SEEK_CUR);
     ALLOCATE (catalog[0].missing, Missing, 1);
     catalog[0].Nmissing = 0;
@@ -153,5 +154,5 @@
     catalog[0].secfilt = FtableToSecFilt (&ftable, &Nitems, &catalog[0].catformat);
     if (Nexpect != Nitems) {
-      fprintf (stderr, "Warning: mismatch between Nsecfilt items in PHU and Table headers (%d vs %d)\n", Nexpect, Nitems);
+      fprintf (stderr, "Warning: mismatch between Nsecfilt items in PHU and Table headers (%lld vs %lld)\n", (long long) Nexpect, (long long) Nitems);
     }
 
@@ -159,5 +160,5 @@
        we need to interleave these magnitudes with the secfilt entries just loaded */
     if (primary != NULL) {
-      int Ntmpfilt, Ntotal, i, j;
+      off_t Ntmpfilt, Ntotal, i, j;
       SecFilt *tmpfilt;
       tmpfilt  = catalog[0].secfilt;
@@ -182,5 +183,5 @@
     /* no real need to skip the data array here... */
     Nbytes = gfits_data_size (&header);
-    fseek (f, Nbytes, SEEK_CUR);
+    fseeko (f, Nbytes, SEEK_CUR);
     if (primary != NULL) {
       free (primary);
@@ -200,5 +201,5 @@
 int dvo_catalog_save_mef (Catalog *catalog, char VERBOSE) {
 
-  int Nitems;
+  off_t Nitems;
   FILE *f;
   Matrix matrix;
@@ -207,5 +208,6 @@
   SecFilt *primary;
   SecFilt *secfilt;
-  int i, j, Nsecfilt, Nallfilt, Ntotal;
+  off_t i, j, Nallfilt, Ntotal;
+  int Nsecfilt;
 
   if (catalog[0].Naverage == 0) {
@@ -236,14 +238,14 @@
 
   /* make sure header is consistent with data */
-  gfits_modify (&catalog[0].header, "NSTARS",   "%d", 1, catalog[0].Naverage);
-  gfits_modify (&catalog[0].header, "NMEAS",    "%d", 1, catalog[0].Nmeasure);
-  gfits_modify (&catalog[0].header, "NMISS",    "%d", 1, catalog[0].Nmissing);
-  gfits_modify (&catalog[0].header, "NSECFILT", "%d", 1, Nsecfilt);
-  gfits_modify (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
+  gfits_modify (&catalog[0].header, "NSTARS",   "%lld", 1, (long long) catalog[0].Naverage);
+  gfits_modify (&catalog[0].header, "NMEAS",    "%lld", 1, (long long) catalog[0].Nmeasure);
+  gfits_modify (&catalog[0].header, "NMISS",    "%lld", 1, (long long) catalog[0].Nmissing);
+  gfits_modify (&catalog[0].header, "NSECFILT", "%d",   1,                        Nsecfilt);
+  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
   gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
 
   f = catalog[0].f;
   /* rewind file pointers and truncate */
-  fseek (f, 0, SEEK_SET);
+  fseeko (f, 0LL, SEEK_SET);
   ftruncate (fileno (catalog[0].f), 0);
   ftable.header = &header;
Index: trunk/Ohana/src/libdvo/src/dvo_catalog_raw.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_catalog_raw.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_catalog_raw.c	(revision 27435)
@@ -5,8 +5,8 @@
 int dvo_catalog_load_raw (Catalog *catalog, int VERBOSE) {
   
-  int Nitems, nitems;
-  int i, Nmeas, Nmiss, size;
-  int NewMeasure, Nskip;
-  int AverageSize, MeasureSize, MissingSize, SecFiltSize;
+  off_t Nitems, nitems;
+  off_t i, Nmeas, Nmiss, size;
+  off_t NewMeasure, Nskip;
+  off_t AverageSize, MeasureSize, MissingSize, SecFiltSize;
   FILE *f;
   struct stat filestatus;
@@ -17,12 +17,12 @@
 
   /* move pointer past header -- must be already read (load_catalog) */
-  fseek (f, catalog[0].header.size, SEEK_SET);
+  fseeko (f, catalog[0].header.datasize, SEEK_SET);
 
   /* get the components from the header */
   catalog[0].Naverage = catalog[0].Nmeasure = catalog[0].Nmissing = catalog[0].Nsecfilt = 0;
-  if (!gfits_scan (&catalog[0].header, "NSTARS",   "%d", 1, &catalog[0].Naverage)) return (FALSE);
-  if (!gfits_scan (&catalog[0].header, "NMEAS",    "%d", 1, &catalog[0].Nmeasure)) return (FALSE);
-  if (!gfits_scan (&catalog[0].header, "NMISS",    "%d", 1, &catalog[0].Nmissing)) return (FALSE);
-  if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d", 1, &catalog[0].Nsecfilt)) catalog[0].Nsecfilt = 0;
+  if (!gfits_scan (&catalog[0].header, "NSTARS",   "%lld", 1, (long long *) &catalog[0].Naverage)) return (FALSE);
+  if (!gfits_scan (&catalog[0].header, "NMEAS",    "%lld", 1, (long long *) &catalog[0].Nmeasure)) return (FALSE);
+  if (!gfits_scan (&catalog[0].header, "NMISS",    "%lld", 1, (long long *) &catalog[0].Nmissing)) return (FALSE);
+  if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d",   1,               &catalog[0].Nsecfilt)) catalog[0].Nsecfilt = 0;
 
   /* the OBJID is a counter that uniquely defines an average entry and never changes.  if
@@ -45,5 +45,5 @@
   }
   /* special cases: old versions of the DB tables which were poorly identified */
-  if (gfits_scan (&catalog[0].header, "NEWMEAS",  "%t", 1, &NewMeasure)) {
+  if (gfits_scan_alt (&catalog[0].header, "NEWMEAS",  "%t", 1, &NewMeasure)) {
     catalog[0].catformat = DVO_FORMAT_ELIXIR; // special case for ELIXIR
     goto got_format;
@@ -98,5 +98,5 @@
 
   /* predicted file size - for double checking data validity */
-  size = catalog[0].header.size;
+  size = catalog[0].header.datasize;
   size += AverageSize * catalog[0].Naverage;
   size += MeasureSize * catalog[0].Nmeasure;
@@ -112,9 +112,9 @@
     if (VERBOSE) {
       fprintf (stderr, "star catalog has inconsistent size\n");
-      fprintf (stderr, "average: %d = %d bytes\n", catalog[0].Naverage, catalog[0].Naverage*AverageSize);
-      fprintf (stderr, "measure: %d = %d bytes\n", catalog[0].Nmeasure, catalog[0].Nmeasure*MeasureSize);
-      fprintf (stderr, "missing: %d = %d bytes\n", catalog[0].Nmissing, catalog[0].Nmissing*MissingSize);
-      fprintf (stderr, "secfilt: %d = %d bytes\n", catalog[0].Nsecfilt, catalog[0].Nsecfilt*SecFiltSize*catalog[0].Naverage);
-      fprintf (stderr, "expect: %d, found: %d\n", size, (int)filestatus.st_size);
+      fprintf (stderr, "average: %lld = %lld bytes\n", (long long) catalog[0].Naverage, (long long) catalog[0].Naverage*AverageSize);
+      fprintf (stderr, "measure: %lld = %lld bytes\n", (long long) catalog[0].Nmeasure, (long long) catalog[0].Nmeasure*MeasureSize);
+      fprintf (stderr, "missing: %lld = %lld bytes\n", (long long) catalog[0].Nmissing, (long long) catalog[0].Nmissing*MissingSize);
+      fprintf (stderr, "secfilt: %lld = %lld bytes\n", (long long) catalog[0].Nsecfilt, (long long) catalog[0].Nsecfilt*SecFiltSize*catalog[0].Naverage);
+      fprintf (stderr, "expect: %lld, found: %lld\n", (long long) size, (long long) filestatus.st_size);
     }
     return (FALSE);
@@ -136,5 +136,5 @@
     /* skip over averages */
     Nskip = catalog[0].Naverage * AverageSize;
-    fseek (f, Nskip, SEEK_CUR); 
+    fseeko (f, Nskip, SEEK_CUR); 
   }    
   
@@ -145,5 +145,5 @@
     /* skip over measures */
     Nskip = catalog[0].Nmeasure * MeasureSize;
-    fseek (f, Nskip, SEEK_CUR); 
+    fseeko (f, Nskip, SEEK_CUR); 
   }    
 
@@ -154,5 +154,5 @@
     nitems = fread (catalog[0].missing, MissingSize, Nitems, f);
     if (nitems != Nitems) {
-      if (VERBOSE) fprintf (stderr, "failed to read missing from catalog file %s (%d vs %d)\n", catalog[0].filename, nitems, Nitems);
+      if (VERBOSE) fprintf (stderr, "failed to read missing from catalog file %s (%lld vs %lld)\n", catalog[0].filename, (long long) nitems, (long long) Nitems);
       return (FALSE);
     }
@@ -161,5 +161,5 @@
     /* skip over missings */
     Nskip = catalog[0].Nmissing * MissingSize;
-    fseek (f, Nskip, SEEK_CUR); 
+    fseeko (f, Nskip, SEEK_CUR); 
   }
   
@@ -172,5 +172,5 @@
        we need to interleave these magnitudes with the secfilt entries just loaded */
     if (primary != NULL) {
-      int Ntmpfilt, Nsecfilt, Ntotal, i, j;
+      off_t Ntmpfilt, Nsecfilt, Ntotal, i, j;
       SecFilt *tmpfilt;
       tmpfilt  = catalog[0].secfilt;
@@ -193,10 +193,14 @@
     /* skip over secfilts */
     Nskip = catalog[0].Nsecfilt * catalog[0].Naverage * SecFiltSize;
-    fseek (f, Nskip, SEEK_CUR); 
+    fseeko (f, Nskip, SEEK_CUR); 
     if (primary != NULL) free (primary);
   }
 
-  if (VERBOSE) fprintf (stderr, "read %d stars from catalog file %s (%d measurements, %d missing, %d secondary filters)\n", 
-			catalog[0].Naverage, catalog[0].filename, catalog[0].Nmeasure, catalog[0].Nmissing, catalog[0].Nsecfilt);
+  if (VERBOSE) fprintf (stderr, "read %lld stars from catalog file %s (%lld measurements, %lld missing, %lld secondary filters)\n", 
+			(long long) catalog[0].Naverage, 
+			catalog[0].filename, 
+			(long long) catalog[0].Nmeasure, 
+			(long long) catalog[0].Nmissing, 
+			(long long) catalog[0].Nsecfilt);
 
   /* check data integrity */
@@ -209,6 +213,6 @@
       if (VERBOSE) {
 	fprintf (stderr, "****** data in catalog %s is corrupt, sums don't check\n", catalog[0].filename);
-	fprintf (stderr, "****** Nmeas: %d, %d\n", Nmeas, catalog[0].Nmeasure);
-	fprintf (stderr, "****** Nmiss: %d, %d\n", Nmiss, catalog[0].Nmissing);
+	fprintf (stderr, "****** Nmeas: %lld, %lld\n", (long long) Nmeas, (long long) catalog[0].Nmeasure);
+	fprintf (stderr, "****** Nmiss: %lld, %lld\n", (long long) Nmiss, (long long) catalog[0].Nmissing);
       }
       return (FALSE);
@@ -226,9 +230,9 @@
 int dvo_catalog_save_raw (Catalog *catalog, char VERBOSE) {
 
-  int Nitems, nitems;
+  off_t Nitems, nitems;
   FILE *f;
   SecFilt *primary;
   SecFilt *secfilt;
-  int i, j, Nsecfilt, Nallfilt, Ntotal;
+  off_t i, j, Nsecfilt, Nallfilt, Ntotal;
 
   if (catalog[0].Naverage == 0) {
@@ -259,8 +263,8 @@
 
   /* make sure header is consistent with data */
-  gfits_modify (&catalog[0].header, "NSTARS",   "%d", 1, catalog[0].Naverage);
-  gfits_modify (&catalog[0].header, "NMEAS",    "%d", 1, catalog[0].Nmeasure);
-  gfits_modify (&catalog[0].header, "NMISS",    "%d", 1, catalog[0].Nmissing);
-  gfits_modify (&catalog[0].header, "NSECFILT", "%d", 1, catalog[0].Nsecfilt);
+  gfits_modify (&catalog[0].header, "NSTARS",   "%lld", 1, (long long) catalog[0].Naverage);
+  gfits_modify (&catalog[0].header, "NMEAS",    "%lld", 1, (long long) catalog[0].Nmeasure);
+  gfits_modify (&catalog[0].header, "NMISS",    "%lld", 1, (long long) catalog[0].Nmissing);
+  gfits_modify (&catalog[0].header, "NSECFILT", "%lld", 1, (long long) catalog[0].Nsecfilt);
   gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
 
@@ -278,10 +282,10 @@
   /* rewind file pointers and truncate file */
   f = catalog[0].f;
-  fseek (f, 0, SEEK_SET);
+  fseeko (f, 0, SEEK_SET);
   ftruncate (fileno (catalog[0].f), 0);
 
   /* write header data (use gfits_write_header?) */
-  nitems = fwrite (catalog[0].header.buffer, 1, catalog[0].header.size, f);
-  if (nitems != catalog[0].header.size) {
+  nitems = fwrite (catalog[0].header.buffer, 1, catalog[0].header.datasize, f);
+  if (nitems != catalog[0].header.datasize) {
     if (VERBOSE) fprintf (stderr, "failed to write header\n");
     goto failure;
@@ -330,5 +334,5 @@
    in these cases, save these values in primary; otherwise set primary to NULL */
 
-Average *ReadRawAverage (FILE *f, int Naverage, int format, SecFilt **primary) {
+Average *ReadRawAverage (FILE *f, off_t Naverage, char format, SecFilt **primary) {
 
   Average *average;
@@ -339,10 +343,10 @@
 # define FORMAT_CASE(NAME,TYPE) \
     case DVO_FORMAT_##NAME: { \
-      int nitems; \
+      off_t nitems; \
       Average_##TYPE *tmpAverage; \
       ALLOCATE (tmpAverage, Average_##TYPE, MAX (Naverage, 1)); \
       nitems = fread (tmpAverage, sizeof(Average_##TYPE), Naverage, f); \
       if (nitems != Naverage) { \
-	fprintf (stderr, "failed to read averages (%d vs %d)\n", nitems, Naverage); \
+	fprintf (stderr, "failed to read averages (%lld vs %lld)\n", (long long) nitems, (long long) Naverage); \
 	return (NULL); \
       } \
@@ -354,9 +358,9 @@
   switch (format) {
     case DVO_FORMAT_INTERNAL: {
-      int nitems;
+      off_t nitems;
       ALLOCATE (average, Average, MAX (Naverage, 1));
       nitems = fread (average, sizeof(Average), Naverage, f);
       if (nitems != Naverage) {
-	fprintf (stderr, "failed to read averages (%d vs %d)\n", nitems, Naverage);
+	fprintf (stderr, "failed to read averages (%lld vs %lld)\n", (long long) nitems, (long long) Naverage);
 	return (NULL);
       }
@@ -384,10 +388,10 @@
 /* accepts and converts internal average formats and outputs 
    raw data in the specified format */
-int WriteRawAverage (FILE *f, Average *average, int Naverage, int format, SecFilt *primary) {
+int WriteRawAverage (FILE *f, Average *average, off_t Naverage, char format, SecFilt *primary) {
 
 // this macro generates the case statements for each type
 # define FORMAT_CASE(NAME,TYPE) \
     case DVO_FORMAT_##NAME: { \
-      int nitems; \
+      off_t nitems; \
       Average_##TYPE *tmpAverage; \
       tmpAverage = AverageInternalTo_##TYPE (average, Naverage, primary); \
@@ -396,5 +400,5 @@
       free (tmpAverage); \
       if (nitems != Naverage) { \
-	fprintf (stderr, "failed to write averages (%d vs %d)\n", nitems, Naverage); \
+	fprintf (stderr, "failed to write averages (%lld vs %lld)\n", (long long) nitems, (long long) Naverage); \
 	return (FALSE); \
       } \
@@ -403,9 +407,9 @@
   switch (format) {
     case DVO_FORMAT_INTERNAL: {
-      int nitems;
+      off_t nitems;
       gfits_convert_Average (average, sizeof(Average), Naverage);
       nitems = fwrite (average, sizeof(Average), Naverage, f);
       if (nitems != Naverage) {
-	fprintf (stderr, "failed to write averages (%d vs %d)\n", nitems, Naverage);
+	fprintf (stderr, "failed to write averages (%lld vs %lld)\n", (long long) nitems, (long long) Naverage);
 	return (FALSE);
       }
@@ -432,5 +436,5 @@
 /** Average / Raw Table conversions **/
 
-Measure *ReadRawMeasure (FILE *f, int Nmeasure, int format) {
+Measure *ReadRawMeasure (FILE *f, off_t Nmeasure, char format) {
 
   Measure *measure;
@@ -439,10 +443,10 @@
 # define FORMAT_CASE(NAME,TYPE) \
     case DVO_FORMAT_##NAME: { \
-      int nitems; \
+      off_t nitems; \
       Measure_##TYPE *tmpMeasure; \
       ALLOCATE (tmpMeasure, Measure_##TYPE, MAX (Nmeasure, 1)); \
       nitems = fread (tmpMeasure, sizeof(Measure_##TYPE), Nmeasure, f); \
       if (nitems != Nmeasure) { \
-	fprintf (stderr, "failed to read measures (%d vs %d)\n", nitems, Nmeasure); \
+	fprintf (stderr, "failed to read measures (%lld vs %lld)\n", (long long) nitems, (long long) Nmeasure); \
 	return (NULL); \
       } \
@@ -454,9 +458,9 @@
   switch (format) {
     case DVO_FORMAT_INTERNAL: {
-      int nitems;
+      off_t nitems;
       ALLOCATE (measure, Measure, MAX (Nmeasure, 1));
       nitems = fread (measure, sizeof(Measure), Nmeasure, f);
       if (nitems != Nmeasure) {
-	fprintf (stderr, "failed to read measures (%d vs %d)\n", nitems, Nmeasure);
+	fprintf (stderr, "failed to read measures (%lld vs %lld)\n", (long long) nitems, (long long) Nmeasure);
 	return (NULL);
       }
@@ -484,10 +488,10 @@
 /* accepts and converts internal measure formats and outputs 
    raw data in the specified format */
-int WriteRawMeasure (FILE *f, Measure *measure, int Nmeasure, int format) {
+int WriteRawMeasure (FILE *f, Measure *measure, off_t Nmeasure, char format) {
 
 // this macro generates the case statements for each type
 # define FORMAT_CASE(NAME,TYPE) \
     case DVO_FORMAT_##NAME: { \
-      int nitems; \
+      off_t nitems; \
       Measure_##TYPE *tmpMeasure; \
       tmpMeasure = MeasureInternalTo_##TYPE (measure, Nmeasure); \
@@ -496,5 +500,5 @@
       free (tmpMeasure); \
       if (nitems != Nmeasure) { \
-	fprintf (stderr, "failed to write measures (%d vs %d)\n", nitems, Nmeasure); \
+	fprintf (stderr, "failed to write measures (%lld vs %lld)\n", (long long) nitems, (long long) Nmeasure); \
 	return (FALSE); \
       } \
@@ -503,9 +507,9 @@
   switch (format) {
     case DVO_FORMAT_INTERNAL: {
-      int nitems;
+      off_t nitems;
       gfits_convert_Measure (measure, sizeof(Measure), Nmeasure);
       nitems = fwrite (measure, sizeof(Measure), Nmeasure, f);
       if (nitems != Nmeasure) {
-	fprintf (stderr, "failed to write measures (%d vs %d)\n", nitems, Nmeasure);
+	fprintf (stderr, "failed to write measures (%lld vs %lld)\n", (long long) nitems, (long long) Nmeasure);
 	return (FALSE);
       }
@@ -532,5 +536,5 @@
 /** SecFilt / Raw Table conversions **/
 
-SecFilt *ReadRawSecFilt (FILE *f, int Nsecfilt, int format) {
+SecFilt *ReadRawSecFilt (FILE *f, off_t Nsecfilt, char format) {
 
   SecFilt *secfilt;
@@ -539,10 +543,10 @@
 # define FORMAT_CASE(NAME,TYPE) \
     case DVO_FORMAT_##NAME: { \
-      int nitems; \
+      off_t nitems; \
       SecFilt_##TYPE *tmpSecFilt; \
       ALLOCATE (tmpSecFilt, SecFilt_##TYPE, MAX (Nsecfilt, 1)); \
       nitems = fread (tmpSecFilt, sizeof(SecFilt_##TYPE), Nsecfilt, f); \
       if (nitems != Nsecfilt) { \
-	fprintf (stderr, "failed to read secfilts (%d vs %d)\n", nitems, Nsecfilt); \
+	fprintf (stderr, "failed to read secfilts (%lld vs %lld)\n", (long long) nitems, (long long) Nsecfilt); \
 	return (NULL); \
       } \
@@ -554,9 +558,9 @@
   switch (format) {
     case DVO_FORMAT_INTERNAL: {
-      int nitems;
+      off_t nitems;
       ALLOCATE (secfilt, SecFilt, MAX (Nsecfilt, 1));
       nitems = fread (secfilt, sizeof(SecFilt), Nsecfilt, f);
       if (nitems != Nsecfilt) {
-	fprintf (stderr, "failed to read secfilts (%d vs %d)\n", nitems, Nsecfilt);
+	fprintf (stderr, "failed to read secfilts (%lld vs %lld)\n", (long long) nitems, (long long) Nsecfilt);
 	return (NULL);
       }
@@ -584,10 +588,10 @@
 /* accepts and converts internal secfilt formats and outputs 
    raw data in the specified format */
-int WriteRawSecFilt (FILE *f, SecFilt *secfilt, int Nsecfilt, int format) {
+int WriteRawSecFilt (FILE *f, SecFilt *secfilt, off_t Nsecfilt, char format) {
 
 // this macro generates the case statements for each type
 # define FORMAT_CASE(NAME,TYPE) \
     case DVO_FORMAT_##NAME: { \
-      int nitems; \
+      off_t nitems; \
       SecFilt_##TYPE *tmpSecFilt; \
       tmpSecFilt = SecFiltInternalTo_##TYPE (secfilt, Nsecfilt); \
@@ -596,5 +600,5 @@
       free (tmpSecFilt); \
       if (nitems != Nsecfilt) { \
-	fprintf (stderr, "failed to write secfilts (%d vs %d)\n", nitems, Nsecfilt); \
+	fprintf (stderr, "failed to write secfilts (%lld vs %lld)\n", (long long) nitems, (long long) Nsecfilt); \
 	return (FALSE); \
       } \
@@ -603,9 +607,9 @@
   switch (format) {
     case DVO_FORMAT_INTERNAL: {
-      int nitems;
+      off_t nitems;
       gfits_convert_SecFilt (secfilt, sizeof(SecFilt), Nsecfilt);
       nitems = fwrite (secfilt, sizeof(SecFilt), Nsecfilt, f);
       if (nitems != Nsecfilt) {
-	fprintf (stderr, "failed to write secfilts (%d vs %d)\n", nitems, Nsecfilt);
+	fprintf (stderr, "failed to write secfilts (%lld vs %lld)\n", (long long) nitems, (long long) Nsecfilt);
 	return (FALSE);
       }
Index: trunk/Ohana/src/libdvo/src/dvo_catalog_split.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_catalog_split.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_catalog_split.c	(revision 27435)
@@ -8,5 +8,5 @@
 int dvo_catalog_secfilt_to_primary (Catalog *catalog, SecFilt **myPrimary, SecFilt **mySecfilt, int *myNsecfilt) {
 
-  int i, j, Nallfilt, Nsecfilt, Ntotal;
+  off_t i, j, Nallfilt, Nsecfilt, Ntotal;
 
   SecFilt *primary;
@@ -43,7 +43,7 @@
 }
 
-int dvo_catalog_primary_to_secfilt (Catalog *catalog, SecFilt *primary, int Naves) {
-
-  int Ntmpfilt, Nsecfilt, Ntotal, i, j;
+int dvo_catalog_primary_to_secfilt (Catalog *catalog, SecFilt *primary, off_t Naves) {
+
+  off_t Ntmpfilt, Nsecfilt, Ntotal, i, j;
   SecFilt *tmpfilt;
 
@@ -71,10 +71,10 @@
 }
 
-int dvo_catalog_save_subcat (Catalog *catalog, FTable *ftable, int start, int Nrows, int Ndisk, int Ntotal) {
+int dvo_catalog_save_subcat (Catalog *catalog, FTable *ftable, off_t start, off_t Nrows, off_t Ndisk, off_t Ntotal) {
 
   Matrix matrix;
 
   /* rewind file pointers and truncate (file is still open) */
-  fseek (catalog->f, 0, SEEK_SET);
+  fseeko (catalog->f, 0LL, SEEK_SET);
 
   // write PHU header
@@ -103,5 +103,6 @@
 int dvo_catalog_open_subcat (Catalog *catalog, Catalog **Subcat, Header *header, char *name, int VERBOSE) {
 
-  int Nskip, status;
+  off_t Nskip;
+  int status;
   char *path, string[80];
   Catalog *subcat;
@@ -145,5 +146,5 @@
   }
   Nskip = gfits_data_size (&subcat[0].header);
-  fseek (subcat[0].f, Nskip, SEEK_CUR);
+  fseeko (subcat[0].f, Nskip, SEEK_CUR);
 
   /* read Measure table header */
@@ -158,5 +159,8 @@
 int dvo_catalog_load_split (Catalog *catalog, int VERBOSE) {
 
-  int Nbytes, Nitems, Naverage, Nmeasure, Nmissing, Nsecfilt, status;
+  off_t Nbytes;
+  off_t Naverage, Nmeasure, Nmissing;
+  off_t Nitems;
+  int status, Nsecfilt;
   Header header;
   FTable ftable;
@@ -170,17 +174,17 @@
 
   /* get the components from the header - these duplicate information in the split files (NAXIS2) */
-  if (!gfits_scan (&catalog[0].header, "NSTARS",   "%d", 1, &Naverage)) return (FALSE);
-  if (!gfits_scan (&catalog[0].header, "NMEAS",    "%d", 1, &Nmeasure)) return (FALSE);
-  if (!gfits_scan (&catalog[0].header, "NMISS",    "%d", 1, &Nmissing)) return (FALSE);
-  if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d", 1, &Nsecfilt)) Nsecfilt = 0;
+  if (!gfits_scan (&catalog[0].header, "NSTARS",   "%lld", 1, (long long *) &Naverage)) return (FALSE);
+  if (!gfits_scan (&catalog[0].header, "NMEAS",    "%lld", 1, (long long *) &Nmeasure)) return (FALSE);
+  if (!gfits_scan (&catalog[0].header, "NMISS",    "%lld", 1, (long long *) &Nmissing)) return (FALSE);
+  if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d",   1,               &Nsecfilt)) Nsecfilt = 0;
 
   /* the OBJID is a counter that uniquely defines an average entry and never changes.  if
      it is not defined for a legacy database, we can generate them using the existing index values.
      If it is missing, give a warning and recommend the user upgrade the DB */
-  if (!gfits_scan (&catalog[0].header, "OBJID",    "%d", 1, &catalog[0].objID)) {
+  if (!gfits_scan (&catalog[0].header, "OBJID",    "%u", 1, &catalog[0].objID)) {
     if (VERBOSE) fprintf (stderr, "WARNING: OBJID is not set for this database: upgrade for full feature set\n");
     catalog[0].objID = 0;
   }
-  if (!gfits_scan (&catalog[0].header, "CATID",    "%d", 1, &catalog[0].catID)) {
+  if (!gfits_scan (&catalog[0].header, "CATID",    "%u", 1, &catalog[0].catID)) {
     if (VERBOSE) fprintf (stderr, "WARNING: CATID is not set for this database: upgrade for full feature set\n");
     catalog[0].catID = 0;
@@ -206,6 +210,6 @@
   if (catalog[0].catflags & LOAD_AVES) {
     /* move pointer past header -- must be already read (load_catalog) */
-    Nbytes = catalog[0].header.size + gfits_data_size (&catalog[0].header);
-    fseek (catalog[0].f, Nbytes, SEEK_SET);
+    Nbytes = catalog[0].header.datasize + gfits_data_size (&catalog[0].header);
+    fseeko (catalog[0].f, Nbytes, SEEK_SET);
     /* read Average table header */
     if (!gfits_fread_header (catalog[0].f, &header)) { 
@@ -223,5 +227,5 @@
     catalog[0].average = FtableToAverage (&ftable, &Naverage, &catalog[0].catformat, &primary);
     if (Naverage != catalog[0].Naves_disk) {
-      fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers (%d vs %d)\n", Naverage, catalog[0].Naves_disk);
+      fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers (%lld vs %lld)\n", (long long) Naverage, (long long) catalog[0].Naves_disk);
     }
     gfits_free_header (&header);
@@ -252,5 +256,5 @@
     catalog[0].measure = FtableToMeasure (&ftable, &Nmeasure, &catalog[0].catformat);
     if (Nmeasure != catalog[0].Nmeas_disk) {
-      fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%d vs %d)\n", Nmeasure, catalog[0].Nmeas_disk);
+      fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%lld vs %lld)\n", (long long) Nmeasure, (long long) catalog[0].Nmeas_disk);
     }
     catalog[0].Nmeasure = catalog[0].Nmeas_disk;
@@ -282,5 +286,5 @@
     catalog[0].missing = gfits_table_get_Missing (&ftable, &Nmissing, NULL);
     if (Nmissing != catalog[0].Nmiss_disk) {
-      fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%d vs %d)\n", Nmissing, catalog[0].Nmiss_disk);
+      fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%lld vs %lld)\n", (long long) Nmissing, (long long) catalog[0].Nmiss_disk);
     }
     catalog[0].Nmissing = catalog[0].Nmiss_disk;
@@ -311,5 +315,5 @@
     catalog[0].secfilt = FtableToSecFilt (&ftable, &Nitems, &catalog[0].catformat);
     if (Nitems != catalog[0].Nsecf_disk) {
-      fprintf (stderr, "Warning: mismatch between Nsecfilt items in PHU and Table headers (%d vs %d)\n", Nitems, catalog[0].Nsecf_disk);
+      fprintf (stderr, "Warning: mismatch between Nsecfilt items in PHU and Table headers (%lld vs %lld)\n", (long long) Nitems, (long long) catalog[0].Nsecf_disk);
     }
     catalog[0].Nsecf_mem = catalog[0].Nsecf_disk;
@@ -339,7 +343,8 @@
 // I need to always read both average and secfilt at the same time to correctly manage the
 // primary secfilt values...
-int dvo_catalog_load_segment_split (Catalog *catalog, int VERBOSE, int start, int Nrows) {
-
-  int Nbytes, Naverage, Nexpect, Nitems, Nmeasure, Nmissing;
+int dvo_catalog_load_segment_split (Catalog *catalog, int VERBOSE, off_t start, off_t Nrows) {
+
+  off_t Nbytes;
+  off_t Naverage, Nexpect, Nitems, Nmeasure, Nmissing;
   Header header;
   FTable ftable;
@@ -357,6 +362,6 @@
     /*** load the Average data ***/
     /* move pointer past header and matrix -- must be already read (load_catalog) */
-    Nbytes = catalog[0].header.size + gfits_data_size (&catalog[0].header);
-    fseek (catalog[0].f, Nbytes, SEEK_SET);
+    Nbytes = catalog[0].header.datasize + gfits_data_size (&catalog[0].header);
+    fseeko (catalog[0].f, Nbytes, SEEK_SET);
     /* read Average table header */
     if (!gfits_fread_header (catalog[0].f, &header)) {
@@ -386,6 +391,6 @@
 
     /* move pointer past header -- must be already read (load_catalog) */
-    Nbytes = subcat[0].header.size + gfits_data_size (&subcat[0].header);
-    fseek (subcat[0].f, Nbytes, SEEK_SET);
+    Nbytes = subcat[0].header.datasize + gfits_data_size (&subcat[0].header);
+    fseeko (subcat[0].f, Nbytes, SEEK_SET);
 
     /* read Secfilt table header */
@@ -403,5 +408,5 @@
     catalog[0].secfilt = FtableToSecFilt (&ftable, &Nitems, &catalog[0].catformat);
     if (Nitems != Nexpect) {
-      fprintf (stderr, "Warning: mismatch between Nsecfilt items in PHU and Table headers (%d vs %d)\n", Nitems, Nexpect);
+      fprintf (stderr, "Warning: mismatch between Nsecfilt items in PHU and Table headers (%lld vs %lld)\n", (long long) Nitems, (long long) Nexpect);
     }
     catalog[0].Nsecf_mem = catalog[0].Naverage * catalog[0].Nsecfilt;
@@ -422,6 +427,6 @@
 
     /* move pointer past header -- must be already read (load_catalog) */
-    Nbytes = subcat[0].header.size + gfits_data_size (&subcat[0].header);
-    fseek (subcat[0].f, Nbytes, SEEK_SET);
+    Nbytes = subcat[0].header.datasize + gfits_data_size (&subcat[0].header);
+    fseeko (subcat[0].f, Nbytes, SEEK_SET);
 
     /* read Measure table header */
@@ -439,5 +444,5 @@
     catalog[0].measure = FtableToMeasure (&ftable, &Nmeasure, &catalog[0].catformat);
     if (Nmeasure != Nrows) {
-      fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%d vs %d)\n", Nmeasure, Nrows);
+      fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%lld vs %lld)\n", (long long) Nmeasure, (long long) Nrows);
     }
     gfits_free_header (&header);
@@ -452,6 +457,6 @@
 
     /* move pointer past header -- must be already read (load_catalog) */
-    Nbytes = subcat[0].header.size + gfits_data_size (&subcat[0].header);
-    fseek (subcat[0].f, Nbytes, SEEK_SET);
+    Nbytes = subcat[0].header.datasize + gfits_data_size (&subcat[0].header);
+    fseeko (subcat[0].f, Nbytes, SEEK_SET);
 
     /* read Missing table header */
@@ -469,5 +474,5 @@
     catalog[0].missing = gfits_table_get_Missing (&ftable, &Nmissing, NULL);
     if (Nmissing != Nrows) {
-      fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%d vs %d)\n", Nmissing, Nrows);
+      fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%lld vs %lld)\n", (long long) Nmissing, (long long) Nrows);
     }
     gfits_free_header (&header);
@@ -481,11 +486,11 @@
 int dvo_catalog_save_split (Catalog *catalog, char VERBOSE) {
 
-  int Nitems;
+  off_t Nitems;
   Header header;
   FTable ftable;
   SecFilt *primary, *secfilt;
   int Nsecfilt;
-  int Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new;
-  int first, start, Nrows;
+  off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new;
+  off_t first, start, Nrows;
 
   ftable.header = &header;
@@ -519,9 +524,9 @@
 
   /* make sure header is consistent with data */
-  gfits_modify (&catalog[0].header, "NSTARS",   "%d", 1, Naves_disk_new);
-  gfits_modify (&catalog[0].header, "NMEAS",    "%d", 1, Nmeas_disk_new);
-  gfits_modify (&catalog[0].header, "NMISS",    "%d", 1, Nmiss_disk_new);
-  gfits_modify (&catalog[0].header, "NSECFILT", "%d", 1, Nsecfilt);
-  gfits_modify (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
+  gfits_modify (&catalog[0].header, "NSTARS",   "%lld", 1, (long long) Naves_disk_new);
+  gfits_modify (&catalog[0].header, "NMEAS",    "%lld", 1, (long long) Nmeas_disk_new);
+  gfits_modify (&catalog[0].header, "NMISS",    "%lld", 1, (long long) Nmiss_disk_new);
+  gfits_modify (&catalog[0].header, "NSECFILT", "%d",   1, Nsecfilt);
+  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
   gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
 
@@ -555,5 +560,5 @@
     // even if we do not save the average table, we need to keep the header in sync
     /* rewind file pointers and truncate (file is still open) */
-    fseek (catalog[0].f, 0, SEEK_SET);
+    fseeko (catalog[0].f, 0, SEEK_SET);
 
     /* write table PHU header - always write this out */
@@ -662,11 +667,11 @@
 int dvo_catalog_save_split_complete (Catalog *catalog, char VERBOSE) {
 
-  int Nitems;
+  off_t Nitems;
   Header header;
   FTable ftable;
   SecFilt *primary, *secfilt;
   int Nsecfilt;
-  int Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new;
-  int first, start, Nrows;
+  off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new;
+  off_t first, start, Nrows;
 
   ftable.header = &header;
@@ -693,12 +698,10 @@
   }
 
-  if ((catalog[0].Naverage > 0) && (Naves_disk_new == 0)) {
-    Naves_disk_new = catalog[0].Naverage;
+  Naves_disk_new = catalog[0].Naverage;
+  if (Naves_disk_new == 0) {
     if (VERBOSE) fprintf (stderr, "resulting catalog is empty; delete it\n");
     // unlink ();
     return (TRUE);
   }
-
-  Naves_disk_new = catalog[0].Naverage;
 
   // for the appropriate types, pull out the first secfilt and pass to AverageToFtable as primary
@@ -720,9 +723,9 @@
 
   /* make sure header is consistent with data */
-  gfits_modify (&catalog[0].header, "NSTARS",   "%d", 1, Naves_disk_new);
-  gfits_modify (&catalog[0].header, "NMEAS",    "%d", 1, Nmeas_disk_new);
-  gfits_modify (&catalog[0].header, "NMISS",    "%d", 1, Nmiss_disk_new);
+  gfits_modify (&catalog[0].header, "NSTARS",   "%lld", 1, (long long) Naves_disk_new);
+  gfits_modify (&catalog[0].header, "NMEAS",    "%lld", 1, (long long) Nmeas_disk_new);
+  gfits_modify (&catalog[0].header, "NMISS",    "%lld", 1, (long long) Nmiss_disk_new);
   gfits_modify (&catalog[0].header, "NSECFILT", "%d", 1, Nsecfilt);
-  gfits_modify (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
+  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
   gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
 
@@ -756,5 +759,5 @@
     // even if we do not save the average table, we need to keep the header in sync
     /* rewind file pointers and truncate (file is still open) */
-    fseek (catalog[0].f, 0, SEEK_SET);
+    fseeko (catalog[0].f, 0, SEEK_SET);
 
     /* write table PHU header - always write this out */
@@ -867,6 +870,6 @@
   SecFilt *primary, *secfilt;
   int Nsecfilt;
-  int Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new;
-  int first, start, Nrows;
+  off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new;
+  off_t first, start, Nrows;
 
   ftable.header = &header;
@@ -899,9 +902,9 @@
 
   /* make sure header is consistent with data */
-  gfits_modify (&catalog[0].header, "NSTARS",   "%d", 1, Naves_disk_new);
-  gfits_modify (&catalog[0].header, "NMEAS",    "%d", 1, Nmeas_disk_new);
-  gfits_modify (&catalog[0].header, "NMISS",    "%d", 1, Nmiss_disk_new);
+  gfits_modify (&catalog[0].header, "NSTARS",   "%lld", 1, (long long) Naves_disk_new);
+  gfits_modify (&catalog[0].header, "NMEAS",    "%lld", 1, (long long) Nmeas_disk_new);
+  gfits_modify (&catalog[0].header, "NMISS",    "%lld", 1, (long long) Nmiss_disk_new);
   gfits_modify (&catalog[0].header, "NSECFILT", "%d", 1, Nsecfilt);
-  gfits_modify (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
+  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
   gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
 
@@ -935,5 +938,5 @@
     // even if we do not save the average table, we need to keep the header in sync
     /* rewind file pointers and truncate (file is still open) */
-    fseek (catalog[0].f, 0, SEEK_SET);
+    fseeko (catalog[0].f, 0, SEEK_SET);
 
     /* write table PHU header - always write this out */
Index: trunk/Ohana/src/libdvo/src/dvo_convert.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_convert.c	(revision 27435)
@@ -13,5 +13,5 @@
 /*** Average / FTable conversion functions ***/
 
-Average *FtableToAverage (FTable *ftable, int *Naverage, int *format, SecFilt **primary) {
+Average *FtableToAverage (FTable *ftable, off_t *Naverage, char *format, SecFilt **primary) {
 
   Average *average;
@@ -59,5 +59,5 @@
 }
 
-int AverageToFtable (FTable *ftable, Average *average, int Naverage, int format, SecFilt *primary) {
+int AverageToFtable (FTable *ftable, Average *average, off_t Naverage, char format, SecFilt *primary) {
 
 # define FORMAT_CASE(FORMAT, TYPE) \
@@ -94,5 +94,5 @@
 /*** Measure / FTable conversion functions ***/
 
-Measure *FtableToMeasure (FTable *ftable, int *Nmeasure, int *format) {
+Measure *FtableToMeasure (FTable *ftable, off_t *Nmeasure, char *format) {
 
   Measure *measure;
@@ -136,5 +136,5 @@
 }
 
-int MeasureToFtable (FTable *ftable, Measure *measure, int Nmeasure, int format) {
+int MeasureToFtable (FTable *ftable, Measure *measure, off_t Nmeasure, char format) {
 
 # define FORMAT_CASE(FORMAT, TYPE) \
@@ -171,5 +171,5 @@
 /*** SecFilt / FTable conversion functions ***/
 
-SecFilt *FtableToSecFilt (FTable *ftable, int *Nsecfilt, int *format) {
+SecFilt *FtableToSecFilt (FTable *ftable, off_t *Nsecfilt, char *format) {
 
   SecFilt *secfilt;
@@ -213,5 +213,5 @@
 }
 
-int SecFiltToFtable (FTable *ftable, SecFilt *secfilt, int Nsecfilt, int format) {
+int SecFiltToFtable (FTable *ftable, SecFilt *secfilt, off_t Nsecfilt, char format) {
 
 # define FORMAT_CASE(FORMAT, TYPE) \
@@ -248,7 +248,7 @@
 /*** Image Conversions ***/
 
-int FtableToImage (FTable *ftable, Header *theader, int *format) {
-
-  int Nimage;
+int FtableToImage (FTable *ftable, Header *theader, char *format) {
+
+  off_t Nimage;
   char extname[80];
 
@@ -261,7 +261,7 @@
     gfits_free_header (theader);
     gfits_table_mkheader_Image (theader);
-    gfits_modify (theader, "NAXIS2", "%d", 1, Nimage);
+    gfits_modify (theader, "NAXIS2", "%lld", 1, (long long) Nimage);
     theader[0].Naxis[1] = Nimage;
-    ftable[0].size = gfits_data_size (theader);
+    ftable[0].datasize = gfits_data_size (theader);
     return (TRUE);
   }
@@ -282,7 +282,7 @@
     gfits_free_header (theader); \
     gfits_table_mkheader_Image (theader); \
-    gfits_modify (theader, "NAXIS2", "%d", 1, Nimage); \
+    gfits_modify (theader, "NAXIS2", "%lld", 1, (long long) Nimage); \
     theader[0].Naxis[1] = Nimage; \
-    ftable[0].size = gfits_data_size (theader); \
+    ftable[0].datasize = gfits_data_size (theader); \
     return (TRUE); }
 
@@ -312,7 +312,7 @@
 }
 
-int ImageToFtable (FTable *ftable, Header *theader, int format) {
-
-  int Nimage;
+int ImageToFtable (FTable *ftable, Header *theader, char format) {
+
+  off_t Nimage;
 
   Nimage = theader[0].Naxis[1];
@@ -353,7 +353,7 @@
 }
 
-int ImageToVtable (VTable *vtable, Header *theader, int format) {
-
-  int i, Nrow, Nimage;
+int ImageToVtable (VTable *vtable, Header *theader, char format) {
+
+  off_t i, Nrow, Nimage;
 
   Nrow = vtable[0].Nrow;
@@ -370,10 +370,10 @@
       } \
       /* convert header from old format to new format */ \
-      gfits_scan (theader, "NAXIS2", "%d", 1, &Nimage); \
+      gfits_scan (theader, "NAXIS2", "%lld", 1, (long long *) &Nimage); \
       gfits_free_header (theader); \
       gfits_table_mkheader_Image_##TYPE (theader); \
-      gfits_modify (theader, "NAXIS2", "%d", 1, Nimage); \
+      gfits_modify (theader, "NAXIS2", "%lld", 1, (long long) Nimage); \
       theader[0].Naxis[1] = Nimage; \
-      vtable[0].size = gfits_data_size (theader); \
+      vtable[0].datasize = gfits_data_size (theader); \
       return (TRUE); }
 
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 27435)
@@ -3,7 +3,7 @@
 /* convert PS1_DEV_1 formats to internal formats */
 
-Measure *Measure_PS1_DEV_1_ToInternal (Measure_PS1_DEV_1 *in, int Nvalues) {
-
-  int i;
+Measure *Measure_PS1_DEV_1_ToInternal (Measure_PS1_DEV_1 *in, off_t Nvalues) {
+
+  off_t i;
   Measure *out;
 
@@ -61,7 +61,7 @@
 }
 
-Measure_PS1_DEV_1 *MeasureInternalTo_PS1_DEV_1 (Measure *in, int Nvalues) {
-
-  int i;
+Measure_PS1_DEV_1 *MeasureInternalTo_PS1_DEV_1 (Measure *in, off_t Nvalues) {
+
+  off_t i;
   Measure_PS1_DEV_1 *out;
 
@@ -108,7 +108,7 @@
 
 // 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
-Average *Average_PS1_DEV_1_ToInternal (Average_PS1_DEV_1 *in, int Nvalues, SecFilt **primary) {
-
-  int i;
+Average *Average_PS1_DEV_1_ToInternal (Average_PS1_DEV_1 *in, off_t Nvalues, SecFilt **primary) {
+
+  off_t i;
   Average *out;
 
@@ -148,7 +148,7 @@
 
 // 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
-Average_PS1_DEV_1 *AverageInternalTo_PS1_DEV_1 (Average *in, int Nvalues, SecFilt *primary) {
-
-  int i;
+Average_PS1_DEV_1 *AverageInternalTo_PS1_DEV_1 (Average *in, off_t Nvalues, SecFilt *primary) {
+
+  off_t i;
   Average_PS1_DEV_1 *out;
 
@@ -182,7 +182,7 @@
 }
 
-SecFilt *SecFilt_PS1_DEV_1_ToInternal (SecFilt_PS1_DEV_1 *in, int Nvalues) {
-
-  int i;
+SecFilt *SecFilt_PS1_DEV_1_ToInternal (SecFilt_PS1_DEV_1 *in, off_t Nvalues) {
+
+  off_t i;
   SecFilt *out;
 
@@ -203,7 +203,7 @@
 }
 
-SecFilt_PS1_DEV_1 *SecFiltInternalTo_PS1_DEV_1 (SecFilt *in, int Nvalues) {
-
-  int i;
+SecFilt_PS1_DEV_1 *SecFiltInternalTo_PS1_DEV_1 (SecFilt *in, off_t Nvalues) {
+
+  off_t i;
   SecFilt_PS1_DEV_1 *out;
 
@@ -220,7 +220,7 @@
 }
 
-Image *Image_PS1_DEV_1_ToInternal (Image_PS1_DEV_1 *in, int Nvalues) {
-
-  int i;
+Image *Image_PS1_DEV_1_ToInternal (Image_PS1_DEV_1 *in, off_t Nvalues) {
+
+  off_t i;
   Image *out;
 
@@ -284,7 +284,7 @@
 
 /* convert internal images to panstarrs-format images */
-Image_PS1_DEV_1 *ImageInternalTo_PS1_DEV_1 (Image *in, int Nvalues) {
-
-  int i;
+Image_PS1_DEV_1 *ImageInternalTo_PS1_DEV_1 (Image *in, off_t Nvalues) {
+
+  off_t i;
   Image_PS1_DEV_1 *out;
 
@@ -342,7 +342,7 @@
 }
 
-PhotCode *PhotCode_PS1_DEV_1_To_Internal (PhotCode_PS1_DEV_1 *in, int Nvalues) {
-
-  int i;
+PhotCode *PhotCode_PS1_DEV_1_To_Internal (PhotCode_PS1_DEV_1 *in, off_t Nvalues) {
+
+  off_t i;
   PhotCode *out;
 
@@ -381,7 +381,7 @@
 }
 
-PhotCode_PS1_DEV_1 *PhotCode_Internal_To_PS1_DEV_1 (PhotCode *in, int Nvalues) {
-
-  int i;
+PhotCode_PS1_DEV_1 *PhotCode_Internal_To_PS1_DEV_1 (PhotCode *in, off_t Nvalues) {
+
+  off_t i;
   PhotCode_PS1_DEV_1 *out;
 
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 27435)
@@ -3,7 +3,7 @@
 /* convert PS1_DEV_2 formats to internal formats */
 
-Measure *Measure_PS1_DEV_2_ToInternal (Measure_PS1_DEV_2 *in, int Nvalues) {
-
-  int i;
+Measure *Measure_PS1_DEV_2_ToInternal (Measure_PS1_DEV_2 *in, off_t Nvalues) {
+
+  off_t i;
   Measure *out;
 
@@ -58,7 +58,7 @@
 }
 
-Measure_PS1_DEV_2 *MeasureInternalTo_PS1_DEV_2 (Measure *in, int Nvalues) {
-
-  int i;
+Measure_PS1_DEV_2 *MeasureInternalTo_PS1_DEV_2 (Measure *in, off_t Nvalues) {
+
+  off_t i;
   Measure_PS1_DEV_2 *out;
 
@@ -104,7 +104,7 @@
 
 // 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
-Average *Average_PS1_DEV_2_ToInternal (Average_PS1_DEV_2 *in, int Nvalues, SecFilt **primary) {
-
-  int i;
+Average *Average_PS1_DEV_2_ToInternal (Average_PS1_DEV_2 *in, off_t Nvalues, SecFilt **primary) {
+
+  off_t i;
   Average *out;
 
@@ -142,7 +142,7 @@
 
 // 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
-Average_PS1_DEV_2 *AverageInternalTo_PS1_DEV_2 (Average *in, int Nvalues, SecFilt *primary) {
-
-  int i;
+Average_PS1_DEV_2 *AverageInternalTo_PS1_DEV_2 (Average *in, off_t Nvalues, SecFilt *primary) {
+
+  off_t i;
   Average_PS1_DEV_2 *out;
 
@@ -176,7 +176,7 @@
 }
 
-SecFilt *SecFilt_PS1_DEV_2_ToInternal (SecFilt_PS1_DEV_2 *in, int Nvalues) {
-
-  int i;
+SecFilt *SecFilt_PS1_DEV_2_ToInternal (SecFilt_PS1_DEV_2 *in, off_t Nvalues) {
+
+  off_t i;
   SecFilt *out;
 
@@ -197,7 +197,7 @@
 }
 
-SecFilt_PS1_DEV_2 *SecFiltInternalTo_PS1_DEV_2 (SecFilt *in, int Nvalues) {
-
-  int i;
+SecFilt_PS1_DEV_2 *SecFiltInternalTo_PS1_DEV_2 (SecFilt *in, off_t Nvalues) {
+
+  off_t i;
   SecFilt_PS1_DEV_2 *out;
 
@@ -214,7 +214,7 @@
 }
 
-Image *Image_PS1_DEV_2_ToInternal (Image_PS1_DEV_2 *in, int Nvalues) {
-
-  int i;
+Image *Image_PS1_DEV_2_ToInternal (Image_PS1_DEV_2 *in, off_t Nvalues) {
+
+  off_t i;
   Image *out;
 
@@ -224,5 +224,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
 
-    strncpy (out[i].name, in[i].name, 63); // out[121], int[64]
+    strncpy (out[i].name, in[i].name, 63); // out[121], in[64]
     out[i].name[63] = 0; // force termination
 
@@ -275,7 +275,7 @@
 }
 
-Image_PS1_DEV_2 *ImageInternalTo_PS1_DEV_2 (Image *in, int Nvalues) {
-
-  int i;
+Image_PS1_DEV_2 *ImageInternalTo_PS1_DEV_2 (Image *in, off_t Nvalues) {
+
+  off_t i;
   Image_PS1_DEV_2 *out;
 
@@ -335,7 +335,7 @@
 }
 
-PhotCode *PhotCode_PS1_DEV_2_To_Internal (PhotCode_PS1_DEV_2 *in, int Nvalues) {
-
-  int i;
+PhotCode *PhotCode_PS1_DEV_2_To_Internal (PhotCode_PS1_DEV_2 *in, off_t Nvalues) {
+
+  off_t i;
   PhotCode *out;
 
@@ -372,7 +372,7 @@
 }
 
-PhotCode_PS1_DEV_2 *PhotCode_Internal_To_PS1_DEV_2 (PhotCode *in, int Nvalues) {
-
-  int i;
+PhotCode_PS1_DEV_2 *PhotCode_Internal_To_PS1_DEV_2 (PhotCode *in, off_t Nvalues) {
+
+  off_t i;
   PhotCode_PS1_DEV_2 *out;
 
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c	(revision 27435)
@@ -5,7 +5,7 @@
 // We only provide image and photcode conversion
 
-Image *Image_PS1_DEV_3_ToInternal (Image_PS1_DEV_3 *in, int Nvalues) {
+Image *Image_PS1_DEV_3_ToInternal (Image_PS1_DEV_3 *in, off_t Nvalues) {
 
-  int i;
+  off_t i;
   Image *out;
 
@@ -66,7 +66,7 @@
 }
 
-Image_PS1_DEV_3 *ImageInternalTo_PS1_DEV_3 (Image *in, int Nvalues) {
+Image_PS1_DEV_3 *ImageInternalTo_PS1_DEV_3 (Image *in, off_t Nvalues) {
 
-  int i;
+  off_t i;
   Image_PS1_DEV_3 *out;
 
@@ -126,7 +126,7 @@
 }
 
-PhotCode *PhotCode_PS1_DEV_3_To_Internal (PhotCode_PS1_DEV_3 *in, int Nvalues) {
+PhotCode *PhotCode_PS1_DEV_3_To_Internal (PhotCode_PS1_DEV_3 *in, off_t Nvalues) {
 
-  int i;
+  off_t i;
   PhotCode *out;
 
@@ -162,7 +162,7 @@
 }
 
-PhotCode_PS1_DEV_3 *PhotCode_Internal_To_PS1_DEV_3 (PhotCode *in, int Nvalues) {
+PhotCode_PS1_DEV_3 *PhotCode_Internal_To_PS1_DEV_3 (PhotCode *in, off_t Nvalues) {
 
-  int i;
+  off_t i;
   PhotCode_PS1_DEV_3 *out;
 
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c	(revision 27435)
@@ -3,7 +3,7 @@
 /* convert PS1_REF formats to internal formats */
 
-Measure *Measure_PS1_REF_ToInternal (Measure_PS1_REF *in, int Nvalues) {
-
-  int i;
+Measure *Measure_PS1_REF_ToInternal (Measure_PS1_REF *in, off_t Nvalues) {
+
+  off_t i;
   Measure *out;
 
@@ -56,7 +56,7 @@
 }
 
-Measure_PS1_REF *MeasureInternalTo_PS1_REF (Measure *in, int Nvalues) {
-
-  int i;
+Measure_PS1_REF *MeasureInternalTo_PS1_REF (Measure *in, off_t Nvalues) {
+
+  off_t i;
   Measure_PS1_REF *out;
 
@@ -79,7 +79,7 @@
 
 // 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
-Average *Average_PS1_REF_ToInternal (Average_PS1_REF *in, int Nvalues, SecFilt **primary) {
-
-  int i;
+Average *Average_PS1_REF_ToInternal (Average_PS1_REF *in, off_t Nvalues, SecFilt **primary) {
+
+  off_t i;
   Average *out;
 
@@ -97,5 +97,5 @@
     out[i].P        	 = NAN;
     out[i].dP       	 = NAN;
-    out[i].Xp       	 = NAN;
+    out[i].Xp       	 = NAN_S_SHORT;
     out[i].ChiSq       	 = NAN;
     out[i].Npos       	 = 0;
@@ -115,7 +115,7 @@
 
 // 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
-Average_PS1_REF *AverageInternalTo_PS1_REF (Average *in, int Nvalues, SecFilt *primary) {
-
-  int i;
+Average_PS1_REF *AverageInternalTo_PS1_REF (Average *in, off_t Nvalues, SecFilt *primary) {
+
+  off_t i;
   Average_PS1_REF *out;
 
@@ -138,7 +138,7 @@
 }
 
-SecFilt *SecFilt_PS1_REF_ToInternal (SecFilt_PS1_REF *in, int Nvalues) {
-
-  int i;
+SecFilt *SecFilt_PS1_REF_ToInternal (SecFilt_PS1_REF *in, off_t Nvalues) {
+
+  off_t i;
   SecFilt *out;
 
@@ -148,5 +148,5 @@
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
-    out[i].Xm    = NAN;
+    out[i].Xm    = NAN_S_SHORT;
     out[i].Ncode = 0;
     out[i].Nused = 0;
@@ -157,7 +157,7 @@
 }
 
-SecFilt_PS1_REF *SecFiltInternalTo_PS1_REF (SecFilt *in, int Nvalues) {
-
-  int i;
+SecFilt_PS1_REF *SecFiltInternalTo_PS1_REF (SecFilt *in, off_t Nvalues) {
+
+  off_t i;
   SecFilt_PS1_REF *out;
 
@@ -171,7 +171,7 @@
 }
 
-Image *Image_PS1_REF_ToInternal (Image_PS1_REF *in, int Nvalues) {
-
-  int i;
+Image *Image_PS1_REF_ToInternal (Image_PS1_REF *in, off_t Nvalues) {
+
+  off_t i;
   Image *out;
 
@@ -230,7 +230,7 @@
 }
 
-Image_PS1_REF *ImageInternalTo_PS1_REF (Image *in, int Nvalues) {
-
-  int i;
+Image_PS1_REF *ImageInternalTo_PS1_REF (Image *in, off_t Nvalues) {
+
+  off_t i;
   Image_PS1_REF *out;
 
@@ -289,7 +289,7 @@
 }
 
-PhotCode *PhotCode_PS1_REF_To_Internal (PhotCode_PS1_REF *in, int Nvalues) {
-
-  int i;
+PhotCode *PhotCode_PS1_REF_To_Internal (PhotCode_PS1_REF *in, off_t Nvalues) {
+
+  off_t i;
   PhotCode *out;
 
@@ -325,7 +325,7 @@
 }
 
-PhotCode_PS1_REF *PhotCode_Internal_To_PS1_REF (PhotCode *in, int Nvalues) {
-
-  int i;
+PhotCode_PS1_REF *PhotCode_Internal_To_PS1_REF (PhotCode *in, off_t Nvalues) {
+
+  off_t i;
   PhotCode_PS1_REF *out;
 
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 27435)
@@ -3,7 +3,7 @@
 /* convert PS1_V1 formats to internal formats */
 
-Measure *Measure_PS1_V1_ToInternal (Measure_PS1_V1 *in, int Nvalues) {
-
-  int i;
+Measure *Measure_PS1_V1_ToInternal (Measure_PS1_V1 *in, off_t Nvalues) {
+
+  off_t i;
   Measure *out;
 
@@ -56,7 +56,7 @@
 }
 
-Measure_PS1_V1 *MeasureInternalTo_PS1_V1 (Measure *in, int Nvalues) {
-
-  int i;
+Measure_PS1_V1 *MeasureInternalTo_PS1_V1 (Measure *in, off_t Nvalues) {
+
+  off_t i;
   Measure_PS1_V1 *out;
 
@@ -111,7 +111,7 @@
 
 // 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
-Average *Average_PS1_V1_ToInternal (Average_PS1_V1 *in, int Nvalues, SecFilt **primary) {
-
-  int i;
+Average *Average_PS1_V1_ToInternal (Average_PS1_V1 *in, off_t Nvalues, SecFilt **primary) {
+
+  off_t i;
   Average *out;
 
@@ -147,7 +147,7 @@
 
 // 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
-Average_PS1_V1 *AverageInternalTo_PS1_V1 (Average *in, int Nvalues, SecFilt *primary) {
-
-  int i;
+Average_PS1_V1 *AverageInternalTo_PS1_V1 (Average *in, off_t Nvalues, SecFilt *primary) {
+
+  off_t i;
   Average_PS1_V1 *out;
 
@@ -182,7 +182,7 @@
 }
 
-SecFilt *SecFilt_PS1_V1_ToInternal (SecFilt_PS1_V1 *in, int Nvalues) {
-
-  int i;
+SecFilt *SecFilt_PS1_V1_ToInternal (SecFilt_PS1_V1 *in, off_t Nvalues) {
+
+  off_t i;
   SecFilt *out;
 
@@ -201,7 +201,7 @@
 }
 
-SecFilt_PS1_V1 *SecFiltInternalTo_PS1_V1 (SecFilt *in, int Nvalues) {
-
-  int i;
+SecFilt_PS1_V1 *SecFiltInternalTo_PS1_V1 (SecFilt *in, off_t Nvalues) {
+
+  off_t i;
   SecFilt_PS1_V1 *out;
 
@@ -220,7 +220,7 @@
 }
 
-Image *Image_PS1_V1_ToInternal (Image_PS1_V1 *in, int Nvalues) {
-
-  int i;
+Image *Image_PS1_V1_ToInternal (Image_PS1_V1 *in, off_t Nvalues) {
+
+  off_t i;
   Image *out;
 
@@ -279,7 +279,7 @@
 }
 
-Image_PS1_V1 *ImageInternalTo_PS1_V1 (Image *in, int Nvalues) {
-
-  int i;
+Image_PS1_V1 *ImageInternalTo_PS1_V1 (Image *in, off_t Nvalues) {
+
+  off_t i;
   Image_PS1_V1 *out;
 
@@ -338,7 +338,7 @@
 }
 
-PhotCode *PhotCode_PS1_V1_To_Internal (PhotCode_PS1_V1 *in, int Nvalues) {
-
-  int i;
+PhotCode *PhotCode_PS1_V1_To_Internal (PhotCode_PS1_V1 *in, off_t Nvalues) {
+
+  off_t i;
   PhotCode *out;
 
@@ -374,7 +374,7 @@
 }
 
-PhotCode_PS1_V1 *PhotCode_Internal_To_PS1_V1 (PhotCode *in, int Nvalues) {
-
-  int i;
+PhotCode_PS1_V1 *PhotCode_Internal_To_PS1_V1 (PhotCode *in, off_t Nvalues) {
+
+  off_t i;
   PhotCode_PS1_V1 *out;
 
Index: trunk/Ohana/src/libdvo/src/dvo_convert_elixir.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 27435)
@@ -2,7 +2,7 @@
 
 /* convert elixir-format measures to internal measures */
-Measure *Measure_Elixir_ToInternal (Measure_Elixir *in, int Nvalues) {
-
-  int i;
+Measure *Measure_Elixir_ToInternal (Measure_Elixir *in, off_t Nvalues) {
+
+  off_t i;
   Measure *out;
 
@@ -69,7 +69,7 @@
 
 /* convert internal measures to elixir-format measures */
-Measure_Elixir *MeasureInternalTo_Elixir (Measure *in, int Nvalues) {
-
-  int i;
+Measure_Elixir *MeasureInternalTo_Elixir (Measure *in, off_t Nvalues) {
+
+  off_t i;
   Measure_Elixir *out;
 
@@ -108,7 +108,7 @@
 
 /* convert elixir-format averages to internal averages */
-Average *Average_Elixir_ToInternal (Average_Elixir *in, int Nvalues, SecFilt **primary) {
-
-  int i;
+Average *Average_Elixir_ToInternal (Average_Elixir *in, off_t Nvalues, SecFilt **primary) {
+
+  off_t i;
   Average *out;
 
@@ -159,7 +159,7 @@
 
 /* convert internal averages to elixir-format averages */
-Average_Elixir *AverageInternalTo_Elixir (Average *in, int Nvalues, SecFilt *primary) {
-
-  int i;
+Average_Elixir *AverageInternalTo_Elixir (Average *in, off_t Nvalues, SecFilt *primary) {
+
+  off_t i;
   Average_Elixir *out;
 
@@ -189,7 +189,7 @@
 
 /* convert elixir-format secfilts to internal secfilts */
-SecFilt *SecFilt_Elixir_ToInternal (SecFilt_Elixir *in, int Nvalues) {
-
-  int i;
+SecFilt *SecFilt_Elixir_ToInternal (SecFilt_Elixir *in, off_t Nvalues) {
+
+  off_t i;
   SecFilt *out;
 
@@ -213,7 +213,7 @@
 
 /* convert internal secfilts to elixir-format secfilts */
-SecFilt_Elixir *SecFiltInternalTo_Elixir (SecFilt *in, int Nvalues) {
-
-  int i;
+SecFilt_Elixir *SecFiltInternalTo_Elixir (SecFilt *in, off_t Nvalues) {
+
+  off_t i;
   SecFilt_Elixir *out;
 
@@ -231,7 +231,7 @@
 
 /* convert elixir-format images to internal images */
-Image *Image_Elixir_ToInternal (Image_Elixir *in, int Nvalues) {
-
-  int i;
+Image *Image_Elixir_ToInternal (Image_Elixir *in, off_t Nvalues) {
+
+  off_t i;
   Image *out;
 
@@ -297,7 +297,7 @@
 
 /* convert internal images to elixir-format images */
-Image_Elixir *ImageInternalTo_Elixir (Image *in, int Nvalues) {
-
-  int i;
+Image_Elixir *ImageInternalTo_Elixir (Image *in, off_t Nvalues) {
+
+  off_t i;
   Image_Elixir *out;
 
@@ -355,7 +355,7 @@
 }
 
-PhotCode *PhotCode_Elixir_To_Internal (PhotCode_Elixir *in, int Nvalues) {
-
-  int i;
+PhotCode *PhotCode_Elixir_To_Internal (PhotCode_Elixir *in, off_t Nvalues) {
+
+  off_t i;
   PhotCode *out;
 
@@ -395,7 +395,7 @@
 }
 
-PhotCode_Elixir *PhotCode_Internal_To_Elixir (PhotCode *in, int Nvalues) {
-
-  int i;
+PhotCode_Elixir *PhotCode_Internal_To_Elixir (PhotCode *in, off_t Nvalues) {
+
+  off_t i;
   PhotCode_Elixir *out;
 
Index: trunk/Ohana/src/libdvo/src/dvo_convert_loneos.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 27435)
@@ -2,7 +2,7 @@
 
 /* convert loneos-format measures to internal measures */
-Measure *Measure_Loneos_ToInternal (Measure_Loneos *in, int Nvalues) {
-
-  int i;
+Measure *Measure_Loneos_ToInternal (Measure_Loneos *in, off_t Nvalues) {
+
+  off_t i;
   Measure *out;
 
@@ -71,7 +71,7 @@
 
 /* convert internal measures to loneos-format measures */
-Measure_Loneos *MeasureInternalTo_Loneos (Measure *in, int Nvalues) {
-
-  int i;
+Measure_Loneos *MeasureInternalTo_Loneos (Measure *in, off_t Nvalues) {
+
+  off_t i;
   Measure_Loneos *out;
 
@@ -99,7 +99,7 @@
 
 /* convert loneos-format averages to internal averages */
-Average *Average_Loneos_ToInternal (Average_Loneos *in, int Nvalues, SecFilt **primary) {
-
-  int i;
+Average *Average_Loneos_ToInternal (Average_Loneos *in, off_t Nvalues, SecFilt **primary) {
+
+  off_t i;
   Average *out;
 
@@ -151,7 +151,7 @@
 
 /* convert internal averages to loneos-format averages */
-Average_Loneos *AverageInternalTo_Loneos (Average *in, int Nvalues, SecFilt *primary) {
-
-  int i;
+Average_Loneos *AverageInternalTo_Loneos (Average *in, off_t Nvalues, SecFilt *primary) {
+
+  off_t i;
   Average_Loneos *out;
 
@@ -180,7 +180,7 @@
 
 /* convert loneos-format secfilts to internal secfilts */
-SecFilt *SecFilt_Loneos_ToInternal (SecFilt_Loneos *in, int Nvalues) {
-
-  int i;
+SecFilt *SecFilt_Loneos_ToInternal (SecFilt_Loneos *in, off_t Nvalues) {
+
+  off_t i;
   SecFilt *out;
 
@@ -206,7 +206,7 @@
 
 /* convert internal secfilts to loneos-format secfilts */
-SecFilt_Loneos *SecFiltInternalTo_Loneos (SecFilt *in, int Nvalues) {
-
-  int i;
+SecFilt_Loneos *SecFiltInternalTo_Loneos (SecFilt *in, off_t Nvalues) {
+
+  off_t i;
   SecFilt_Loneos *out;
 
@@ -223,7 +223,7 @@
 
 /* convert loneos-format images to internal images */
-Image *Image_Loneos_ToInternal (Image_Loneos *in, int Nvalues) {
-
-  int i;
+Image *Image_Loneos_ToInternal (Image_Loneos *in, off_t Nvalues) {
+
+  off_t i;
   Image *out;
 
@@ -290,7 +290,7 @@
 
 /* convert internal images to loneos-format images */
-Image_Loneos *ImageInternalTo_Loneos (Image *in, int Nvalues) {
-
-  int i;
+Image_Loneos *ImageInternalTo_Loneos (Image *in, off_t Nvalues) {
+
+  off_t i;
   Image_Loneos *out;
 
Index: trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 27435)
@@ -2,7 +2,7 @@
 
 /* convert panstarrs-format measures to internal measures */
-Measure *Measure_Panstarrs_DEV_0_ToInternal (Measure_Panstarrs_DEV_0 *in, int Nvalues) {
-
-  int i;
+Measure *Measure_Panstarrs_DEV_0_ToInternal (Measure_Panstarrs_DEV_0 *in, off_t Nvalues) {
+
+  off_t i;
   Measure *out;
 
@@ -66,7 +66,7 @@
 
 /* convert internal measures to panstarrs-format measures */
-Measure_Panstarrs_DEV_0 *MeasureInternalTo_Panstarrs_DEV_0 (Measure *in, int Nvalues) {
-
-  int i;
+Measure_Panstarrs_DEV_0 *MeasureInternalTo_Panstarrs_DEV_0 (Measure *in, off_t Nvalues) {
+
+  off_t i;
   Measure_Panstarrs_DEV_0 *out;
 
@@ -115,7 +115,7 @@
 /* convert panstarrs-format averages to internal averages */
 // 'primary is needed to conform with the API for Loneos and Elixir, but is not used
-Average *Average_Panstarrs_DEV_0_ToInternal (Average_Panstarrs_DEV_0 *in, int Nvalues, SecFilt **primary) {
-
-  int i;
+Average *Average_Panstarrs_DEV_0_ToInternal (Average_Panstarrs_DEV_0 *in, off_t Nvalues, SecFilt **primary) {
+
+  off_t i;
   Average *out;
 
@@ -156,7 +156,7 @@
 /* convert internal averages to panstarrs-format averages */
 // 'primary is needed to conform with the API for Loneos and Elixir, but is not used
-Average_Panstarrs_DEV_0 *AverageInternalTo_Panstarrs_DEV_0 (Average *in, int Nvalues, SecFilt *primary) {
-
-  int i;
+Average_Panstarrs_DEV_0 *AverageInternalTo_Panstarrs_DEV_0 (Average *in, off_t Nvalues, SecFilt *primary) {
+
+  off_t i;
   Average_Panstarrs_DEV_0 *out;
 
@@ -191,7 +191,7 @@
 
 /* convert panstarrs-format secfilts to internal secfilts */
-SecFilt *SecFilt_Panstarrs_DEV_0_ToInternal (SecFilt_Panstarrs_DEV_0 *in, int Nvalues) {
-
-  int i;
+SecFilt *SecFilt_Panstarrs_DEV_0_ToInternal (SecFilt_Panstarrs_DEV_0 *in, off_t Nvalues) {
+
+  off_t i;
   SecFilt *out;
 
@@ -213,7 +213,7 @@
 
 /* convert internal secfilts to panstarrs-format secfilts */
-SecFilt_Panstarrs_DEV_0 *SecFiltInternalTo_Panstarrs_DEV_0 (SecFilt *in, int Nvalues) {
-
-  int i;
+SecFilt_Panstarrs_DEV_0 *SecFiltInternalTo_Panstarrs_DEV_0 (SecFilt *in, off_t Nvalues) {
+
+  off_t i;
   SecFilt_Panstarrs_DEV_0 *out;
 
@@ -231,7 +231,7 @@
 
 /* convert panstarrs-format images to internal images */
-Image *Image_Panstarrs_DEV_0_ToInternal (Image_Panstarrs_DEV_0 *in, int Nvalues) {
-
-  int i;
+Image *Image_Panstarrs_DEV_0_ToInternal (Image_Panstarrs_DEV_0 *in, off_t Nvalues) {
+
+  off_t i;
   Image *out;
 
@@ -297,7 +297,7 @@
 
 /* convert internal images to panstarrs-format images */
-Image_Panstarrs_DEV_0 *ImageInternalTo_Panstarrs_DEV_0 (Image *in, int Nvalues) {
-
-  int i;
+Image_Panstarrs_DEV_0 *ImageInternalTo_Panstarrs_DEV_0 (Image *in, off_t Nvalues) {
+
+  off_t i;
   Image_Panstarrs_DEV_0 *out;
 
Index: trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 27435)
@@ -2,7 +2,7 @@
 
 /* convert panstarrs-format measures to internal measures */
-Measure *Measure_Panstarrs_DEV_1_ToInternal (Measure_Panstarrs_DEV_1 *in, int Nvalues) {
-
-  int i;
+Measure *Measure_Panstarrs_DEV_1_ToInternal (Measure_Panstarrs_DEV_1 *in, off_t Nvalues) {
+
+  off_t i;
   Measure *out;
 
@@ -66,7 +66,7 @@
 
 /* convert internal measures to panstarrs-format measures */
-Measure_Panstarrs_DEV_1 *MeasureInternalTo_Panstarrs_DEV_1 (Measure *in, int Nvalues) {
-
-  int i;
+Measure_Panstarrs_DEV_1 *MeasureInternalTo_Panstarrs_DEV_1 (Measure *in, off_t Nvalues) {
+
+  off_t i;
   Measure_Panstarrs_DEV_1 *out;
 
@@ -115,7 +115,7 @@
 /* convert panstarrs-format averages to internal averages */
 // 'primary is needed to conform with the API for Loneos and Elixir, but is not used
-Average *Average_Panstarrs_DEV_1_ToInternal (Average_Panstarrs_DEV_1 *in, int Nvalues, SecFilt **primary) {
-
-  int i;
+Average *Average_Panstarrs_DEV_1_ToInternal (Average_Panstarrs_DEV_1 *in, off_t Nvalues, SecFilt **primary) {
+
+  off_t i;
   Average *out;
 
@@ -156,7 +156,7 @@
 /* convert internal averages to panstarrs-format averages */
 // 'primary is needed to conform with the API for Loneos and Elixir, but is not used
-Average_Panstarrs_DEV_1 *AverageInternalTo_Panstarrs_DEV_1 (Average *in, int Nvalues, SecFilt *primary) {
-
-  int i;
+Average_Panstarrs_DEV_1 *AverageInternalTo_Panstarrs_DEV_1 (Average *in, off_t Nvalues, SecFilt *primary) {
+
+  off_t i;
   Average_Panstarrs_DEV_1 *out;
 
@@ -191,7 +191,7 @@
 
 /* convert panstarrs-format secfilts to internal secfilts */
-SecFilt *SecFilt_Panstarrs_DEV_1_ToInternal (SecFilt_Panstarrs_DEV_1 *in, int Nvalues) {
-
-  int i;
+SecFilt *SecFilt_Panstarrs_DEV_1_ToInternal (SecFilt_Panstarrs_DEV_1 *in, off_t Nvalues) {
+
+  off_t i;
   SecFilt *out;
 
@@ -213,7 +213,7 @@
 
 /* convert internal secfilts to panstarrs-format secfilts */
-SecFilt_Panstarrs_DEV_1 *SecFiltInternalTo_Panstarrs_DEV_1 (SecFilt *in, int Nvalues) {
-
-  int i;
+SecFilt_Panstarrs_DEV_1 *SecFiltInternalTo_Panstarrs_DEV_1 (SecFilt *in, off_t Nvalues) {
+
+  off_t i;
   SecFilt_Panstarrs_DEV_1 *out;
 
@@ -231,7 +231,7 @@
 
 /* convert panstarrs-format images to internal images */
-Image *Image_Panstarrs_DEV_1_ToInternal (Image_Panstarrs_DEV_1 *in, int Nvalues) {
-
-  int i;
+Image *Image_Panstarrs_DEV_1_ToInternal (Image_Panstarrs_DEV_1 *in, off_t Nvalues) {
+
+  off_t i;
   Image *out;
 
@@ -297,7 +297,7 @@
 
 /* convert internal images to panstarrs-format images */
-Image_Panstarrs_DEV_1 *ImageInternalTo_Panstarrs_DEV_1 (Image *in, int Nvalues) {
-
-  int i;
+Image_Panstarrs_DEV_1 *ImageInternalTo_Panstarrs_DEV_1 (Image *in, off_t Nvalues) {
+
+  off_t i;
   Image_Panstarrs_DEV_1 *out;
 
Index: trunk/Ohana/src/libdvo/src/dvo_image.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_image.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_image.c	(revision 27435)
@@ -52,5 +52,5 @@
   /* test for NAXIS == 2 in line 3 */
   bzero (buffer, 241);
-  fseek (db[0].f, 0, SEEK_SET);
+  fseeko (db[0].f, 0, SEEK_SET);
   Nread = fread (buffer, 1, 240, db[0].f);
   if (Nread != 240) {
@@ -63,5 +63,5 @@
     return (FALSE);
   }
-  fseek (db[0].f, 0, SEEK_SET);
+  fseeko (db[0].f, 0, SEEK_SET);
 
   /* default values */
@@ -114,13 +114,13 @@
 }
 
-int dvo_image_addrows (FITS_DB *db, Image *new, int Nnew) {
-
-  int Nimages;
+int dvo_image_addrows (FITS_DB *db, Image *new, off_t Nnew) {
+
+  off_t Nimages;
 
   /* adjust header */
   Nimages = 0;
-  gfits_scan (&db[0].header, "NIMAGES", "%d", 1, &Nimages);
+  gfits_scan (&db[0].header, "NIMAGES", "%lld", 1, (long long *) &Nimages);
   Nimages += Nnew;
-  gfits_modify (&db[0].header, "NIMAGES", "%d", 1, Nimages);
+  gfits_modify (&db[0].header, "NIMAGES", "%lld", 1, (long long) Nimages);
 
   gfits_table_to_vtable (&db[0].ftable, &db[0].vtable, 0, 0);
@@ -195,5 +195,5 @@
   gfits_table_set_Image (&db[0].ftable, NULL, 0);
 
-  gfits_modify (&db[0].header, "NIMAGES", "%d", 1, 0);
+  gfits_modify (&db[0].header, "NIMAGES", "%lld", 1, 0LL);
   gfits_modify (&db[0].header, "ZERO_PT", "%lf", 1, ZeroPoint);
 
Index: trunk/Ohana/src/libdvo/src/dvo_image_raw.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_image_raw.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_image_raw.c	(revision 27435)
@@ -7,5 +7,5 @@
 int dvo_image_load_raw (FITS_DB *db, int VERBOSE, int FORCE_READ) {
 
-  int Nimage, Ndata, size, ImageSize, nbytes, Nbytes;
+  off_t Nimage, Ndata, size, ImageSize, nbytes, Nbytes;
   struct stat filestatus;
   char format[80], telescope[80];
@@ -39,5 +39,5 @@
   /* find number of images */
   Nimage = 0;
-  gfits_scan (&db[0].header, "NIMAGES", "%d", 1, &Nimage);
+  gfits_scan (&db[0].header, "NIMAGES", "%lld", 1, (long long *) &Nimage);
   if (stat (db[0].filename, &filestatus) == -1) {
     if (VERBOSE) fprintf (stderr, "ERROR: failed to get status of image catalog\n");
@@ -59,9 +59,9 @@
 
   /* check that filesize makes sense */
-  size = Nimage*ImageSize + db[0].header.size;
+  size = Nimage*ImageSize + db[0].header.datasize;
   if (size != filestatus.st_size) {
-    Ndata = (filestatus.st_size - db[0].header.size) / ImageSize;
+    Ndata = (filestatus.st_size - db[0].header.datasize) / ImageSize;
     if (VERBOSE) fprintf (stderr, "ERROR: image catalog has inconsistent size\n");
-    if (VERBOSE) fprintf (stderr, "header: %d, data: %d\n", Nimage, Ndata);
+    if (VERBOSE) fprintf (stderr, "header: %lld, data: %lld\n", (long long) Nimage, (long long) Ndata);
     if (!FORCE_READ) exit (1);
     Nimage = Ndata;
@@ -94,7 +94,7 @@
   } 
 
-  gfits_modify (&db[0].theader, "NAXIS2", "%d", 1, Nimage);
+  gfits_modify (&db[0].theader, "NAXIS2", "%lld", 1, (long long) Nimage);
   db[0].theader.Naxis[1] = Nimage;
-  db[0].ftable.size = gfits_data_size (&db[0].theader);
+  db[0].ftable.datasize = gfits_data_size (&db[0].theader);
   db[0].swapped = FALSE;  /* table does not have internal byte-order */
   return (TRUE);
@@ -104,16 +104,16 @@
 int dvo_image_update_raw (FITS_DB *db, int VERBOSE) {
 
-  int i, Nx, Ny, Nrow, Nbytes;
-  int status, start, offset;
-  int *row;
+  off_t i, Nx, Ny, Nrow, Nbytes, start, offset;
+  off_t status;
+  off_t *row;
 
-  if (VERBOSE) fprintf (stderr, "writing out %d images\n", db[0].vtable.Nrow);
+  if (VERBOSE) fprintf (stderr, "writing out %lld images\n", (long long) db[0].vtable.Nrow);
 
   /* position to start of file */
-  Fseek (db[0].f, 0, SEEK_SET);
+  fseeko (db[0].f, 0, SEEK_SET);
   
   /* write out complete header (no check on disk size?) */
-  status = fwrite (db[0].header.buffer, 1, db[0].header.size, db[0].f);
-  if (status != db[0].header.size) {
+  status = fwrite (db[0].header.buffer, 1, db[0].header.datasize, db[0].f);
+  if (status != db[0].header.datasize) {
     fprintf (stderr, "ERROR: failed writing data to image header\n");
     exit (1);
@@ -123,6 +123,6 @@
   Nrow = db[0].vtable.Nrow;
   row = db[0].vtable.row;
-  gfits_scan (db[0].vtable.header, "NAXIS1", "%d", 1, &Nx);
-  gfits_scan (db[0].vtable.header, "NAXIS2", "%d", 1, &Ny);
+  gfits_scan (db[0].vtable.header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (db[0].vtable.header, "NAXIS2", "%lld", 1, (long long *) &Ny);
 
   /* file pointer is at beginning of desired table data */
@@ -131,5 +131,5 @@
   for (i = 0; i < Nrow; i++) {
     offset = start + Nx*row[i];
-    fseek (db[0].f, offset, SEEK_SET);
+    fseeko (db[0].f, offset, SEEK_SET);
     Nbytes = fwrite (db[0].vtable.buffer[i], sizeof (char), Nx, db[0].f);
     if (Nbytes != Nx) { return (FALSE); }
@@ -141,7 +141,8 @@
 int dvo_image_save_raw (FITS_DB *db, int VERBOSE) {
 
-  int status, Nx, Ny, size, Nbytes;
+  off_t Nx, Ny, size, Nbytes;
+  int status;
 
-  if (VERBOSE) fprintf (stderr, "writing out %d images\n", db[0].theader.Naxis[1]);
+  if (VERBOSE) fprintf (stderr, "writing out %lld images\n", (long long) db[0].theader.Naxis[1]);
 
   /* position to start of file */
@@ -149,12 +150,12 @@
   
   /* write out complete header (no check on disk size?) */
-  status = fwrite (db[0].header.buffer, 1, db[0].header.size, db[0].f);
-  if (status != db[0].header.size) {
+  status = fwrite (db[0].header.buffer, 1, db[0].header.datasize, db[0].f);
+  if (status != db[0].header.datasize) {
     fprintf (stderr, "ERROR: failed writing data to image header\n");
     exit (1);
   }
 
-  gfits_scan (db[0].ftable.header, "NAXIS1", "%d", 1, &Nx);
-  gfits_scan (db[0].ftable.header, "NAXIS2", "%d", 1, &Ny);
+  gfits_scan (db[0].ftable.header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (db[0].ftable.header, "NAXIS2", "%lld", 1, (long long *) &Ny);
   size = Nx * Ny;
   Nbytes = fwrite (db[0].ftable.buffer, sizeof(char), size, db[0].f);
Index: trunk/Ohana/src/libdvo/src/dvo_util.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_util.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvo_util.c	(revision 27435)
@@ -18,4 +18,5 @@
 
     memset(config, 0, sizeof(dvoConfig));
+    return config;
 }
 
@@ -98,5 +99,5 @@
     }
 
-    char *catdir, filename[256];
+    char filename[256];
   
     sprintf (filename, "%s/Images.dat", dvoConfig->catdir);
@@ -136,6 +137,4 @@
 Image *dvoImageByExternID(dvoConfig *dvoConfig, int sourceID, int externID)
 {
-    Image *images;
-    int Nimage;
     int i;
     
@@ -199,12 +198,9 @@
 }
 
-int dvoGetDetections(SkyList *skylist, int imageID, dvoDetection **results, int *pMaxDetID)
-{
-  int QUIET = 0;
-  int FULL_OUTPUT = 0;
+off_t dvoGetDetections(SkyList *skylist, int imageID, dvoDetection **results, int *pMaxDetID)
+{
   int GetMeasures = 1;
-  int SaveVectors = 0;
   int reg;
-  int Ndetect = 0;
+  off_t Ndetect = 0;
 
   int detectionsArrayLength = 1000;
@@ -226,8 +222,7 @@
       dvo_catalog_unlock (&catalog);
 
-      int Nstars = catalog.Naverage;
-      int Nmeasure = catalog.Nmeasure;
-
-      int i;
+      off_t Nmeasure = catalog.Nmeasure;
+
+      off_t i;
       for (i=0; i< Nmeasure; i++) {
         Measure *m = catalog.measure + i;
@@ -265,5 +260,5 @@
 
       memset(sorted, 0, sizeof(dvoDetection) * *pMaxDetID);
-      int i;
+      off_t i;
       for (i = 0; i < Ndetect; i++) {
            sorted[detections[i].meas.detID] = detections[i];
Index: trunk/Ohana/src/libdvo/src/dvosorts.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvosorts.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/dvosorts.c	(revision 27435)
@@ -4,5 +4,5 @@
 
 /* values are ave[i].R, ave[i].D, ave[i].M */
-void sortave (Average *ave, int N) {
+void sortave (Average *ave, off_t N) {
 
 # define SWAPFUNC(A,B){ Average tmp; tmp = ave[A]; ave[A] = ave[B]; ave[B] = tmp; }
@@ -17,5 +17,5 @@
 
 /* sort subset by image[subset[i]].tzero */
-void sort_image_subset (Image *image, int *subset, int N) {
+void sort_image_subset (Image *image, off_t *subset, off_t N) {
 
 # define SWAPFUNC(A,B){ int tmp; tmp = subset[A]; subset[A] = subset[B]; subset[B] = tmp; }
@@ -30,7 +30,7 @@
 
 /* sort a coordinate pair (X,Y) and the associated index (S) */
-void sort_coords_index (double *X, double *Y, int *S, int N) {
+void sort_coords_index (double *X, double *Y, off_t *S, off_t N) {
   
-# define SWAPFUNC(A,B){ double dtmp; int itmp; \
+# define SWAPFUNC(A,B){ double dtmp; off_t itmp; \
   dtmp = X[A]; X[A] = X[B]; X[B] = dtmp; \
   dtmp = Y[A]; Y[A] = Y[B]; Y[B] = dtmp; \
@@ -46,5 +46,5 @@
 }
 
-void sort_regions (SkyRegion *region, int N) {
+void sort_regions (SkyRegion *region, off_t N) {
 
 # define SWAPFUNC(A,B){ SkyRegion tmp; tmp = region[A]; region[A] = region[B]; region[B] = tmp; }
@@ -57,17 +57,2 @@
 
 }
-
-# if (0)
-// deprecated along with Stars as an autocode type
-void sort_stars_ra (Stars *stars, int N) {
-
-# define SWAPFUNC(A,B){ Stars tmp; tmp = stars[A]; stars[A] = stars[B]; stars[B] = tmp; }
-# define COMPARE(A,B)(stars[A].R < stars[B].R)
-
-  OHANA_SORT (N, COMPARE, SWAPFUNC);
-
-# undef SWAPFUNC
-# undef COMPARE
-
-}
-# endif
Index: trunk/Ohana/src/libdvo/src/fits_db.c
===================================================================
--- trunk/Ohana/src/libdvo/src/fits_db.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/fits_db.c	(revision 27435)
@@ -92,8 +92,8 @@
 }
 
-/* load the data from Nrows from table starting at start; load header, etc if needed */
-int gfits_db_load_segment (FITS_DB *db, int start, int Nrows) {
-
-  int Nskip;
+/* load the Nrows data from table starting at start; load header, etc if needed */
+int gfits_db_load_segment (FITS_DB *db, off_t start, off_t Nrows) {
+
+  off_t Nskip;
 
   /* database name must be set first */
@@ -119,5 +119,5 @@
     }
   } else {
-    Nskip = db[0].header.size;
+    Nskip = db[0].header.datasize;
     Fseek (db[0].f, Nskip, SEEK_CUR);
   }
@@ -141,5 +141,5 @@
     }
   } else {
-    Nskip = db[0].header.size;
+    Nskip = db[0].header.datasize;
     Fseek (db[0].f, Nskip, SEEK_CUR);
   }
Index: trunk/Ohana/src/libdvo/src/mosaic_astrom.c
===================================================================
--- trunk/Ohana/src/libdvo/src/mosaic_astrom.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/mosaic_astrom.c	(revision 27435)
@@ -1,19 +1,22 @@
 # include <dvo.h>
 
+off_t getDISentry (e_time start, e_time stop, e_time *startMos, off_t *indexMos, off_t Nmosaic);
+void SortDISindex (e_time *S, off_t *I, off_t N);
+
 /* chip-match table: j = ChipMatch[i], images[j] is DIS for images[i] WRP */
 
-static int    iDIS = -1;      // DIS entry in ChipMatch[]
-static int    Ndis = 0;
-static int    *DISentry = NULL;
+static off_t  iDIS = -1;      // DIS entry in ChipMatch[]
+static off_t  Ndis = 0;
+static off_t  *DISentry = NULL;
 static e_time *DIStzero = NULL;
-static int    *ChipMatch = NULL;
+static off_t  *ChipMatch = NULL;
 
 /* what is the currently registered mosaic image? */
-int GetRegisteredMosaic () {
+off_t GetRegisteredMosaic () {
   return (iDIS);
 }
 
 /* given an image array and a current entry of type WRP, find matching DIS & Register it */
-int FindMosaicForImage (Image *images, int Nimages, int entry) {
+int FindMosaicForImage (Image *images, off_t Nimages, off_t entry) {
 
   int status;
@@ -28,8 +31,8 @@
 
 /* given an image array and a current entry of type WRP, find matching DIS & Register it */
-int FindMosaicForImage_TableSearch (Image *images, int Nimages, int entry) {
+int FindMosaicForImage_TableSearch (Image *images, off_t Nimages, off_t entry) {
 
   e_time tzero;
-  int i;
+  off_t i;
 
   /* search backwards for image with same time and type DIS */
@@ -65,11 +68,11 @@
 
 /* given an image array and a current entry of type WRP, find matching DIS & Register it */
-int FindMosaicForImage_MatchSearch (Image *images, int Nimages, int entry) {
-
-  int N;
+int FindMosaicForImage_MatchSearch (Image *images, off_t Nimages, off_t entry) {
+
+  off_t N;
 
   if (strcmp(&images[entry].coords.ctype[4], "-WRP")) {
     /* not a wrp image, do nothing */
-    return (TRUE); /* error or not */
+    return (TRUE); /* error or not? */
   }
 
@@ -85,7 +88,7 @@
 }
 
-int BuildChipMatch (Image *images, int Nimages) {
-
-  int i, j, NDIS;
+int BuildChipMatch_old (Image *images, off_t Nimages) {
+
+  off_t i, j, NDIS;
 
   if (DISentry != NULL) free (DISentry);
@@ -96,5 +99,5 @@
   Ndis = 0;
   NDIS = 100;
-  ALLOCATE (DISentry, int, NDIS);
+  ALLOCATE (DISentry, off_t, NDIS);
   ALLOCATE (DIStzero, e_time, NDIS);
 
@@ -106,5 +109,5 @@
     if (Ndis >= NDIS) {
       NDIS += 100;
-      REALLOCATE (DISentry, int, NDIS);
+      REALLOCATE (DISentry, off_t, NDIS);
       REALLOCATE (DIStzero, e_time, NDIS);
     }
@@ -112,5 +115,5 @@
 
   /* find all matched WRP images */
-  ALLOCATE (ChipMatch, int, Nimages);
+  ALLOCATE (ChipMatch, off_t, Nimages);
   for (i = 0; i < Nimages; i++) {
     ChipMatch[i] = -1;
@@ -131,2 +134,97 @@
   return (TRUE);
 }
+
+int BuildChipMatch (Image *images, off_t Nimages) {
+
+  off_t i, j, NDIS;
+
+  if (DISentry != NULL) free (DISentry);
+  if (DIStzero != NULL) free (DIStzero);
+  if (ChipMatch != NULL) free (ChipMatch);
+
+  // allocate containers for DIS indexing
+  Ndis = 0;
+  NDIS = 100;
+  ALLOCATE (DISentry, off_t, NDIS);
+  ALLOCATE (DIStzero, e_time, NDIS);
+
+  // find all DIS images, save tzero (& instrument) 
+  for (i = 0; i < Nimages; i++) {
+    if (strcmp(&images[i].coords.ctype[4], "-DIS")) continue;
+    DISentry[Ndis] = i;
+    DIStzero[Ndis] = images[i].tzero;
+    Ndis ++;
+    if (Ndis >= NDIS) {
+      NDIS += 100;
+      REALLOCATE (DISentry, off_t, NDIS);
+      REALLOCATE (DIStzero, e_time, NDIS);
+    }
+  }
+
+  // sort the index, start, and stop by the start times:
+  SortDISindex (DIStzero, DISentry, Ndis);
+
+  /* find all matched WRP images */
+  ALLOCATE (ChipMatch, off_t, Nimages);
+  for (i = 0; i < Nimages; i++) {
+    ChipMatch[i] = -1;
+    if (strcmp(&images[i].coords.ctype[4], "-WRP")) continue;
+
+    j = getDISentry (images[i].tzero, images[i].tzero + (int) images[i].exptime, DIStzero, DISentry, Ndis);
+    if (j == -1) {
+      fprintf (stderr, "WARNING: can't find matching mosaic \n");
+      ChipMatch[i] = -2;
+      continue;
+    }
+    if (j >= Nimages) abort();
+
+    ChipMatch[i] = j;
+  }
+  return (TRUE);
+}
+
+off_t getDISentry (e_time start, e_time stop, e_time *startMos, off_t *indexMos, off_t Nmosaic) {
+
+  // use bisection to find the overlapping mosaic
+
+  off_t Nlo, Nhi, N;
+
+  // find the last mosaic before start
+  Nlo = 0; Nhi = Nmosaic;
+  while (Nhi - Nlo > 10) {
+    N = 0.5*(Nlo + Nhi);
+    if (startMos[N] < start) {
+      Nlo = MAX(N, 0);
+    } else {
+      Nhi = MIN(N + 1, Nmosaic);
+    }
+  }
+
+  // check for the matched mosaic starting from Nlo 
+  // we may have to go much beyond Nlo since stop is not sorted
+  // can we use a sorted version of stop to check when we are beyond the valid range??
+  for (N = Nlo; N < Nmosaic; N++) { 
+    if (startMos[N] < start) continue;
+    if (startMos[N] > stop) return (-1);
+    return (indexMos[N]);
+  }
+
+  return (-1);
+}
+
+// sort two times vectors and an index by first time vector
+void SortDISindex (e_time *S, off_t *I, off_t N) {
+
+# define SWAPFUNC(A,B){ e_time tmp_t; off_t tmp_i; \
+  tmp_t = S[A]; S[A] = S[B]; S[B] = tmp_t; \
+  tmp_i = I[A]; I[A] = I[B]; I[B] = tmp_i; \
+}
+# define COMPARE(A,B)(S[A] < S[B])
+
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+
+}
+
Index: trunk/Ohana/src/libdvo/src/skyregion_io.c
===================================================================
--- trunk/Ohana/src/libdvo/src/skyregion_io.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/skyregion_io.c	(revision 27435)
@@ -126,4 +126,10 @@
 
   /* third option: GSCFILE */
+
+  if (gscfile == NULL) {
+    fprintf (stderr, "error loading sky table from existing db (%s)\n", catdir);
+    return (NULL);
+  }
+
   sky = SkyTableFromGSC (gscfile, depth, verbose);
   if (sky == NULL) {
Index: trunk/Ohana/src/libdvo/src/skyregion_ops.c
===================================================================
--- trunk/Ohana/src/libdvo/src/skyregion_ops.c	(revision 27392)
+++ trunk/Ohana/src/libdvo/src/skyregion_ops.c	(revision 27435)
@@ -386,7 +386,5 @@
 SkyList *SkyListChildrenByBounds_List (SkyList *table, int depth, double Rmin, double Rmax, double Dmin, double Dmax) {
 
-  int i, j, Ns, Ne, Nnew, NNEW;
-  int append;
-  SkyList *children;
+  int i, Nnew, NNEW;
   SkyList *list;
   SkyRegion **region;
Index: trunk/Ohana/src/libfits/header/F_H_field.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_H_field.c	(revision 27392)
+++ trunk/Ohana/src/libfits/header/F_H_field.c	(revision 27435)
@@ -6,6 +6,9 @@
 
   char *buf;
-  int i, Nwant, Nfound;
+  off_t i;
+  int Nwant, Nfound;
   char keyword[10];
+
+  if (header[0].buffer == NULL) return NULL;
 
   /* create a blank-padded keyword with exactly 8 characters */
@@ -19,5 +22,5 @@
     /* find the Nth entry */
     Nfound = 0;
-    for (i = 0; i < header[0].size; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
+    for (i = 0; i < header[0].datasize; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
       if (!strncmp (keyword, buf, 8)) {
 	Nfound ++;
@@ -30,5 +33,5 @@
     /* count the entries */
     Nfound = 0;
-    for (i = 0; i < header[0].size; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
+    for (i = 0; i < header[0].datasize; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
       if (!strncmp (keyword, buf, 8)) {
 	Nfound ++;
@@ -41,5 +44,5 @@
     /* find the Nwant entry */
     Nfound = 0;
-    for (i = 0; i < header[0].size; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
+    for (i = 0; i < header[0].datasize; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
       if (!strncmp (keyword, buf, 8)) {
 	Nfound ++;
@@ -50,5 +53,5 @@
   }
 
-  return ((char *) NULL);
+  return NULL;
 
 /* 
@@ -66,5 +69,8 @@
 
   char *buf, *ptr;
-  int i, Nwant, Nfound, Nfield;
+  off_t i;
+  int Nwant, Nfound, Nfield;
+
+  if (header[0].buffer == NULL) return NULL;
 
   Nfield = strlen (field);
@@ -76,5 +82,5 @@
   if (N > 0) {
     Nfound = 0;
-    for (i = 0; i < header[0].size; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
+    for (i = 0; i < header[0].datasize; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
       // have we found a HIERARCH entry?
       if (strncmp ("HIERARCH", buf, 8)) continue;
@@ -90,5 +96,5 @@
     /* count the entries */
     Nfound = 0;
-    for (i = 0; i < header[0].size; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
+    for (i = 0; i < header[0].datasize; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
       if (strncmp ("HIERARCH", buf, 8)) continue;
       ptr = buf + 9; // start of following keyword
@@ -102,5 +108,5 @@
     /* find the Nwant entry */
     Nfound = 0;
-    for (i = 0; i < header[0].size; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
+    for (i = 0; i < header[0].datasize; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
       if (strncmp ("HIERARCH", buf, 8)) continue;
       ptr = buf + 9; // start of following keyword
@@ -111,5 +117,5 @@
   }
 
-  return ((char *) NULL);
+  return NULL;
 
 /* 
@@ -122,9 +128,9 @@
 
 /*********************** fits header field ****************************/
-char *gfits_header_lineno (Header *header, int N) {
+char *gfits_header_lineno (Header *header, off_t N) {
 
   char *buf;
 
-  if (N*80 >= header[0].size) return NULL;
+  if (N*80 >= header[0].datasize) return NULL;
 
   buf = &header[0].buffer[N*80];
Index: trunk/Ohana/src/libfits/header/F_copy_H.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_copy_H.c	(revision 27392)
+++ trunk/Ohana/src/libfits/header/F_copy_H.c	(revision 27435)
@@ -16,5 +16,5 @@
     out[0].Naxis[i] = in[0].Naxis[i];
 
-  out[0].size   = in[0].size;
+  out[0].datasize = in[0].datasize;
 
   out[0].pcount = in[0].pcount;
@@ -24,7 +24,7 @@
 
   if (out[0].buffer != NULL) free (out[0].buffer);
-  ALLOCATE (out[0].buffer, char, out[0].size);
+  ALLOCATE (out[0].buffer, char, out[0].datasize);
   
-  strncpy (out[0].buffer, in[0].buffer, out[0].size);
+  memcpy (out[0].buffer, in[0].buffer, out[0].datasize);
 
   return (TRUE);
Index: trunk/Ohana/src/libfits/header/F_create_H.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_create_H.c	(revision 27392)
+++ trunk/Ohana/src/libfits/header/F_create_H.c	(revision 27435)
@@ -9,5 +9,5 @@
   char axis[10];
   
-  header[0].size = NBYTES;
+  header[0].datasize = NBYTES;
 
   ALLOCATE (header[0].buffer, char, NBYTES);
@@ -17,5 +17,5 @@
   strncpy (header[0].buffer, "END", 3);
 
-  gfits_modify (header, "SIMPLE", "%t", 1, header[0].simple);
+  gfits_modify_alt (header, "SIMPLE", "%t", 1, header[0].simple);
   gfits_modify (header, "BITPIX", "%d", 1, header[0].bitpix);
   gfits_modify (header, "NAXIS",  "%d", 1, header[0].Naxes);
@@ -23,5 +23,5 @@
   for (i = 0; i < header[0].Naxes; i++) {
     snprintf (axis, 10, "NAXIS%d", i + 1);
-    gfits_modify (header,  axis, "%d", 1, header[0].Naxis[i]);
+    gfits_modify (header,  axis, "%lld", 1, (long long) header[0].Naxis[i]);
   }
 
@@ -30,5 +30,5 @@
   gfits_modify (header, "BSCALE", "%lf", 1, header[0].bscale);
   gfits_modify (header, "BZERO",  "%lf", 1, header[0].bzero);
-  gfits_modify (header, "EXTEND", "%t",  1, header[0].extend);
+  gfits_modify_alt (header, "EXTEND", "%t",  1, header[0].extend);
   return (TRUE);
 
Index: trunk/Ohana/src/libfits/header/F_delete.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_delete.c	(revision 27392)
+++ trunk/Ohana/src/libfits/header/F_delete.c	(revision 27435)
@@ -5,5 +5,6 @@
 int gfits_delete (Header *header, char *field, int N) {
   
-  int i, Nbytes;
+  int i;
+  off_t Nbytes;
   char *p1, *p2;
   
@@ -22,7 +23,7 @@
 
   p2 = gfits_header_field (header, "END", 1);
-  if (header[0].size - (p2 - header[0].buffer + FT_LINE_LENGTH) > FT_RECORD_SIZE) {
-    header[0].size -= FT_RECORD_SIZE;
-    REALLOCATE (header[0].buffer, char, header[0].size);
+  if (header[0].datasize - (p2 - header[0].buffer + FT_LINE_LENGTH) > FT_RECORD_SIZE) {
+    header[0].datasize -= FT_RECORD_SIZE;
+    REALLOCATE (header[0].buffer, char, header[0].datasize);
   }
   return (TRUE);
Index: trunk/Ohana/src/libfits/header/F_modify.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_modify.c	(revision 27392)
+++ trunk/Ohana/src/libfits/header/F_modify.c	(revision 27435)
@@ -2,4 +2,5 @@
 # include <gfitsio.h>
 
+// this is only valid for the regular and non-boolean fields
 int gfits_modify (Header *header, char *field, char *mode, int N,...) {
   
@@ -8,5 +9,5 @@
 
   char comment[82], string[82], data[82];
-  char *p, *qs, *qe;
+  char *p, *qe;
   va_list argp;
   
@@ -29,7 +30,7 @@
     
     /* is there enough space for 1 more line? */
-    if (header[0].size - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) {
-      header[0].size += FT_RECORD_SIZE;
-      REALLOCATE (header[0].buffer, char, header[0].size);
+    if (header[0].datasize - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) {
+      header[0].datasize += FT_RECORD_SIZE;
+      REALLOCATE (header[0].buffer, char, header[0].datasize);
       p = gfits_header_field (header, "END", 1);
       if (p == NULL) return (FALSE); 
@@ -50,14 +51,79 @@
 
   /* write the numeric modes */
-  if (!strcmp (mode, "%d"))  snprintf (string, 81, "%-8s= %20d / %-s ",     field, va_arg (argp, int),      comment);
-  if (!strcmp (mode, "%u"))  snprintf (string, 81, "%-8s= %20d / %-s ",     field, va_arg (argp, unsigned), comment);
-  if (!strcmp (mode, "%ld")) snprintf (string, 81, "%-8s= %20ld / %-s ",    field, va_arg (argp, long),     comment);
-  if (!strcmp (mode, "%hd")) snprintf (string, 81, "%-8s= %20d / %-s ",     field, va_arg (argp, int),      comment);
-  if (!strcmp (mode, "%f"))  snprintf (string, 81, "%-8s= %20.10f / %-s ",  field, va_arg (argp, double),   comment); 
-  if (!strcmp (mode, "%lf")) snprintf (string, 81, "%-8s= %20.10f / %-s ",  field, va_arg (argp, double),   comment); 
-  if (!strcmp (mode, "%e"))  snprintf (string, 81, "%-8s= %20.10E / %-s ",  field, va_arg (argp, double),   comment); 
-  if (!strcmp (mode, "%le")) snprintf (string, 81, "%-8s= %20.10E / %-s ",  field, va_arg (argp, double),   comment); 
-  if (!strcmp (mode, "%g"))  snprintf (string, 81, "%-8s= %20.10G / %-s ",  field, va_arg (argp, double),   comment); 
-  if (!strcmp (mode, "%lg")) snprintf (string, 81, "%-8s= %20.10G / %-s ",  field, va_arg (argp, double),   comment); 
+  if (!strcmp (mode, "%d"))   snprintf (string, 81, "%-8s= %20d / %-s ",    field, va_arg (argp, int),       	      comment);
+  if (!strcmp (mode, "%ld"))  snprintf (string, 81, "%-8s= %20ld / %-s ",   field, va_arg (argp, long),      	      comment);
+  if (!strcmp (mode, "%lld")) snprintf (string, 81, "%-8s= %20lld / %-s ",  field, va_arg (argp, long long), 	      comment);
+  if (!strcmp (mode, "%Ld"))  snprintf (string, 81, "%-8s= %20lld / %-s ",  field, va_arg (argp, long long), 	      comment);
+  if (!strcmp (mode, "%u"))   snprintf (string, 81, "%-8s= %20u / %-s ",    field, va_arg (argp, unsigned),  	      comment);
+  if (!strcmp (mode, "%lu"))  snprintf (string, 81, "%-8s= %20lu / %-s ",   field, va_arg (argp, unsigned long),      comment);
+  if (!strcmp (mode, "%llu")) snprintf (string, 81, "%-8s= %20llu / %-s ",  field, va_arg (argp, unsigned long long), comment);
+  if (!strcmp (mode, "%Lu"))  snprintf (string, 81, "%-8s= %20llu / %-s ",  field, va_arg (argp, unsigned long long), comment);
+  if (!strcmp (mode, "%hd"))  snprintf (string, 81, "%-8s= %20d / %-s ",    field, va_arg (argp, int),      	      comment); 
+  if (!strcmp (mode, "%f"))   snprintf (string, 81, "%-8s= %20.10f / %-s ", field, va_arg (argp, double),   	      comment); 
+  if (!strcmp (mode, "%lf"))  snprintf (string, 81, "%-8s= %20.10f / %-s ", field, va_arg (argp, double),   	      comment); 
+  if (!strcmp (mode, "%e"))   snprintf (string, 81, "%-8s= %20.10E / %-s ", field, va_arg (argp, double),   	      comment); 
+  if (!strcmp (mode, "%le"))  snprintf (string, 81, "%-8s= %20.10E / %-s ", field, va_arg (argp, double),   	      comment); 
+  if (!strcmp (mode, "%g"))   snprintf (string, 81, "%-8s= %20.10G / %-s ", field, va_arg (argp, double),   	      comment); 
+  if (!strcmp (mode, "%lg"))  snprintf (string, 81, "%-8s= %20.10G / %-s ", field, va_arg (argp, double),   	      comment); 
+
+  /* string value.  Quotes must be at least 18 chars apart */
+  if (!strcmp (mode, "%s")) {
+    strncpy (data, va_arg (argp, char *), 68);
+    snprintf (string, 81, "%-8s= '%-18s' / %-s ", field, data, comment);
+  }
+
+  strncpy (p, string, 80);
+  va_end (argp);
+  return (TRUE);
+
+}
+
+// alternate version for the special types (boolean, comments, COMMENT)
+int gfits_modify_alt (Header *header, char *field, char *mode, int N,...) {
+  
+  /* this function expects one more argument, the value to be written */
+  /* this function is extremely similar to gfits_print, except it allows for changing an existing field. */
+
+  char comment[82], string[82], data[82];
+  char *p, *qs, *qe;
+  va_list argp;
+  
+  va_start (argp, N);
+  bzero (data, 82);
+  bzero (string, 82);
+  bzero (comment, 82);
+
+  if (mode[0] != '%') {
+    fprintf (stderr, "gfits_print: weird mode:  %s\n", mode);
+    return (FALSE);
+  }
+
+  /* find location of desired entry */
+  p = gfits_header_field (header, field, N);
+  if (p == NULL)  {
+    /* new entry, find the END of the header */
+    p = gfits_header_field (header, "END", 1);
+    if (p == NULL) return (FALSE); 
+    
+    /* is there enough space for 1 more line? */
+    if (header[0].datasize - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) {
+      header[0].datasize += FT_RECORD_SIZE;
+      REALLOCATE (header[0].buffer, char, header[0].datasize);
+      p = gfits_header_field (header, "END", 1);
+      if (p == NULL) return (FALSE); 
+      memset (p + FT_LINE_LENGTH, ' ', FT_RECORD_SIZE);
+    }
+    
+    /* push END line back 1 */
+    memmove ((p + FT_LINE_LENGTH), p, FT_LINE_LENGTH);
+    memset (p, ' ', FT_LINE_LENGTH);
+  } else {
+    /* old entry, save the comment region (is this skipping a character for non-strings?) */
+    qe = gfits_keyword_end (p);
+    qe += 3;
+    qe = MIN (p + 80, qe);
+    strncpy (comment, qe, p + 80 - qe);
+  }
+  gfits_pad_ending (comment, ' ', 82);  /* comment must contain spaces to the end */
 
   /* write the boolean mode */
@@ -67,10 +133,4 @@
     else
       snprintf (string, 81, "%-8s= %18s F / %-s ", field, " ", comment);
-  }
-
-  /* string value.  Quotes must be at least 18 chars apart */
-  if (!strcmp (mode, "%s")) {
-    strncpy (data, va_arg (argp, char *), 68);
-    snprintf (string, 81, "%-8s= '%-18s' / %-s ", field, data, comment);
   }
 
Index: trunk/Ohana/src/libfits/header/F_print.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_print.c	(revision 27392)
+++ trunk/Ohana/src/libfits/header/F_print.c	(revision 27435)
@@ -2,5 +2,80 @@
 # include <gfitsio.h>
 
+// this only prints the regular and non-boolean fields
 int gfits_print (Header *header, char *field, char *mode, int N,...) {
+  
+  /* this function expects one more argument, the value to be written */
+
+  static char blank[] = " ";
+  char string[82], line[80];
+  char *p;
+  va_list argp;  
+
+  va_start (argp, N);
+  
+  if (mode[0] != '%') {
+    fprintf (stderr, "gfits_print: weird mode:  %s\n", mode);
+    return (FALSE);
+  }
+
+  /* this is supposed to create a new field, not modify an old one.  */
+  p = gfits_header_field (header, field, N);
+  if (p != NULL) return (FALSE);
+
+  /* find the END of the header */
+  p = gfits_header_field (header, "END", 1);
+  if (p == NULL) return (FALSE); 
+
+  /* is there enough space for 1 more line? */
+  if (header[0].datasize - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) {
+    header[0].datasize += FT_RECORD_SIZE;
+    REALLOCATE (header[0].buffer, char, header[0].datasize);
+    /* re-find the "END" marker, in case new memory block is used */
+    p = gfits_header_field (header, "END", 1);
+    if (p == NULL) return (FALSE); 
+    memset (p + FT_LINE_LENGTH, ' ', FT_RECORD_SIZE);
+  }
+
+  /* push END line back 1 */
+  memmove ((p + FT_LINE_LENGTH), p, FT_LINE_LENGTH);
+  memset (p, ' ', FT_LINE_LENGTH);
+
+  /* write the new FITS card, setting the comment to be blank */
+  /* in these lines, the value field will expand as needed, forcing out the comment
+     the total line is limited by snprintf to only 80 chars + EOL */
+
+  /* write the numeric modes */
+  if (!strcmp (mode, "%d"))  { snprintf (string, 81, "%-8s= %20d / %46s ",    field, va_arg (argp, int),                blank); }
+  if (!strcmp (mode, "%ld")) { snprintf (string, 81, "%-8s= %20ld / %46s ",   field, va_arg (argp, long),               blank); }
+  if (!strcmp (mode, "%lld")){ snprintf (string, 81, "%-8s= %20lld / %46s ",  field, va_arg (argp, long long),          blank); }
+  if (!strcmp (mode, "%Ld")) { snprintf (string, 81, "%-8s= %20lld / %46s ",  field, va_arg (argp, long long),          blank); }
+  if (!strcmp (mode, "%u"))  { snprintf (string, 81, "%-8s= %20u / %46s ",    field, va_arg (argp, unsigned),           blank); }
+  if (!strcmp (mode, "%lu")) { snprintf (string, 81, "%-8s= %20lu / %46s ",   field, va_arg (argp, unsigned long),      blank); }
+  if (!strcmp (mode, "%llu")){ snprintf (string, 81, "%-8s= %20llu / %46s ",  field, va_arg (argp, unsigned long long), blank); }
+  if (!strcmp (mode, "%Lu")) { snprintf (string, 81, "%-8s= %20llu / %46s ",  field, va_arg (argp, unsigned long long), blank); }
+  if (!strcmp (mode, "%hd")) { snprintf (string, 81, "%-8s= %20d / %46s ",    field, va_arg (argp, int),                blank); }
+  if (!strcmp (mode, "%f"))  { snprintf (string, 81, "%-8s= %20.10f / %46s ", field, va_arg (argp, double),             blank); }
+  if (!strcmp (mode, "%lf")) { snprintf (string, 81, "%-8s= %20.10f / %46s ", field, va_arg (argp, double),             blank); }
+  if (!strcmp (mode, "%e"))  { snprintf (string, 81, "%-8s= %20.10E / %46s ", field, va_arg (argp, double),             blank); }
+  if (!strcmp (mode, "%le")) { snprintf (string, 81, "%-8s= %20.10E / %46s ", field, va_arg (argp, double),             blank); }
+  if (!strcmp (mode, "%g"))  { snprintf (string, 81, "%-8s= %20.10G / %46s ", field, va_arg (argp, double),             blank); }
+  if (!strcmp (mode, "%lg")) { snprintf (string, 81, "%-8s= %20.10G / %46s ", field, va_arg (argp, double),             blank); }
+
+  /* string value.  Quotes must be at least 18 chars apart.  Longer lines will this should be fixed to allow arbitrary string lengths, up to 69 chars */
+  if (!strcmp (mode, "%s")) {
+    strcpy (line, va_arg (argp, char *));
+    line[68] = 0;
+    snprintf (string, 81, "%-8s= '%-18s' / %46s ", field, line, blank);
+  }
+
+  strncpy (p, string, 80);
+  
+  va_end (argp);
+  return (TRUE);
+
+}
+
+// alternate version for the special types (boolean, comments, COMMENT)
+int gfits_print_alt (Header *header, char *field, char *mode, int N,...) {
   
   /* this function expects one more argument, the value to be written */
@@ -27,7 +102,7 @@
 
   /* is there enough space for 1 more line? */
-  if (header[0].size - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) {
-    header[0].size += FT_RECORD_SIZE;
-    REALLOCATE (header[0].buffer, char, header[0].size);
+  if (header[0].datasize - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) {
+    header[0].datasize += FT_RECORD_SIZE;
+    REALLOCATE (header[0].buffer, char, header[0].datasize);
     /* re-find the "END" marker, in case new memory block is used */
     p = gfits_header_field (header, "END", 1);
@@ -40,20 +115,4 @@
   memset (p, ' ', FT_LINE_LENGTH);
 
-  /* write the new FITS card, setting the comment to be blank */
-  /* in these lines, the value field will expand as needed, forcing out the comment
-     the total line is limited by snprintf to only 80 chars + EOL */
-
-  /* write the numeric modes */
-  if (!strcmp (mode, "%d"))  { snprintf (string, 81, "%-8s= %20d / %46s ",    field, va_arg (argp, int),      blank); }
-  if (!strcmp (mode, "%u"))  { snprintf (string, 81, "%-8s= %20d / %46s ",    field, va_arg (argp, unsigned), blank); }
-  if (!strcmp (mode, "%ld")) { snprintf (string, 81, "%-8s= %20ld / %46s ",   field, va_arg (argp, long),     blank); }
-  if (!strcmp (mode, "%hd")) { snprintf (string, 81, "%-8s= %20d / %46s ",    field, va_arg (argp, int),      blank); }
-  if (!strcmp (mode, "%f"))  { snprintf (string, 81, "%-8s= %20.10f / %46s ", field, va_arg (argp, double),   blank); }
-  if (!strcmp (mode, "%lf")) { snprintf (string, 81, "%-8s= %20.10f / %46s ", field, va_arg (argp, double),   blank); }
-  if (!strcmp (mode, "%e"))  { snprintf (string, 81, "%-8s= %20.10E / %46s ", field, va_arg (argp, double),   blank); }
-  if (!strcmp (mode, "%le")) { snprintf (string, 81, "%-8s= %20.10E / %46s ", field, va_arg (argp, double),   blank); }
-  if (!strcmp (mode, "%g"))  { snprintf (string, 81, "%-8s= %20.10G / %46s ", field, va_arg (argp, double),   blank); }
-  if (!strcmp (mode, "%lg")) { snprintf (string, 81, "%-8s= %20.10G / %46s ", field, va_arg (argp, double),   blank); }
-
   /* write the boolean mode */
   if (!strcmp (mode, "%t")) {
@@ -63,11 +122,4 @@
     else
       snprintf (string, 81, "%-8s= %18s F / %46s ", field, blank, blank);
-  }
-
-  /* string value.  Quotes must be at least 18 chars apart.  Longer lines will this should be fixed to allow arbitrary string lengths, up to 69 chars */
-  if (!strcmp (mode, "%s")) {
-    strcpy (line, va_arg (argp, char *));
-    line[68] = 0;
-    snprintf (string, 81, "%-8s= '%-18s' / %46s ", field, line, blank);
   }
 
Index: trunk/Ohana/src/libfits/header/F_read_H.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_read_H.c	(revision 27392)
+++ trunk/Ohana/src/libfits/header/F_read_H.c	(revision 27435)
@@ -23,8 +23,9 @@
 int gfits_load_header (FILE *f, Header *header) {
 
-  int i, done, Nbytes, t1, t2;
+  off_t i, Nbytes;
+  int done, t1, t2;
   char *p;
 
-  header[0].size = 0;
+  header[0].datasize = 0;
   done = FALSE;
   ALLOCATE (header[0].buffer, char, 1);
@@ -32,6 +33,5 @@
   for (i = 0; !done; i++) {
     REALLOCATE (header[0].buffer, char, (i + 1)*FT_RECORD_SIZE);
-    Nbytes = fread (&header[0].buffer[i*FT_RECORD_SIZE], 
-		    sizeof(char), FT_RECORD_SIZE, f);
+    Nbytes = fread (&header[0].buffer[i*FT_RECORD_SIZE], sizeof(char), FT_RECORD_SIZE, f);
     if (Nbytes != FT_RECORD_SIZE) {
       if (feof(f)) return (FALSE);
@@ -40,5 +40,5 @@
     }
     
-    header[0].size += Nbytes;
+    header[0].datasize += Nbytes;
 
     if (i == 0) { 
@@ -60,23 +60,23 @@
     header[0].Naxis[i] = 0;
 
-  gfits_scan (header,  "SIMPLE", "%t",   1, &header[0].simple);
+  gfits_scan_alt (header,  "SIMPLE", "%t",   1, &header[0].simple);
   gfits_scan (header,  "BITPIX", "%d",   1, &header[0].bitpix);
   gfits_scan (header,  "NAXIS",  "%d",   1, &header[0].Naxes);
 				                           
-  gfits_scan (header,  "EXTEND", "%t",   1, &header[0].extend);
-  gfits_scan (header,  "UNSIGN", "%t",   1, &header[0].unsign);
+  gfits_scan_alt (header,  "EXTEND", "%t",   1, &header[0].extend);
+  gfits_scan_alt (header,  "UNSIGN", "%t",   1, &header[0].unsign);
   gfits_scan (header,  "BSCALE", "%lf",  1, &header[0].bscale);
   gfits_scan (header,  "BZERO",  "%lf",  1, &header[0].bzero);
 				       
-  gfits_scan (header,  "NAXIS1", "%d", 1, &header[0].Naxis[0]);
-  gfits_scan (header,  "NAXIS2", "%d", 1, &header[0].Naxis[1]);
-  gfits_scan (header,  "NAXIS3", "%d", 1, &header[0].Naxis[2]);
-  gfits_scan (header,  "NAXIS4", "%d", 1, &header[0].Naxis[3]);
-  gfits_scan (header,  "NAXIS5", "%d", 1, &header[0].Naxis[4]);
-  gfits_scan (header,  "NAXIS6", "%d", 1, &header[0].Naxis[5]);
-  gfits_scan (header,  "NAXIS7", "%d", 1, &header[0].Naxis[6]);
-  gfits_scan (header,  "NAXIS8", "%d", 1, &header[0].Naxis[7]);
-  gfits_scan (header,  "NAXIS9", "%d", 1, &header[0].Naxis[8]);
-  gfits_scan (header, "NAXIS10", "%d", 1, &header[0].Naxis[9]);
+  gfits_scan (header,  "NAXIS1", "%lld", 1, (long long *) &header[0].Naxis[0]);
+  gfits_scan (header,  "NAXIS2", "%lld", 1, (long long *) &header[0].Naxis[1]);
+  gfits_scan (header,  "NAXIS3", "%lld", 1, (long long *) &header[0].Naxis[2]);
+  gfits_scan (header,  "NAXIS4", "%lld", 1, (long long *) &header[0].Naxis[3]);
+  gfits_scan (header,  "NAXIS5", "%lld", 1, (long long *) &header[0].Naxis[4]);
+  gfits_scan (header,  "NAXIS6", "%lld", 1, (long long *) &header[0].Naxis[5]);
+  gfits_scan (header,  "NAXIS7", "%lld", 1, (long long *) &header[0].Naxis[6]);
+  gfits_scan (header,  "NAXIS8", "%lld", 1, (long long *) &header[0].Naxis[7]);
+  gfits_scan (header,  "NAXIS9", "%lld", 1, (long long *) &header[0].Naxis[8]);
+  gfits_scan (header, "NAXIS10", "%lld", 1, (long long *) &header[0].Naxis[9]);
 
   if (!gfits_scan (header, "PCOUNT",  "%d", 1, &header[0].pcount)) {
Index: trunk/Ohana/src/libfits/header/F_read_XH.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_read_XH.c	(revision 27392)
+++ trunk/Ohana/src/libfits/header/F_read_XH.c	(revision 27435)
@@ -31,9 +31,10 @@
   /* read header for extension number N */
 
-  int j, Nmatrix, Nskip;
+  int j;
+  off_t Nmatrix, Nskip;
   Header theader;
   
   /* set f to beginning of file */
-  fseek (f, 0, SEEK_SET);
+  fseeko (f, 0, SEEK_SET);
 
   Nskip = 0;
@@ -47,6 +48,6 @@
 
     /* skip to next header */
-    fseek (f, Nmatrix, SEEK_CUR);
-    Nskip += (Nmatrix + theader.size);
+    fseeko (f, Nmatrix, SEEK_CUR);
+    Nskip += (Nmatrix + theader.datasize);
     gfits_free_header (&theader);
   }
@@ -55,5 +56,5 @@
     return (FALSE);
   }
-  Nskip += header[0].size;
+  Nskip += header[0].datasize;
   return (Nskip);
 }	
Index: trunk/Ohana/src/libfits/header/F_scan.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_scan.c	(revision 27392)
+++ trunk/Ohana/src/libfits/header/F_scan.c	(revision 27435)
@@ -2,4 +2,5 @@
 # include <gfitsio.h>
 
+// this only scans the regular and non-boolean fields
 int gfits_scan (Header *header, char *field, char *mode, int N,...) {
 
@@ -13,9 +14,23 @@
 }
   
+// alternate version for the special types (boolean, comments, COMMENT)
+int gfits_scan_alt (Header *header, char *field, char *mode, int N,...) {
+
+  int status;
+  va_list argp;
+  
+  va_start (argp, N);
+  status = gfits_vscan_alt (header, field, mode, N, argp);
+  va_end (argp);
+  return (status);
+}
+  
+// this only scans the regular and non-boolean fields
 int gfits_vscan (Header *header, char *field, char *mode, int N, va_list argp) {
 
   char *p, *q, *s, tmp[81];
   int Nchar, status;
-  double value;
+  long long value;
+  double fvalue;
   
   /* find the correct line with field */
@@ -26,4 +41,64 @@
   }
 
+  /* all others require '=' in column 8 */
+  if (p[8] != '=') return (FALSE);
+
+  /* extract data into char array (exclude containing ' chars) */
+  if (!strcmp (mode, "%s")) {
+    s = gfits_keyword_start (p); /* points at first char (not ') */
+    q = gfits_keyword_end (p); /* points at following space or ' */
+
+    Nchar = MAX (0, (q - s));
+    bzero (tmp, 81);
+    memcpy (tmp, s, Nchar);
+    stripwhite (tmp);
+    strcpy (va_arg (argp, char *), tmp);
+    return (TRUE);
+  }
+  
+  /* remaining options are numerical data */
+  /* need to interpret 1.0d5 as 1.0e5 */
+  s = gfits_keyword_start (p); /* points at first char (not ') */
+  q = gfits_keyword_end (p); /* points at following space or ' */
+
+  if (!strcmp (mode, "%f") || !strcmp (mode, "%lf")) {
+    fvalue = strtod (s, &q);
+    if ((*q == 'd') || (*q == 'D')) 
+      fvalue *= pow (10.0, atof (q + 1));
+
+    if (!strcmp (mode, "%f"))   { *va_arg (argp, float *)  = fvalue; return (TRUE); }
+    if (!strcmp (mode, "%lf"))  { *va_arg (argp, double *) = fvalue; return (TRUE); }
+  }
+
+  value = strtoll (s, &q, 0);
+  if ((*q == 'd') || (*q == 'D')) value *= pow (10.0, atof (q + 1));
+
+  if (!strcmp (mode, "%d"))   { *va_arg (argp, int *)       	     = value; return (TRUE); }
+  if (!strcmp (mode, "%ld"))  { *va_arg (argp, long *)      	     = value; return (TRUE); }
+  if (!strcmp (mode, "%lld")) { *va_arg (argp, long long *) 	     = value; return (TRUE); }
+  if (!strcmp (mode, "%Ld"))  { *va_arg (argp, long long *) 	     = value; return (TRUE); }
+  if (!strcmp (mode, "%u"))   { *va_arg (argp, unsigned *)  	     = value; return (TRUE); }
+  if (!strcmp (mode, "%lu"))  { *va_arg (argp, unsigned long *)      = value; return (TRUE); }
+  if (!strcmp (mode, "%llu")) { *va_arg (argp, unsigned long long *) = value; return (TRUE); }
+  if (!strcmp (mode, "%Lu"))  { *va_arg (argp, unsigned long long *) = value; return (TRUE); }
+  if (!strcmp (mode, "%hd"))  { *va_arg (argp, short *)     	     = value; return (TRUE); }
+
+  /* no valid mode found */
+  return (FALSE);
+}
+
+// alternate version for the special types (boolean, comments, COMMENT)
+int gfits_vscan_alt (Header *header, char *field, char *mode, int N, va_list argp) {
+
+  char *p, *q, *s, tmp[81];
+  int Nchar, status;
+
+  /* find the correct line with field */
+  p = gfits_header_field (header, field, N);
+  if (p == NULL) {
+    status = gfits_vscan_hierarch (header, field, mode, N, argp);
+    return (status);
+  }
+
   /* non-data entry (COMMENT, HISTORY) */
   if (!strcmp (mode, "%S")) {
@@ -47,17 +122,4 @@
   }
 
-  /* extract data into char array (exclude containing ' chars) */
-  if (!strcmp (mode, "%s")) {
-    s = gfits_keyword_start (p); /* points at first char (not ') */
-    q = gfits_keyword_end (p); /* points at following space or ' */
-
-    Nchar = MAX (0, (q - s));
-    bzero (tmp, 81);
-    memcpy (tmp, s, Nchar);
-    stripwhite (tmp);
-    strcpy (va_arg (argp, char *), tmp);
-    return (TRUE);
-  }
-  
   /* boolean data, requires int target */
   if (!strcmp (mode, "%t")) {
@@ -73,19 +135,4 @@
   }
 
-  /* remaining options are numerical data */
-  /* need to interpret 1.0d5 as 1.0e5 */
-  s = gfits_keyword_start (p); /* points at first char (not ') */
-  q = gfits_keyword_end (p); /* points at following space or ' */
-  value = strtod (s, &q);
-  if ((*q == 'd') || (*q == 'D')) 
-    value *= pow (10.0, atof (q + 1));
-
-  if (!strcmp (mode, "%d"))  { *va_arg (argp, int *)       = value; return (TRUE); }
-  if (!strcmp (mode, "%u"))  { *va_arg (argp, unsigned *)  = value; return (TRUE); }
-  if (!strcmp (mode, "%ld")) { *va_arg (argp, long *)      = value; return (TRUE); }
-  if (!strcmp (mode, "%hd")) { *va_arg (argp, short *)     = value; return (TRUE); }
-  if (!strcmp (mode, "%f"))  { *va_arg (argp, float *)     = value; return (TRUE); }
-  if (!strcmp (mode, "%lf")) { *va_arg (argp, double *)    = value; return (TRUE); }
-
   /* no valid mode found */
   return (FALSE);
@@ -97,5 +144,6 @@
   char *p, *q, *s, tmp[81];
   int Nchar, Nfield;
-  double value;
+  long long value;
+  double fvalue;
   
   /* find the correct line with field */
@@ -156,14 +204,26 @@
   s = gfits_hierarch_keyword_start (p, field); /* points at first char (not ') */
   q = gfits_hierarch_keyword_end (p, field); /* points at following space or ' */
-  value = strtod (s, &q);
-  if ((*q == 'd') || (*q == 'D')) 
-    value *= pow (10.0, atof (q + 1));
-
-  if (!strcmp (mode, "%d"))  { *va_arg (argp, int *)       = value; return (TRUE); }
-  if (!strcmp (mode, "%u"))  { *va_arg (argp, unsigned *)  = value; return (TRUE); }
-  if (!strcmp (mode, "%ld")) { *va_arg (argp, long *)      = value; return (TRUE); }
-  if (!strcmp (mode, "%hd")) { *va_arg (argp, short *)     = value; return (TRUE); }
-  if (!strcmp (mode, "%f"))  { *va_arg (argp, float *)     = value; return (TRUE); }
-  if (!strcmp (mode, "%lf")) { *va_arg (argp, double *)    = value; return (TRUE); }
+
+  if (!strcmp (mode, "%f") || !strcmp (mode, "%lf")) {
+    fvalue = strtod (s, &q);
+    if ((*q == 'd') || (*q == 'D')) 
+      fvalue *= pow (10.0, atof (q + 1));
+
+    if (!strcmp (mode, "%f"))   { *va_arg (argp, float *)  = fvalue; return (TRUE); }
+    if (!strcmp (mode, "%lf"))  { *va_arg (argp, double *) = fvalue; return (TRUE); }
+  }
+
+  value = strtoll (s, &q, 0);
+  if ((*q == 'd') || (*q == 'D')) value *= pow (10.0, atof (q + 1));
+
+  if (!strcmp (mode, "%d"))   { *va_arg (argp, int *)       	     = value; return (TRUE); }
+  if (!strcmp (mode, "%ld"))  { *va_arg (argp, long *)      	     = value; return (TRUE); }
+  if (!strcmp (mode, "%lld")) { *va_arg (argp, long long *) 	     = value; return (TRUE); }
+  if (!strcmp (mode, "%Ld"))  { *va_arg (argp, long long *) 	     = value; return (TRUE); }
+  if (!strcmp (mode, "%u"))   { *va_arg (argp, unsigned *)  	     = value; return (TRUE); }
+  if (!strcmp (mode, "%lu"))  { *va_arg (argp, unsigned long *)      = value; return (TRUE); }
+  if (!strcmp (mode, "%llu")) { *va_arg (argp, unsigned long long *) = value; return (TRUE); }
+  if (!strcmp (mode, "%Lu"))  { *va_arg (argp, unsigned long long *) = value; return (TRUE); }
+  if (!strcmp (mode, "%hd"))  { *va_arg (argp, short *)     	     = value; return (TRUE); }
 
   /* no valid mode found */
Index: trunk/Ohana/src/libfits/header/F_write_H.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_write_H.c	(revision 27392)
+++ trunk/Ohana/src/libfits/header/F_write_H.c	(revision 27435)
@@ -6,5 +6,6 @@
 
   FILE *f;
-  int Nbytes, status;
+  off_t Nbytes;
+  int status;
   
   status = TRUE;
@@ -13,7 +14,7 @@
   if (f == (FILE *) NULL) return (FALSE);
 
-  Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].size, f);
+  Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].datasize, f);
 
-  if (Nbytes != header[0].size) {
+  if (Nbytes != header[0].datasize) {
     status = FALSE;
   }
@@ -27,11 +28,12 @@
 int gfits_save_header (FILE *f, Header *header) {
 
-  int Nbytes, status;
+  off_t Nbytes; 
+  int status;
   
   status = TRUE;
 
-  Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].size, f);
+  Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].datasize, f);
 
-  if (Nbytes != header[0].size) {
+  if (Nbytes != header[0].datasize) {
     status = FALSE;
   }
Index: trunk/Ohana/src/libfits/include/gfitsio.h
===================================================================
--- trunk/Ohana/src/libfits/include/gfitsio.h	(revision 27392)
+++ trunk/Ohana/src/libfits/include/gfitsio.h	(revision 27435)
@@ -44,11 +44,11 @@
 
 typedef struct {
-  int                     simple;
-  int                     unsign;
-  int                     extend;
-  int                     bitpix;
-  int                     Naxes;
-  int                     Naxis[FT_MAX_NAXES];
-  int                     size;
+  int                     simple; // T or F
+  int                     unsign; // T or F
+  int                     extend; // T or F
+  int                     bitpix; // 8, 16, 32, 64, or -32, -64
+  int                     Naxes;  // < FT_MAX_NAXES (10)
+  off_t                   Naxis[FT_MAX_NAXES];
+  off_t                   datasize;
   int                     pcount;
   int                     gcount;
@@ -65,6 +65,6 @@
   int                     bitpix;
   int                     Naxes;
-  int                     Naxis[FT_MAX_NAXES];
-  int                     size;
+  off_t                   Naxis[FT_MAX_NAXES];
+  off_t                   datasize;
   double                  bzero;
   double                  bscale;
@@ -76,5 +76,5 @@
   Header                 *header;
   char                   *buffer;
-  int                     size;
+  off_t                   datasize;
 } FTable;
 
@@ -83,16 +83,17 @@
   Header                 *header;
   char                  **buffer;
-  int                     Nrow;
-  int                    *row;
-  int                     size;  /* total buffer size */
-  int                     pad;   /* bytes of padding at the end */
+  off_t                   Nrow;
+  off_t                  *row;
+  off_t                   datasize;  /* total buffer size */
+  off_t                   pad;   /* bytes of padding at the end */
 } VTable;
 
 typedef struct {
-  int  maxlen; 		      // max size of all table rows
-  int  nbytes;		      // number of bytes per column element
-  int  Nstart;		      // byte offset of this column
-  int  heap_start;	      // byte offset to start of HEAP
-  char format;		      // data format character (one of: XLABIJEDCM)
+  int   maxlen; 	      // max size of all table rows
+  int   nbytes;		      // number of bytes per column element
+  int   Nstart;		      // byte offset of this column relative to first column
+  off_t heap_start;	      // byte offset to start of HEAP
+  char  format;		      // data format character (one of: XLABIJEDCM)
+  char  mode;		      // access data pointer type (one of P or Q)
 } VarLengthColumn;
 
@@ -106,5 +107,5 @@
 
 char   *gfits_header_field             PROTO((Header *header, char *field, int N)); 
-char   *gfits_header_lineno            PROTO((Header *header, int N)); 
+char   *gfits_header_lineno            PROTO((Header *header, off_t N)); 
 char   *gfits_keyword_end              PROTO((char *line));
 int     gfits_copy_header              PROTO((Header *in, Header *out)); 
@@ -118,16 +119,20 @@
 int     gfits_init_header              PROTO((Header *header));
 int     gfits_load_header              PROTO((FILE *f, Header *header));
-int     gfits_modify                   PROTO((Header *header, char *field, char *mode, int N,...)); 
-int     gfits_print                    PROTO((Header *header, char *field, char *mode, int N,...)); 
+int     gfits_modify                   PROTO((Header *header, char *field, char *mode, int N,...)) OHANA_FORMAT(printf, 3, 5); 
+int     gfits_print                    PROTO((Header *header, char *field, char *mode, int N,...)) OHANA_FORMAT(printf, 3, 5); 
+int     gfits_modify_alt               PROTO((Header *header, char *field, char *mode, int N,...)); 
+int     gfits_print_alt                PROTO((Header *header, char *field, char *mode, int N,...)); 
 int     gfits_read_Xheader             PROTO((char *filename, Header *header, int N));
 int     gfits_read_header              PROTO((char *filename, Header *header));
 int     gfits_save_header              PROTO((FILE *f, Header *header));
-int     gfits_scan                     PROTO((Header *header, char *field, char *mode, int N,...));
+int     gfits_scan                     PROTO((Header *header, char *field, char *mode, int N,...)) OHANA_FORMAT(scanf, 3, 5);
+int     gfits_scan_alt                 PROTO((Header *header, char *field, char *mode, int N,...));
 int     gfits_set_unsign_mode          PROTO((int mode));
 int     gfits_stripwhite               PROTO((char *string));
 int     gfits_vscan                    PROTO((Header *header, char *field, char *mode, int N, va_list argp));
+int     gfits_vscan_alt                PROTO((Header *header, char *field, char *mode, int N, va_list argp));
 int     gfits_write_header             PROTO((char *filename, Header *header)); 
-int     gfits_data_size                PROTO((Header *header));
-int     gfits_data_min_size            PROTO((Header *header));
+off_t   gfits_data_size                PROTO((Header *header));
+off_t   gfits_data_min_size            PROTO((Header *header));
 int 	gfits_extended_to_primary      PROTO((Header *header, int simple, char *comment));
 int 	gfits_primary_to_extended      PROTO((Header *header, char *exttype, char *comment));
@@ -143,5 +148,5 @@
 /******************************* Matrix functions *************/
 
-void   	gfits_add_matrix_value         PROTO((Matrix *matrix, int x, int y, double value)); 
+void   	gfits_add_matrix_value         PROTO((Matrix *matrix, off_t x, off_t y, double value)); 
 int    	gfits_convert_format           PROTO((Header *header, Matrix *matrix, int outBitpix, double outScale, double outZero, int inBlank, int outUnsign));
 int     gfits_copy_matrix              PROTO((Matrix *in, Matrix *out)); 
@@ -152,12 +157,12 @@
 void    gfits_free_matrix              PROTO((Matrix *matrix)); 
 int     gfits_fwrite_matrix            PROTO((FILE *f, Matrix *matrix));      
-double  gfits_get_matrix_value         PROTO((Matrix *matrix, int x, int y)); 
-void   	gfits_insert_array             PROTO((Matrix *matrix, Matrix *array, int x, int y)); 
+double  gfits_get_matrix_value         PROTO((Matrix *matrix, off_t x, off_t y)); 
+void   	gfits_insert_matrix            PROTO((Matrix *matrix, Matrix *array, off_t x, off_t y)); 
 int    	gfits_load_matrix              PROTO((FILE *f, Matrix *matrix, Header *header));
 int    	gfits_multiply_matrix          PROTO((Matrix *M1, Matrix *M2, Matrix *M3)); 
 int     gfits_read_matrix              PROTO((char *filename, Matrix *matrix));      
 int    	gfits_read_matrix_segment      PROTO((char *filename, Matrix *matrix, char *region));
-int     gfits_read_portion             PROTO((char *filename, Matrix *matrix, int Nskip, int Npix));
-void   	gfits_set_matrix_value         PROTO((Matrix *matrix, int x, int y, double value)); 
+int     gfits_read_portion             PROTO((char *filename, Matrix *matrix, off_t Nskip, off_t Npix));
+void   	gfits_set_matrix_value         PROTO((Matrix *matrix, off_t x, off_t y, double value)); 
 int     gfits_write_matrix             PROTO((char *filename, Matrix *matrix)); 
 int     gfits_uncompress_image 	       PROTO((Header *header, Matrix *matrix, FTable *ftable));
@@ -166,5 +171,5 @@
 int     gfits_byteswap_zdata   	       PROTO((char *zdata, int Nzdata, int bitpix));
 int     gfits_extension_is_compressed  PROTO((Header *header));
-int     gfits_tile_size                PROTO((Matrix *matrix, int *otile, int *ztile));
+off_t   gfits_tile_size                PROTO((Matrix *matrix, int *otile, int *ztile));
 int     gfits_uncompressed_data_pixsize PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions));
 int     gfits_vartable_heap_pixsize    PROTO((char format));
@@ -173,5 +178,5 @@
 
 char   *gfits_table_print              PROTO((FTable *ftable,...));
-int     gfits_add_rows                 PROTO((FTable *ftable, char *data, int Nrow, int Nbytes));
+int     gfits_add_rows                 PROTO((FTable *ftable, char *data, off_t Nrow, off_t Nbytes));
 int     gfits_bintable_format          PROTO((char *format, char *type, int *Nval, int *Nbytes));
 int     gfits_create_table             PROTO((Header *header, FTable *ftable));
@@ -181,28 +186,28 @@
 int   	gfits_fread_ftable             PROTO((FILE *f, FTable *ftable, char *extname)); 
 int   	gfits_fread_ftable_data        PROTO((FILE *f, FTable *ftable));
-int   	gfits_fread_ftable_range       PROTO((FILE *f, FTable *ftable, int start, int Nrows));
-int   	gfits_fread_vtable             PROTO((FILE *f, VTable *vtable, char *extname, int Nrow, int *row));
-int   	gfits_fread_vtable_range       PROTO((FILE *f, VTable *vtable, int start, int Nrows));
+int   	gfits_fread_ftable_range       PROTO((FILE *f, FTable *ftable, off_t start, off_t Nrows));
+int   	gfits_fread_vtable             PROTO((FILE *f, VTable *vtable, char *extname, off_t Nrow, off_t *row));
+int   	gfits_fread_vtable_range       PROTO((FILE *f, VTable *vtable, off_t start, off_t Nrows));
 int     gfits_free_table               PROTO((FTable *ftable));
 int     gfits_free_vtable              PROTO((VTable *vtable));
 int     gfits_fwrite_table             PROTO((FILE *f, FTable *table));
 int     gfits_fwrite_vtable            PROTO((FILE *f, VTable *table));
-int     gfits_fwrite_ftable_range      PROTO((FILE *f, FTable *table, int start, int Nrows, int Ndisk, int Ntotal));
+int     gfits_fwrite_ftable_range      PROTO((FILE *f, FTable *table, off_t start, off_t Nrows, off_t Ndisk, off_t Ntotal));
 int     gfits_get_bintable_column      PROTO((Header *header, FTable *table, char *label, void **data));
 int     gfits_get_bintable_column_type PROTO((Header *header, char *label, char *type, int *Nval));
-void   *gfits_get_bintable_column_data PROTO((Header *header, FTable *table, char *label, char *type, int *Nrow, int *Ncol));
+void   *gfits_get_bintable_column_data PROTO((Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol));
 int     gfits_get_table_column         PROTO((Header *header, FTable *table, char *label, void **data));
 int     gfits_get_table_column_type    PROTO((Header *header, char *label, char *type));
 int     gfits_read_ftable              PROTO((char *filename, FTable *table, char *extname));
 int     gfits_read_table               PROTO((char *filename, FTable *ftable)); 
-int     gfits_set_bintable_column      PROTO((Header *header, FTable *table, char *label, void *data, int Nrow));
-int     gfits_set_table_column         PROTO((Header *header, FTable *table, char *label, void *data, int Nrow));
-int     gfits_table_column             PROTO((FTable *ftable, char *field, char *mode,...));
+int     gfits_set_bintable_column      PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow));
+int     gfits_set_table_column         PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow));
+int     gfits_table_column             PROTO((FTable *ftable, char *field, char *mode,...)) OHANA_FORMAT(printf, 3, 4);
 int     gfits_table_format             PROTO((char *format, char *type, int *Nval, int *Nbytes));
 int     gfits_table_scale_data         PROTO((FTable *ftable));
 int     gfits_table_scale_storage      PROTO((FTable *ftable));
-int     gfits_table_to_vtable          PROTO((FTable *ftable, VTable *vtable, int start, int Nkeep));
-int     gfits_vadd_rows                PROTO((VTable *vtable, char *data, int Nrow, int Nbytes));
-int     gfits_vtable_from_ftable       PROTO((FTable *ftable, VTable *vtable, int *row, int Nrow));
+int     gfits_table_to_vtable          PROTO((FTable *ftable, VTable *vtable, off_t start, off_t Nkeep));
+int     gfits_vadd_rows                PROTO((VTable *vtable, char *data, off_t Nrow, off_t Nbytes));
+int     gfits_vtable_from_ftable       PROTO((FTable *ftable, VTable *vtable, off_t *row, off_t Nrow));
 int     gfits_write_table              PROTO((char *filename, FTable *ftable)); 
 
@@ -215,5 +220,5 @@
 
 int     gfits_varlength_column_define  PROTO((FTable *ftable, VarLengthColumn *def, int column));
-void   *gfits_varlength_column_pointer PROTO((FTable *ftable, VarLengthColumn *column, int row, int *length));
+void   *gfits_varlength_column_pointer PROTO((FTable *ftable, VarLengthColumn *column, off_t row, off_t *length));
 
 #endif /* FITSIO */
Index: trunk/Ohana/src/libfits/matrix/F_add_M.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_add_M.c	(revision 27392)
+++ trunk/Ohana/src/libfits/matrix/F_add_M.c	(revision 27435)
@@ -3,7 +3,5 @@
 
 /*********************** fits insert array ***********************************/
-void gfits_add_matrix (matrix, array, x, y) 
-Matrix *matrix, *array; 
-int x, y;
+void gfits_add_matrix (Matrix *matrix, Matrix *array, off_t x, off_t y) 
 {
 
@@ -15,7 +13,11 @@
   if ((x + array[0].Naxis[0] > matrix[0].Naxis[0]) ||
       (y + array[0].Naxis[1] > matrix[0].Naxis[1])) {
-    fprintf (stderr, "can't add array here: (%d,%d) - (%d,%d) vs (%d,%d)\n",
-	     x, y, x + array[0].Naxis[0], y + array[0].Naxis[1],
-	     matrix[0].Naxis[0], matrix[0].Naxis[1]);
+    fprintf (stderr, "can't add array here: (%lld,%lld) - (%lld,%lld) vs (%lld,%lld)\n",
+	     (long long) x, 
+	     (long long) y, 
+	     (long long) x + array[0].Naxis[0], 
+	     (long long) y + array[0].Naxis[1],
+	     (long long) matrix[0].Naxis[0], 
+	     (long long) matrix[0].Naxis[1]);
     return;
   }
Index: trunk/Ohana/src/libfits/matrix/F_add_M_value.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_add_M_value.c	(revision 27392)
+++ trunk/Ohana/src/libfits/matrix/F_add_M_value.c	(revision 27435)
@@ -3,8 +3,5 @@
 
 /***************** fits add matrix value ***********************************/
-void gfits_add_matrix_value (matrix, x, y, Value) 
-Matrix *matrix; 
-int x, y; 
-double Value;
+void gfits_add_matrix_value (Matrix *matrix, off_t x, off_t y, double Value) 
 {
 
Index: trunk/Ohana/src/libfits/matrix/F_compress_M.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_compress_M.c	(revision 27392)
+++ trunk/Ohana/src/libfits/matrix/F_compress_M.c	(revision 27435)
@@ -24,4 +24,10 @@
     gfits_delete (header, ZNAME, 1); }
 
+# define MOD_KEYWORD_ALT(ZNAME,NAME,TYPE,IN,OUT) { \
+    if (gfits_scan_alt (header, ZNAME, TYPE, 1, IN)) { \
+      gfits_modify_alt (header, NAME, TYPE, 1, OUT); \
+    } \
+    gfits_delete (header, ZNAME, 1); }
+
 # define MOD_KEYWORD_REQUIRED(ZNAME,NAME,TYPE,IN,OUT) { \
   if (!gfits_scan (header, ZNAME, TYPE, 1, IN)) ESCAPE; \
@@ -31,5 +37,6 @@
 int gfits_uncompress_image (Header *header, Matrix *matrix, FTable *ftable) {
 
-  int i, j, status, zimage, zcol, Nzrows, Nout, Nzdata, max_tile_size;
+  off_t Nzdata, Nzrows, zcol;
+  int i, j, status, zimage, Nout, max_tile_size;
   char cmptype[80];
   char zaxis[10], naxis[10], key[10], word[81], exttype[81], checksum[81], datasum[81];
@@ -51,5 +58,5 @@
 
   // is ZIMAGE present?
-  status = gfits_scan (ftable->header, "ZIMAGE", "%t", 1, &zimage);
+  status = gfits_scan_alt (ftable->header, "ZIMAGE", "%t", 1, &zimage);
   if (!status || !zimage) ESCAPE;
 
@@ -70,5 +77,5 @@
     snprintf (zaxis, 10, "ZNAXIS%d", i + 1);
     snprintf (naxis, 10, "NAXIS%d", i + 1);
-    MOD_KEYWORD_REQUIRED (zaxis,  naxis,  "%d", &header->Naxis[i],  header->Naxis[i]);
+    MOD_KEYWORD_REQUIRED (zaxis,  naxis,  "%lld", (long long *) &header->Naxis[i], (long long) header->Naxis[i]);
   }    
 
@@ -118,5 +125,5 @@
   int have_ztension;
 
-  have_zsimple  = gfits_scan (header, "ZSIMPLE", "%t", 1, &zsimple);
+  have_zsimple  = gfits_scan_alt (header, "ZSIMPLE", "%t", 1, &zsimple);
   have_ztension = gfits_scan (header, "ZTENSION", "%s", 1, exttype);
 
@@ -130,6 +137,6 @@
     gfits_extended_to_primary (header, header->simple, "Image data");
 
-    MOD_KEYWORD ("ZEXTEND",  "EXTEND",   "%t", &header->extend, header->extend);
-    MOD_KEYWORD ("ZBLOCKED", "BLOCKED",  "%t", &header->extend, header->extend);
+    MOD_KEYWORD_ALT ("ZEXTEND",  "EXTEND",   "%t", &header->extend, header->extend);
+    MOD_KEYWORD_ALT ("ZBLOCKED", "BLOCKED",  "%t", &header->extend, header->extend);
   }
 
@@ -140,6 +147,6 @@
     gfits_extended_to_primary (header, header->simple, "Image data");
 
-    MOD_KEYWORD ("ZEXTEND",  "EXTEND",   "%t", &header->extend, header->extend);
-    MOD_KEYWORD ("ZBLOCKED", "BLOCKED",  "%t", &header->extend, header->extend);
+    MOD_KEYWORD_ALT ("ZEXTEND",  "EXTEND",   "%t", &header->extend, header->extend);
+    MOD_KEYWORD_ALT ("ZBLOCKED", "BLOCKED",  "%t", &header->extend, header->extend);
   } 
 
@@ -175,5 +182,5 @@
 
   zscale = 1;
-  gfits_scan (header, "ZSCALE", "%lf", 1, &zscale);
+  gfits_scan (header, "ZSCALE", "%f", 1, &zscale);
 
   zblank = 32767;
@@ -184,5 +191,5 @@
 
   zzero = 0;
-  gfits_scan (header, "ZZERO", "%lf", 1, &zzero);
+  gfits_scan (header, "ZZERO", "%f", 1, &zzero);
 
   // find the COMPRESSED_DATA column (format should be 1PB, 1PI, 1PJ)
@@ -196,7 +203,7 @@
   if (!gfits_varlength_column_define (ftable, &zdef, zcol)) ESCAPE;
   gfits_delete (header, "TFIELDS", 1);
-  snprintf (key, 10, "TTYPE%d", zcol);
+  snprintf (key, 10, "TTYPE%lld", (long long) zcol);
   gfits_delete (header, key, 1);
-  snprintf (key, 10, "TFORM%d", zcol);
+  snprintf (key, 10, "TFORM%lld", (long long) zcol);
   gfits_delete (header, key, 1);
 
@@ -236,12 +243,14 @@
   ALLOCATE (out, char, odata_pixsize*max_tile_size);
 
+  off_t row;
+
   // uncompress the data
   Nzrows = ftable->header->Naxis[1];
-  for (i = 0; i < Nzrows; i++) {
+  for (row = 0; row < Nzrows; row++) {
 
     // expected output size for this tile
     Nout = gfits_tile_size (matrix, otile, ztile);
 
-    zdata = gfits_varlength_column_pointer (ftable, &zdef, i, &Nzdata);
+    zdata = gfits_varlength_column_pointer (ftable, &zdef, row, &Nzdata);
     if (!zdata) return (FALSE);
 
@@ -254,4 +263,5 @@
 
     // gfits_uncompress_data uncompresses from zdata to the temporary output buffer which must be allocated
+    // XXX the tile must not be > 2GB
     if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, odata_pixsize)) return (FALSE);
 
@@ -284,7 +294,7 @@
 
 // true sizes of this tile (in pixels)
-int gfits_tile_size (Matrix *matrix, int *otile, int *ztile) {
-
-  int i, Npixels, Ndimen;
+off_t gfits_tile_size (Matrix *matrix, int *otile, int *ztile) {
+
+  off_t i, Npixels, Ndimen;
 
   Npixels = 1;
@@ -470,5 +480,5 @@
     has_extension = gfits_scan (header, "XTENSION", "%s", 1, extension);
     has_extname = gfits_scan (header, "EXTNAME", "%s", 1, extname);
-    has_zimage  = gfits_scan (header, "ZIMAGE", "%t", 1, &zimage);
+    has_zimage  = gfits_scan_alt (header, "ZIMAGE", "%t", 1, &zimage);
 
     if (has_extension && !strcmp (extension, "IMAGE")) return (FALSE);
@@ -486,6 +496,6 @@
     int ztension, zimage;
 
-    has_zimage   = gfits_scan (header, "ZIMAGE",   "%t", 1, &zimage);
-    has_ztension = gfits_scan (header, "ZTENSION", "%t", 1, &ztension);
+    has_zimage   = gfits_scan_alt (header, "ZIMAGE",   "%t", 1, &zimage);
+    has_ztension = gfits_scan_alt (header, "ZTENSION", "%t", 1, &ztension);
 
     if (has_zimage && zimage) return (TRUE);
Index: trunk/Ohana/src/libfits/matrix/F_convert_format.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_convert_format.c	(revision 27392)
+++ trunk/Ohana/src/libfits/matrix/F_convert_format.c	(revision 27435)
@@ -24,5 +24,5 @@
       *out = *in*A + B;					\
     }							\
-  REALLOCATE (matrix[0].buffer, char, matrix[0].size); 
+  REALLOCATE (matrix[0].buffer, char, matrix[0].datasize); 
 
 # define CONVERTSAME(MY_NAN)			\
@@ -41,5 +41,5 @@
   inMode  *in;						\
   outMode *out;						\
-  REALLOCATE (matrix[0].buffer, char, matrix[0].size);	\
+  REALLOCATE (matrix[0].buffer, char, matrix[0].datasize);	\
   out = (outMode *)matrix[0].buffer + Npixels - 1;	\
   in  = (inMode  *)matrix[0].buffer + Npixels - 1;	\
@@ -62,5 +62,5 @@
       *out = *in*A + B;					\
     }							\
-  REALLOCATE (matrix[0].buffer, char, matrix[0].size); 
+  REALLOCATE (matrix[0].buffer, char, matrix[0].datasize); 
 
 # define CONVERTSAME_FF(MY_NAN)			\
@@ -79,5 +79,5 @@
   inMode  *in;						\
   outMode *out;						\
-  REALLOCATE (matrix[0].buffer, char, matrix[0].size);	\
+  REALLOCATE (matrix[0].buffer, char, matrix[0].datasize);	\
   out = (outMode *)matrix[0].buffer + Npixels - 1;	\
   in  = (inMode  *)matrix[0].buffer + Npixels - 1;	\
@@ -106,13 +106,13 @@
     return (TRUE);
 
-  matrix[0].bitpix = header[0].bitpix = outBitpix;
-  matrix[0].bscale = header[0].bscale = outScale;
-  matrix[0].bzero  = header[0].bzero  = outZero;
-  matrix[0].unsign = header[0].unsign = outUnsign;
-  matrix[0].size   = gfits_data_size (header);
+  matrix[0].bitpix   = header[0].bitpix = outBitpix;
+  matrix[0].bscale   = header[0].bscale = outScale;
+  matrix[0].bzero    = header[0].bzero  = outZero;
+  matrix[0].unsign   = header[0].unsign = outUnsign;
+  matrix[0].datasize = gfits_data_size (header);
   gfits_modify (header, "BITPIX", "%d", 1, outBitpix);
   gfits_modify (header, "BSCALE", "%lf", 1, outScale);
   gfits_modify (header, "BZERO",  "%lf", 1, outZero);
-  gfits_modify (header, "UNSIGN", "%t", 1, outUnsign);
+  gfits_modify_alt (header, "UNSIGN", "%t", 1, outUnsign);
 
   Npixels          = header[0].Naxis[0]*header[0].Naxis[1];
@@ -426,8 +426,8 @@
   {
     char *out;
-    int Nextra;
+    off_t Nextra;
     
     out = (char *)matrix[0].buffer;
-    Nextra = matrix[0].size - nbytes;
+    Nextra = matrix[0].datasize - nbytes;
     bzero (&out[nbytes], Nextra);
   }
Index: trunk/Ohana/src/libfits/matrix/F_copy_M.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_copy_M.c	(revision 27392)
+++ trunk/Ohana/src/libfits/matrix/F_copy_M.c	(revision 27435)
@@ -7,17 +7,17 @@
   int i;
 
-  matrix2[0].unsign = matrix1[0].unsign;
-  matrix2[0].bitpix = matrix1[0].bitpix;
-  matrix2[0].size   = matrix1[0].size;
-  matrix2[0].bzero  = matrix1[0].bzero;
-  matrix2[0].bscale = matrix1[0].bscale;
-  matrix2[0].Naxes  = matrix1[0].Naxes;
+  matrix2[0].unsign   = matrix1[0].unsign;
+  matrix2[0].bitpix   = matrix1[0].bitpix;
+  matrix2[0].datasize = matrix1[0].datasize;
+  matrix2[0].bzero    = matrix1[0].bzero;
+  matrix2[0].bscale   = matrix1[0].bscale;
+  matrix2[0].Naxes    = matrix1[0].Naxes;
   for (i = 0; i < FT_MAX_NAXES; i++) 
     matrix2[0].Naxis[i] = matrix1[0].Naxis[i];
 
   if (matrix2[0].buffer != NULL) free (matrix2[0].buffer);
-  ALLOCATE (matrix2[0].buffer, char, matrix2[0].size);
+  ALLOCATE (matrix2[0].buffer, char, matrix2[0].datasize);
   
-  memcpy (matrix2[0].buffer, matrix1[0].buffer, matrix2[0].size);
+  memcpy (matrix2[0].buffer, matrix1[0].buffer, matrix2[0].datasize);
 
   return (TRUE);
Index: trunk/Ohana/src/libfits/matrix/F_create_M.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_create_M.c	(revision 27392)
+++ trunk/Ohana/src/libfits/matrix/F_create_M.c	(revision 27435)
@@ -3,10 +3,8 @@
 
 /*********************** fits create matrix *******************************/
-int gfits_create_matrix (header, matrix) 
-Header *header;
-Matrix *matrix;
-{
+int gfits_create_matrix (Header *header, Matrix *matrix) {
 
-  int i, Nbytes;
+  int i;
+  off_t Nbytes;
 
   matrix[0].bitpix = header[0].bitpix;
@@ -20,7 +18,7 @@
   Nbytes = gfits_data_size (header);
   ALLOCATE (matrix[0].buffer, char, MAX (Nbytes, 1));
-  bzero (matrix[0].buffer, Nbytes);
+  memset (matrix[0].buffer, 0, Nbytes);
   
-  matrix[0].size = Nbytes;
+  matrix[0].datasize = Nbytes;
   return (TRUE);
 
Index: trunk/Ohana/src/libfits/matrix/F_get_M_value.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_get_M_value.c	(revision 27392)
+++ trunk/Ohana/src/libfits/matrix/F_get_M_value.c	(revision 27435)
@@ -3,5 +3,5 @@
 
 /***************** fits get matrix value ***********************************/
-double gfits_get_matrix_value (Matrix *matrix, int x, int y) {
+double gfits_get_matrix_value (Matrix *matrix, off_t x, off_t y) {
 
   double value;
@@ -11,5 +11,5 @@
     return (0.0);
   pixel = matrix[0].Naxis[0]*y + x;
-  value = HUGE_VAL;
+  value = NAN;
 
   if (matrix[0].unsign) {
Index: trunk/Ohana/src/libfits/matrix/F_insert_M.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_insert_M.c	(revision 27392)
+++ trunk/Ohana/src/libfits/matrix/F_insert_M.c	(revision 27435)
@@ -3,15 +3,20 @@
 
 /*********************** fits insert array ***********************************/
-void gfits_insert_matrix (Matrix *matrix, Matrix *array, int x, int y) {
+void gfits_insert_matrix (Matrix *matrix, Matrix *array, off_t x, off_t y) {
 
   /* there is no check here to match BITPIX, BZERO, or BSCALE */
 
-  int i, start_m, Nbytes_m, Nbytes;
+  int i;
+  off_t start_m, Nbytes_m, Nbytes;
 
   if ((x + array[0].Naxis[0] > matrix[0].Naxis[0]) ||
       (y + array[0].Naxis[1] > matrix[0].Naxis[1])) {
-    fprintf (stderr, "can't insert array here: (%d,%d) - (%d,%d) vs (%d,%d)\n",
-	     x, y, x + array[0].Naxis[0], y + array[0].Naxis[1],
-	     matrix[0].Naxis[0], matrix[0].Naxis[1]);
+    fprintf (stderr, "can't insert array here: (%lld,%lld) - (%lld,%lld) vs (%lld,%lld)\n",
+	     (long long) x, 
+	     (long long) y, 
+	     (long long) x + array[0].Naxis[0], 
+	     (long long) y + array[0].Naxis[1],
+	     (long long) matrix[0].Naxis[0], 
+	     (long long) matrix[0].Naxis[1]);
     return;
   }
Index: trunk/Ohana/src/libfits/matrix/F_load_M.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_load_M.c	(revision 27392)
+++ trunk/Ohana/src/libfits/matrix/F_load_M.c	(revision 27435)
@@ -13,5 +13,6 @@
 int gfits_load_matrix (FILE *f, Matrix *matrix, Header *header) {
 
-  int i, nbytes, Nbytes;
+  
+  off_t i, nbytes, Nbytes;
 
   matrix[0].bitpix = header[0].bitpix;
@@ -25,5 +26,5 @@
   Nbytes = gfits_data_size (header);
   ALLOCATE (matrix[0].buffer, char, Nbytes);
-  matrix[0].size = Nbytes;
+  matrix[0].datasize = Nbytes;
 
   nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f);
@@ -94,5 +95,5 @@
   }
   if (nbytes != Nbytes) {  /* this is a FITS error, but often the image is OK */
-    fprintf (stderr, "incomplete block in FITS file: (%d, %d)\n", nbytes, Nbytes);
+    fprintf (stderr, "incomplete block in FITS file: (%lld, %lld)\n", (long long) nbytes, (long long) Nbytes);
     return (TRUE); 
   }
Index: trunk/Ohana/src/libfits/matrix/F_matrix.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_matrix.c	(revision 27392)
+++ trunk/Ohana/src/libfits/matrix/F_matrix.c	(revision 27435)
@@ -2,7 +2,8 @@
 # include <gfitsio.h>
 
-int gfits_data_size (Header *header) {
+off_t gfits_data_size (Header *header) {
   
-  int i, Nrec, size;
+  int i;
+  off_t Nrec, size;
 
   if (header[0].Naxes == 0) return (0);
@@ -25,7 +26,8 @@
 }
 
-int gfits_data_min_size (Header *header) {
+off_t gfits_data_min_size (Header *header) {
   
-  int i, size;
+  int i;
+  off_t size;
 
   if (header[0].Naxes == 0) return (0);
Index: trunk/Ohana/src/libfits/matrix/F_read_M.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_read_M.c	(revision 27392)
+++ trunk/Ohana/src/libfits/matrix/F_read_M.c	(revision 27435)
@@ -18,5 +18,5 @@
   if (f == NULL) return (FALSE);
 
-  fseek (f, header.size, 0);
+  fseeko (f, header.datasize, 0);
   
   status = gfits_load_matrix (f, matrix, &header);
Index: trunk/Ohana/src/libfits/matrix/F_read_portion.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_read_portion.c	(revision 27392)
+++ trunk/Ohana/src/libfits/matrix/F_read_portion.c	(revision 27435)
@@ -9,9 +9,10 @@
 /*********************** fits read matrix ***********************************/
 /** the result of this function is a matrix with dimension Npix * 1 **/
-int gfits_read_portion (char *filename, Matrix *matrix, int Nskip, int Npix) {
+int gfits_read_portion (char *filename, Matrix *matrix, off_t Nskip, off_t Npix) {
 
   FILE *f;
   Header header;
-  int status, nbytes, Nbytes, Nrec;
+  int status;
+  off_t nbytes, Nbytes, Nrec;
 
   status = gfits_read_header (filename, &header);
@@ -37,5 +38,5 @@
     Nbytes = FT_RECORD_SIZE * Nrec;
   }
-  matrix[0].size = Nbytes;
+  matrix[0].datasize = Nbytes;
   ALLOCATE (matrix[0].buffer, char, Nbytes);
 
@@ -43,5 +44,5 @@
   f = fopen (filename, "r");
   if (f == NULL) return (FALSE);
-  fseek (f, header.size + Nskip, SEEK_SET);
+  fseeko (f, header.datasize + Nskip, SEEK_SET);
   nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f);
   if (nbytes != Nbytes) {
@@ -52,53 +53,54 @@
 
 # ifdef BYTE_SWAP  
- {
-  int i, perpix;
-  unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, ctmp;
+  {
+    off_t i;
+    int perpix;
+    unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, ctmp;
 
-  perpix = abs(header.bitpix) / 8;
-  if (perpix > 1) {
-    byte0 = (unsigned char *) matrix[0].buffer;
-    byte1 = (unsigned char *) matrix[0].buffer + 1;
-    byte2 = (unsigned char *) matrix[0].buffer + 2;
-    byte3 = (unsigned char *) matrix[0].buffer + 3;
-    byte4 = (unsigned char *) matrix[0].buffer + 4;
-    byte5 = (unsigned char *) matrix[0].buffer + 5;
-    byte6 = (unsigned char *) matrix[0].buffer + 6;
-    byte7 = (unsigned char *) matrix[0].buffer + 7;
-    if (perpix == 2) {
-      for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) {
-	ctmp = *byte0;
-	*byte0 = *byte1;
-	*byte1 = ctmp;
+    perpix = abs(header.bitpix) / 8;
+    if (perpix > 1) {
+      byte0 = (unsigned char *) matrix[0].buffer;
+      byte1 = (unsigned char *) matrix[0].buffer + 1;
+      byte2 = (unsigned char *) matrix[0].buffer + 2;
+      byte3 = (unsigned char *) matrix[0].buffer + 3;
+      byte4 = (unsigned char *) matrix[0].buffer + 4;
+      byte5 = (unsigned char *) matrix[0].buffer + 5;
+      byte6 = (unsigned char *) matrix[0].buffer + 6;
+      byte7 = (unsigned char *) matrix[0].buffer + 7;
+      if (perpix == 2) {
+	for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) {
+	  ctmp = *byte0;
+	  *byte0 = *byte1;
+	  *byte1 = ctmp;
+	}
       }
-    }
-    if (perpix == 4) {
-      for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) {
-	ctmp = *byte0;
-	*byte0 = *byte3;
-	*byte3 = ctmp;
-	ctmp = *byte1;
-	*byte1 = *byte2;
-	*byte2 = ctmp;
+      if (perpix == 4) {
+	for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) {
+	  ctmp = *byte0;
+	  *byte0 = *byte3;
+	  *byte3 = ctmp;
+	  ctmp = *byte1;
+	  *byte1 = *byte2;
+	  *byte2 = ctmp;
+	}
       }
-    }
-    if (perpix == 8) {
-      for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) {
-	ctmp = *byte0;
-	*byte0 = *byte7;
-	*byte7 = ctmp;
-	ctmp = *byte1;
-	*byte1 = *byte6;
-	*byte6 = ctmp;
-	ctmp = *byte1;
-	*byte2 = *byte5;
-	*byte5 = ctmp;
-	ctmp = *byte1;
-	*byte3 = *byte4;
-	*byte4 = ctmp;
+      if (perpix == 8) {
+	for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) {
+	  ctmp = *byte0;
+	  *byte0 = *byte7;
+	  *byte7 = ctmp;
+	  ctmp = *byte1;
+	  *byte1 = *byte6;
+	  *byte6 = ctmp;
+	  ctmp = *byte1;
+	  *byte2 = *byte5;
+	  *byte5 = ctmp;
+	  ctmp = *byte1;
+	  *byte3 = *byte4;
+	  *byte4 = ctmp;
+	}
       }
     }
   }
- }
 # endif
 
@@ -106,9 +108,9 @@
 
   if (nbytes < Nbytes - 2880) {  /* this is a bad FITS error: image is not OK */
-    fprintf (stderr, "error reading in matrix data from FITS file %s (%d < %d - 2880)\n", filename, nbytes, Nbytes);
+    fprintf (stderr, "error reading in matrix data from FITS file %s (%lld < %lld - 2880)\n", filename, (long long) nbytes, (long long) Nbytes);
     return (FALSE);
   }
   if (nbytes != Nbytes) {  /* this is a FITS error, but often the image is OK */
-    fprintf (stderr, "incomplete block in %s: (%d, %d)\n", filename, nbytes, Nbytes);
+    fprintf (stderr, "incomplete block in %s: (%lld, %lld)\n", filename, (long long) nbytes, (long long) Nbytes);
     return (TRUE); 
   }
Index: trunk/Ohana/src/libfits/matrix/F_read_segment.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_read_segment.c	(revision 27392)
+++ trunk/Ohana/src/libfits/matrix/F_read_segment.c	(revision 27435)
@@ -36,5 +36,6 @@
 int gfits_fread_matrix_segment (FILE *f, Matrix *matrix, Header *header, char *region) {
 
-  int status, i, nbytes, Nbytes, Nskip, NbytesData;
+  int status;
+  off_t i, nbytes, Nbytes, Nskip, NbytesData;
   int wantaxis[FT_MAX_NAXES][2];
   double tmp;
@@ -65,15 +66,15 @@
     matrix[0].Naxis[i] = wantaxis[i][1] - wantaxis[i][0];
 
-  matrix[0].size = abs (matrix[0].bitpix) / 8;
+  matrix[0].datasize = abs (matrix[0].bitpix) / 8;
   for (i = 0; i < matrix[0].Naxes; i++)
-    matrix[0].size *= matrix[0].Naxis[i];
+    matrix[0].datasize *= matrix[0].Naxis[i];
 
   Nskip = wantaxis[2][0]*matrix[0].Naxis[0]*matrix[0].Naxis[1]*abs(matrix[0].bitpix)/8;
-  NbytesData = Nskip + matrix[0].size;
+  NbytesData = Nskip + matrix[0].datasize;
 
   if (NbytesData % FT_RECORD_SIZE) 
-    Nbytes = FT_RECORD_SIZE * ((int) (NbytesData / FT_RECORD_SIZE) + 1) - Nskip;
+    Nbytes = FT_RECORD_SIZE * ((off_t) (NbytesData / FT_RECORD_SIZE) + 1) - Nskip;
   else 
-    Nbytes = FT_RECORD_SIZE * ((int) (NbytesData / FT_RECORD_SIZE)) - Nskip;
+    Nbytes = FT_RECORD_SIZE * ((off_t) (NbytesData / FT_RECORD_SIZE)) - Nskip;
 
   ALLOCATE (matrix[0].buffer, char, MAX (Nbytes, 1));
@@ -86,5 +87,5 @@
 
   /* currently only good for reading in full planes in 3-D */
-  fseek (f, Nskip, SEEK_CUR);
+  fseeko (f, Nskip, SEEK_CUR);
   nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f);
   if (nbytes != Nbytes) {
@@ -92,5 +93,5 @@
   }
 
-  matrix[0].size = Nbytes;
+  matrix[0].datasize = Nbytes;
 
 # ifdef BYTE_SWAP  
@@ -147,9 +148,9 @@
 
   if (nbytes < Nbytes - 2880) {  /* this is a bad FITS error: image is not OK */
-    fprintf (stderr, "error reading in matrix data from FITS file (%d < %d - 2880)\n", nbytes, Nbytes);
+    fprintf (stderr, "error reading in matrix data from FITS file (%lld < %lld - 2880)\n", (long long) nbytes, (long long) Nbytes);
     return (FALSE);
   }
   if (nbytes != Nbytes) {  /* this is a FITS error, but often the image is OK */
-    fprintf (stderr, "incomplete block in FITS file: (%d, %d)\n", nbytes, Nbytes);
+    fprintf (stderr, "incomplete block in FITS file: (%lld, %lld)\n", (long long) nbytes, (long long) Nbytes);
     return (TRUE); 
   }
Index: trunk/Ohana/src/libfits/matrix/F_set_M_value.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_set_M_value.c	(revision 27392)
+++ trunk/Ohana/src/libfits/matrix/F_set_M_value.c	(revision 27435)
@@ -3,7 +3,7 @@
 
 /****************** fits set matrix value ***********************************/
-void gfits_set_matrix_value (Matrix *matrix, int x, int y, double Value) {
+void gfits_set_matrix_value (Matrix *matrix, off_t x, off_t y, double Value) {
 
-  int pixel;
+  off_t pixel;
   double value;
 
Index: trunk/Ohana/src/libfits/matrix/F_write_M.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_write_M.c	(revision 27392)
+++ trunk/Ohana/src/libfits/matrix/F_write_M.c	(revision 27435)
@@ -11,5 +11,5 @@
   if (f == NULL) return (FALSE);
   
-  fseek (f, 0, SEEK_END);  /* write matrix to end of file! */
+  fseeko (f, 0LL, SEEK_END);  /* write matrix to end of file! */
 
   status = gfits_fwrite_matrix (f, matrix);
@@ -21,5 +21,6 @@
 int gfits_fwrite_matrix (FILE *f, Matrix *matrix) {
 
-  int status, nbytes, Nbytes;
+  int status;
+  off_t nbytes, Nbytes;
 
   status = TRUE;
@@ -27,16 +28,16 @@
   /* this is a bit dangerous: we are not realloc'ing the matrix.
      if the size is wrong, it probably should simply pad the fwrite statement.
-     better policy should be defined (ie, matrix.size always correct blocking?)
+     better policy should be defined (ie, matrix.datasize always correct blocking?)
   */
 
-  if (matrix[0].size % FT_RECORD_SIZE) 
-    nbytes = FT_RECORD_SIZE * ((int) (matrix[0].size / FT_RECORD_SIZE) + 1);
+  if (matrix[0].datasize % FT_RECORD_SIZE) 
+    nbytes = FT_RECORD_SIZE * ((off_t) (matrix[0].datasize / FT_RECORD_SIZE) + 1);
   else 
-    nbytes = FT_RECORD_SIZE * ((int) (matrix[0].size / FT_RECORD_SIZE));
+    nbytes = FT_RECORD_SIZE * ((off_t) (matrix[0].datasize / FT_RECORD_SIZE));
 
   /* this is a bit cumbersome: swap all words, write out file, then swap back... */
 # ifdef BYTE_SWAP  
   { 
-    int i;
+    off_t i;
     unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, tmp;
     int perpix;
@@ -96,5 +97,5 @@
 # ifdef BYTE_SWAP 
   {
-    int i;
+    off_t i;
     unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, tmp;
     int perpix;
Index: trunk/Ohana/src/libfits/table/F_create_T.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_create_T.c	(revision 27392)
+++ trunk/Ohana/src/libfits/table/F_create_T.c	(revision 27435)
@@ -5,5 +5,5 @@
 int gfits_create_table (Header *header, FTable *table) {
 
-  int Nbytes;
+  off_t Nbytes;
   char type[80];
 
@@ -19,5 +19,5 @@
     memset (table[0].buffer, 0, Nbytes);
   }
-  table[0].size = Nbytes;
+  table[0].datasize = Nbytes;
   return (TRUE);
 
@@ -29,5 +29,5 @@
 int gfits_create_vtable (Header *header, VTable *table, int Nrow) {
 
-  int i, Nx, Ny;
+  off_t i, Nx, Ny;
   char type[80];
 
@@ -37,10 +37,10 @@
   Nx = table[0].header[0].Naxis[0];
   Ny = table[0].header[0].Naxis[0];
-  table[0].size = gfits_data_size (header);
-  table[0].pad = table[0].size - Nx*Ny;
+  table[0].datasize = gfits_data_size (header);
+  table[0].pad = table[0].datasize - Nx*Ny;
  
   table[0].Nrow = Nrow;
   ALLOCATE (table[0].buffer, char *, MAX (Nrow, 1));
-  ALLOCATE (table[0].row, int, MAX (Nrow, 1));
+  ALLOCATE (table[0].row, off_t, MAX (Nrow, 1));
   for (i = 0; i < Nrow; i++) {
     ALLOCATE (table[0].buffer[i], char, Nx);
Index: trunk/Ohana/src/libfits/table/F_create_TH.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_create_TH.c	(revision 27392)
+++ trunk/Ohana/src/libfits/table/F_create_TH.c	(revision 27435)
@@ -13,5 +13,5 @@
   char axis[10];
   
-  header[0].size = NBYTES;
+  header[0].datasize = NBYTES;
 
   ALLOCATE (header[0].buffer, char, NBYTES);
@@ -27,5 +27,5 @@
   for (i = 0; i < header[0].Naxes; i++) {
     sprintf (axis, "NAXIS%d", i + 1);
-    gfits_modify (header,  axis, "%d", 1, header[0].Naxis[i], 1);
+    gfits_modify (header,  axis, "%lld", 1, (long long) header[0].Naxis[i]);
   }
   
Index: trunk/Ohana/src/libfits/table/F_define_column.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_define_column.c	(revision 27392)
+++ trunk/Ohana/src/libfits/table/F_define_column.c	(revision 27435)
@@ -5,5 +5,6 @@
 int gfits_define_bintable_column (Header *header, char *format, char *label, char *comment, char *unit, double bscale, double bzero) {
 
-  int Nfields, Nbytes, Nval, Naxis1;
+  off_t Naxis1;
+  int Nfields, Nbytes, Nval;
   char type[16], field[16];
   
@@ -12,5 +13,5 @@
   Nfields = 0;
   gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
-  gfits_scan (header, "NAXIS1",  "%d", 1, &Naxis1);
+  gfits_scan (header, "NAXIS1",  "%lld", 1, (long long *) &Naxis1);
   Nfields ++;
   Naxis1 += Nbytes*Nval;
@@ -18,5 +19,5 @@
   sprintf (field, "TTYPE%d", Nfields);
   gfits_modify (header, field, "%s", 1, label);
-  gfits_modify (header, field, "%C", 1, comment);
+  gfits_modify_alt (header, field, "%C", 1, comment);
   sprintf (field, "TUNIT%d", Nfields);
   gfits_modify (header, field, "%s", 1, unit);
@@ -34,5 +35,5 @@
   /* update TFIELDS & NAXIS1 */
   gfits_modify (header, "TFIELDS", "%d", 1, Nfields);
-  gfits_modify (header, "NAXIS1",  "%d", 1, Naxis1);
+  gfits_modify (header, "NAXIS1",  "%lld", 1, (long long) Naxis1);
   header[0].Naxis[0] = Naxis1;
 
@@ -43,5 +44,6 @@
 int gfits_define_table_column (Header *header, char *format, char *label, char *comment, char *unit) {
 
-  int Nstart, Nfields, Nbytes, Nval, Naxis1;
+  off_t Naxis1;
+  int Nstart, Nfields, Nbytes, Nval;
   char type[16], field[16], cformat[16];
 
@@ -51,5 +53,5 @@
   Nfields = 0;
   gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
-  gfits_scan (header, "NAXIS1",  "%d", 1, &Naxis1);
+  gfits_scan (header, "NAXIS1",  "%lld", 1, (long long *) &Naxis1);
   Nstart = Naxis1 + 1;
   Nfields ++;
@@ -58,5 +60,5 @@
   sprintf (field, "TTYPE%d", Nfields);
   gfits_modify (header, field, "%s", 1, label);
-  gfits_modify (header, field, "%C", 1, comment);
+  gfits_modify_alt (header, field, "%C", 1, comment);
   sprintf (field, "TUNIT%d", Nfields);
   gfits_modify (header, field, "%s", 1, unit);
@@ -68,5 +70,5 @@
 
   gfits_modify (header, "TFIELDS", "%d", 1, Nfields);
-  gfits_modify (header, "NAXIS1",  "%d", 1, Naxis1);
+  gfits_modify (header, "NAXIS1",  "%lld", 1, (long long) Naxis1);
   header[0].Naxis[0] = Naxis1;
 
Index: trunk/Ohana/src/libfits/table/F_get_column.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_get_column.c	(revision 27392)
+++ trunk/Ohana/src/libfits/table/F_get_column.c	(revision 27435)
@@ -16,7 +16,8 @@
   tmp = Pin[3]; Pin[3] = Pin[4]; Pin[4] = tmp; }
 
-void *gfits_get_bintable_column_data (Header *header, FTable *table, char *label, char *type, int *Nrow, int *Ncol) {
-
-  int i, N, Nfields, Nval, Nbytes, Nx, Ny, Nstart, Nv, Nb;
+void *gfits_get_bintable_column_data (Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol) {
+
+  off_t Nx, Ny;
+  int i, N, Nfields, Nval, Nbytes, Nstart, Nv, Nb;
   char tlabel[80], field[80], format[80], tmpline[16];
   char *Pin, *Pout, *array;
@@ -50,6 +51,6 @@
   
   /* check existing table dimensions */
-  gfits_scan (header, "NAXIS1",  "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1",  "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2",  "%lld", 1, (long long *) &Ny);
 
   /* scan columns to find insert point */
@@ -153,5 +154,6 @@
 int gfits_get_bintable_column (Header *header, FTable *table, char *label, void **data) {
 
-  int i, N, Nfields, Nval, Nbytes, Nx, Ny, Nstart, Nv, Nb;
+  off_t Nx, Ny;
+  int i, N, Nfields, Nval, Nbytes, Nstart, Nv, Nb;
   char tlabel[80], field[80], format[80], type[16], tmpline[16];
   char *Pin, *Pout, *array;
@@ -185,6 +187,6 @@
   
   /* check existing table dimensions */
-  gfits_scan (header, "NAXIS1",  "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1",  "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2",  "%lld", 1, (long long *) &Ny);
 
   /* scan columns to find insert point */
@@ -307,5 +309,6 @@
 int gfits_get_table_column (Header *header, FTable *table, char *label, void **data) {
 
-  int i, N, Nfields, Nval, Nbytes, Nx, Ny, Nstart, Nv, Nb;
+  off_t Nx, Ny;
+  int i, N, Nfields, Nval, Nbytes, Nstart, Nv, Nb;
   char tlabel[80], field[80], format[80], cformat[80], type[16], tmp[16];
   char *array, *Pin, *Pout, *line;
@@ -333,6 +336,6 @@
   
   /* check existing table dimensions */
-  gfits_scan (header, "NAXIS1",  "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1",  "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2",  "%lld", 1, (long long *) &Ny);
 
   /* scan columns to find insert point */
Index: trunk/Ohana/src/libfits/table/F_read_T.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_read_T.c	(revision 27392)
+++ trunk/Ohana/src/libfits/table/F_read_T.c	(revision 27435)
@@ -19,10 +19,11 @@
 int gfits_fread_ftable (FILE *f, FTable *table, char *extname) {
 
-  int j, found, Nbytes;
+  int j, found;
+  off_t Nbytes;
   Header *header;
   char tname[80];
 
   header = table[0].header;
-  fseek (f, 0, SEEK_SET);
+  fseeko (f, 0, SEEK_SET);
 
   found = FALSE;
@@ -42,5 +43,5 @@
     /* skip to next header */
     Nbytes = gfits_data_size (header);
-    fseek (f, Nbytes, SEEK_CUR);
+    fseeko (f, Nbytes, SEEK_CUR);
     gfits_free_header (header);
   }
@@ -51,5 +52,5 @@
 int gfits_fread_ftable_data (FILE *f, FTable *table) {
 
-  int Nbytes, Nread;
+  off_t Nbytes, Nread;
   char string[128];
 
@@ -63,5 +64,5 @@
     perror (string);
     if (Nread < gfits_data_min_size (table[0].header)) {
-      fprintf (stderr, "error: fits read error in %s, read %d, need %d\n", __func__, Nread, gfits_data_min_size (table[0].header));
+      fprintf (stderr, "error: fits read error in %s, read %lld, need %lld\n", __func__, (long long) Nread, (long long) gfits_data_min_size (table[0].header));
       gfits_free_table  (table);
       return (FALSE);
@@ -69,12 +70,12 @@
     fprintf (stderr, "warning: file missing pad\n");
   }
-  table[0].size = Nbytes;
+  table[0].datasize = Nbytes;
   return (TRUE);
 }	
 
 /*********************** fits read ftable data ***********************************/
-int gfits_fread_ftable_range (FILE *f, FTable *table, int start, int Nrows) {
-
-  int Nbytes, Nread, Nskip, Nx, Ny;
+int gfits_fread_ftable_range (FILE *f, FTable *table, off_t start, off_t Nrows) {
+
+  off_t Nbytes, Nread, Nskip, Nx, Ny;
 
   /* find disk table size */
@@ -93,5 +94,5 @@
   ALLOCATE (table[0].buffer, char, MAX (Nbytes, 1));
 
-  fseek (f, Nskip, SEEK_CUR);
+  fseeko (f, Nskip, SEEK_CUR);
 
   Nread = fread (table[0].buffer, sizeof (char), Nbytes, f);
@@ -108,6 +109,6 @@
   /* modify structure and header to match actual read rows Ny */
   table[0].header[0].Naxis[1] = Nrows;
-  gfits_modify (table[0].header, "NAXIS2",  "%d", 1, Nrows);
-  table[0].size = gfits_data_size (table[0].header);
+  gfits_modify (table[0].header, "NAXIS2",  "%lld", 1, (long long) Nrows);
+  table[0].datasize = gfits_data_size (table[0].header);
 
   return (TRUE);
@@ -115,7 +116,7 @@
 
 /*********************** fits read ftable data ***********************************/
-int gfits_fread_vtable_range (FILE *f, VTable *table, int start, int Nrows) {
-
-  int i, Nbytes, Nread, Nskip, Nx, Ny;
+int gfits_fread_vtable_range (FILE *f, VTable *table, off_t start, off_t Nrows) {
+
+  off_t i, Nbytes, Nread, Nskip, Nx, Ny;
   char *buffer;
 
@@ -123,6 +124,6 @@
   Nx = table[0].header[0].Naxis[0];
   Ny = table[0].header[0].Naxis[1];
-  table[0].size = gfits_data_size (table[0].header);
-  table[0].pad = table[0].size - Nx*Ny;
+  table[0].datasize = gfits_data_size (table[0].header);
+  table[0].pad = table[0].datasize - Nx*Ny;
 
   if (start < 0) return (FALSE);
@@ -133,5 +134,5 @@
   ALLOCATE (buffer, char, MAX (Nbytes, 1));
 
-  fseek (f, Nskip, SEEK_CUR);
+  fseeko (f, Nskip, SEEK_CUR);
   Nread = fread (buffer, sizeof (char), Nbytes, f);
   if (Nread != Nbytes) {
@@ -141,5 +142,5 @@
   }
 
-  ALLOCATE (table[0].row, int, MAX (Nrows, 1));
+  ALLOCATE (table[0].row, off_t, MAX (Nrows, 1));
   ALLOCATE (table[0].buffer, char *, MAX (Nrows, 1));
   for (i = 0; i < Nrows; i++) {
@@ -154,13 +155,14 @@
 
 /*********************** fits read virtual table ***********************************/
-int gfits_fread_vtable (FILE *f, VTable *table, char *extname, int Nrow, int *row) {
-
-  int i, j, Nbytes, Nread;
-  int start, Nx, Ny, offset;
+int gfits_fread_vtable (FILE *f, VTable *table, char *extname, off_t Nrow, off_t *row) {
+
+  off_t i, j;
+  off_t Nbytes, Nread;
+  off_t start, Nx, Ny, offset;
   Header *header;
   char tname[80];
 
   header = table[0].header;
-  fseek (f, 0, SEEK_SET);
+  fseeko (f, 0, SEEK_SET);
 
   for (j = -1; TRUE; j++) {
@@ -176,5 +178,5 @@
     if (strcmp (tname, extname)) {
       /* skip to next header */
-      fseek (f, Nbytes, SEEK_CUR);
+      fseeko (f, Nbytes, SEEK_CUR);
       gfits_free_header (header);
       continue;
@@ -182,7 +184,7 @@
 
     /* file pointer is at beginning of desired table data */
-    start = ftell (f);
-    gfits_scan (header, "NAXIS1", "%d", 1, &Nx);
-    gfits_scan (header, "NAXIS2", "%d", 1, &Ny);
+    start = ftello (f);
+    gfits_scan (header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+    gfits_scan (header, "NAXIS2", "%lld", 1, (long long *) &Ny);
     for (i = 0; i < Nrow; i++) {
       if (row[i] > Ny) { return (FALSE); }
@@ -193,5 +195,5 @@
       ALLOCATE (table[0].buffer[i], char, MAX (1, Nx));
       offset = start + Nx*row[i];
-      fseek (f, offset, SEEK_SET);
+      fseeko (f, offset, SEEK_SET);
       Nread = fread (table[0].buffer[i], sizeof (char), Nx, f);
       if (Nread != Nx) { 
@@ -202,8 +204,8 @@
 
     table[0].Nrow  = Nrow;
-    ALLOCATE (table[0].row, int, MAX (1, Nrow));    
+    ALLOCATE (table[0].row, off_t, MAX (1, Nrow));    
     for (i = 0; i < Nrow; i++) table[0].row[i] = row[i];
-    table[0].size   = gfits_data_size (table[0].header);
-    table[0].pad    = table[0].size - Nx*Ny;
+    table[0].datasize = gfits_data_size (table[0].header);
+    table[0].pad      = table[0].datasize - Nx*Ny;
     return (TRUE);
   }
@@ -212,8 +214,8 @@
 int gfits_fread_header_extname (FILE *f, Header *header, char *extname) {
 
-  int Nbytes;
+  off_t Nbytes;
   char current[80];
 
-  fseek (f, 0, SEEK_SET);
+  fseeko (f, 0, SEEK_SET);
   gfits_fread_header (f, header);
 
@@ -221,5 +223,5 @@
 
   Nbytes = gfits_data_size (header);
-  fseek (f, Nbytes, SEEK_CUR);
+  fseeko (f, Nbytes, SEEK_CUR);
 
   while (gfits_fread_header (f, header)) {
@@ -227,5 +229,5 @@
     if (!strcmp (current, extname)) return (TRUE);
     Nbytes = gfits_data_size (header);
-    fseek (f, Nbytes, SEEK_CUR);
+    fseeko (f, Nbytes, SEEK_CUR);
   }
   return (FALSE);
Index: trunk/Ohana/src/libfits/table/F_read_TH.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_read_TH.c	(revision 27392)
+++ trunk/Ohana/src/libfits/table/F_read_TH.c	(revision 27435)
@@ -7,5 +7,6 @@
   FILE *f;
   Header header;
-  int status, Nbytes;
+  int status;
+  off_t Nbytes;
   
   status = gfits_read_header (filename, &header);
@@ -23,5 +24,5 @@
 
   Nbytes = gfits_data_size (&header);
-  fseek (f, Nbytes, SEEK_SET);
+  fseeko (f, Nbytes, SEEK_SET);
   gfits_free_header (&header);
 
@@ -36,7 +37,8 @@
   
   char *p;
-  int i, done, status, Nbytes;
+  int i, done, status;
+  off_t Nbytes;
   
-  Theader[0].size = 0;
+  Theader[0].datasize = 0;
   done = FALSE;
   ALLOCATE (Theader[0].buffer, char, 1);
@@ -44,13 +46,13 @@
   for (i = 0; !done; i++) {
     REALLOCATE (Theader[0].buffer, char, (i + 1)*FT_RECORD_SIZE);
-    Nbytes = fread (&Theader[0].buffer[i*FT_RECORD_SIZE], 
-		    sizeof(char), FT_RECORD_SIZE, f);
+    Nbytes = fread (&Theader[0].buffer[i*FT_RECORD_SIZE], sizeof(char), FT_RECORD_SIZE, f);
     if (Nbytes != FT_RECORD_SIZE) {
       perror ("fits matrix read error");
     }
 
-    Theader[0].size += Nbytes;
-    if (Nbytes != FT_RECORD_SIZE) 
+    Theader[0].datasize += Nbytes;
+    if (Nbytes != FT_RECORD_SIZE) {
       done = TRUE;
+    }
     p = gfits_header_field (Theader, "END", 1);
     if (p != NULL)
@@ -68,14 +70,14 @@
   if (!status) return (FALSE);
 				                           
-  gfits_scan (Theader,  "NAXIS1", "%d", 1, &Theader[0].Naxis[0]);
-  gfits_scan (Theader,  "NAXIS2", "%d", 1, &Theader[0].Naxis[1]);
-  gfits_scan (Theader,  "NAXIS3", "%d", 1, &Theader[0].Naxis[2]);
-  gfits_scan (Theader,  "NAXIS4", "%d", 1, &Theader[0].Naxis[3]);
-  gfits_scan (Theader,  "NAXIS5", "%d", 1, &Theader[0].Naxis[4]);
-  gfits_scan (Theader,  "NAXIS6", "%d", 1, &Theader[0].Naxis[5]);
-  gfits_scan (Theader,  "NAXIS7", "%d", 1, &Theader[0].Naxis[6]);
-  gfits_scan (Theader,  "NAXIS8", "%d", 1, &Theader[0].Naxis[7]);
-  gfits_scan (Theader,  "NAXIS9", "%d", 1, &Theader[0].Naxis[8]);
-  gfits_scan (Theader, "NAXIS10", "%d", 1, &Theader[0].Naxis[9]);
+  gfits_scan (Theader,  "NAXIS1", "%lld", 1, (long long *) &Theader[0].Naxis[0]);
+  gfits_scan (Theader,  "NAXIS2", "%lld", 1, (long long *) &Theader[0].Naxis[1]);
+  gfits_scan (Theader,  "NAXIS3", "%lld", 1, (long long *) &Theader[0].Naxis[2]);
+  gfits_scan (Theader,  "NAXIS4", "%lld", 1, (long long *) &Theader[0].Naxis[3]);
+  gfits_scan (Theader,  "NAXIS5", "%lld", 1, (long long *) &Theader[0].Naxis[4]);
+  gfits_scan (Theader,  "NAXIS6", "%lld", 1, (long long *) &Theader[0].Naxis[5]);
+  gfits_scan (Theader,  "NAXIS7", "%lld", 1, (long long *) &Theader[0].Naxis[6]);
+  gfits_scan (Theader,  "NAXIS8", "%lld", 1, (long long *) &Theader[0].Naxis[7]);
+  gfits_scan (Theader,  "NAXIS9", "%lld", 1, (long long *) &Theader[0].Naxis[8]);
+  gfits_scan (Theader, "NAXIS10", "%lld", 1, (long long *) &Theader[0].Naxis[9]);
 
   return (TRUE);
Index: trunk/Ohana/src/libfits/table/F_set_column.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_set_column.c	(revision 27392)
+++ trunk/Ohana/src/libfits/table/F_set_column.c	(revision 27435)
@@ -16,7 +16,9 @@
 
 /***********************/
-int gfits_set_bintable_column (Header *header, FTable *table, char *label, void *data, int Nrow) {
-
-  int i, N, Nfields, Nval, Nbytes, Nx, Ny, nbytes, Nstart, Nv, Nb;
+int gfits_set_bintable_column (Header *header, FTable *table, char *label, void *data, off_t Nrow) {
+
+  off_t Nx, Ny, nbytes;
+  int i, N, Nfields;
+  int Nval, Nbytes, Nstart, Nv, Nb;
   char tlabel[80], field[80], format[80], type[16], tmpline[16];
   char *Pin, *Pout, *array;
@@ -47,15 +49,15 @@
   
   /* check existing table dimensions */
-  gfits_scan (header, "NAXIS1",  "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2", "%lld", 1, (long long *) &Ny);
   if (Ny == 0) { 
     Ny = Nrow;
     header[0].Naxis[1] = Ny;
-    gfits_modify (header, "NAXIS2",  "%d", 1, Ny);
+    gfits_modify (header, "NAXIS2", "%lld", 1, (long long) Ny);
 
     nbytes = gfits_data_size (header);
     REALLOCATE (table[0].buffer, char, MAX (nbytes, 1));
     bzero (table[0].buffer, nbytes);
-    table[0].size = nbytes;
+    table[0].datasize = nbytes;
   }
   if (Ny != Nrow) return (FALSE);
@@ -151,7 +153,8 @@
 
 /***********************/
-int gfits_set_table_column (Header *header, FTable *table, char *label, void *data, int Nrow) {
-
-  int i, N, Nfields, Nval, Nbytes, Nx, Ny, nbytes, Nstart, Nv, Nb;
+int gfits_set_table_column (Header *header, FTable *table, char *label, void *data, off_t Nrow) {
+
+  off_t Nx, Ny, nbytes;
+  int i, N, Nfields, Nval, Nbytes, Nstart, Nv, Nb;
   char tlabel[80], field[80], format[80], cformat[80], type[16], tmp[16];
   char *array, *Pin, *Pout, *line;
@@ -178,15 +181,15 @@
   
   /* check existing table dimensions */
-  gfits_scan (header, "NAXIS1",  "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2", "%lld", 1, (long long *) &Ny);
   if (Ny == 0) { 
     Ny = Nrow;
     header[0].Naxis[1] = Ny;
-    gfits_modify (header, "NAXIS2",  "%d", 1, Ny);
+    gfits_modify (header, "NAXIS2", "%lld", 1, (long long) Ny);
 
     nbytes = gfits_data_size (header);
     REALLOCATE (table[0].buffer, char, MAX (nbytes, 1));
     bzero (table[0].buffer, nbytes);
-    table[0].size = nbytes;
+    table[0].datasize = nbytes;
   }
   if (Ny != Nrow) return (FALSE);
Index: trunk/Ohana/src/libfits/table/F_table_format.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_table_format.c	(revision 27392)
+++ trunk/Ohana/src/libfits/table/F_table_format.c	(revision 27435)
@@ -3,4 +3,7 @@
 
 /***********************/
+// get the format of a table column
+// Nval : number of joined columns
+// Nbytes : width of column
 int gfits_bintable_format (char *format, char *type, int *Nval, int *Nbytes) {
 
@@ -119,5 +122,5 @@
 
 /** extract a table subset to a vtable ***/
-int gfits_table_to_vtable (FTable *ftable, VTable *vtable, int start, int Nkeep) {
+int gfits_table_to_vtable (FTable *ftable, VTable *vtable, off_t start, off_t Nkeep) {
 
   /* gfits_table_to_vtable (f, v, 0, Ny - 1) - keep all of table
@@ -125,8 +128,8 @@
   */  
 
-  int i, Nx, Ny;
-
-  gfits_scan (ftable[0].header, "NAXIS1", "%d", 1, &Nx);
-  gfits_scan (ftable[0].header, "NAXIS2", "%d", 1, &Ny);
+  off_t i, Nx, Ny;
+
+  gfits_scan (ftable[0].header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (ftable[0].header, "NAXIS2", "%lld", 1, (long long *) &Ny);
   
   if (start + Nkeep > Ny) return (FALSE);
@@ -134,5 +137,5 @@
   if (Nkeep < 0) return (FALSE);
 
-  ALLOCATE (vtable[0].row, int, MAX (1, Nkeep));
+  ALLOCATE (vtable[0].row, off_t, MAX (1, Nkeep));
   ALLOCATE (vtable[0].buffer, char *, MAX (1, Nkeep));
   for (i = 0; i < Nkeep; i++) {
@@ -143,7 +146,7 @@
   
   vtable[0].header = ftable[0].header;
-  vtable[0].size = ftable[0].size;
+  vtable[0].datasize = ftable[0].datasize;
   vtable[0].Nrow = Nkeep;
-  vtable[0].pad = vtable[0].size - Nx*Ny;
+  vtable[0].pad = vtable[0].datasize - Nx*Ny;
 
   return (TRUE);
@@ -151,19 +154,19 @@
 
 /** convert specified rows to vtable */
-int gfits_vtable_from_ftable (FTable *ftable, VTable *vtable, int *row, int Nrow) {
-
-  int i, N, Nx, Ny;
-
-  gfits_scan (ftable[0].header, "NAXIS1", "%d", 1, &Nx);
-  gfits_scan (ftable[0].header, "NAXIS2", "%d", 1, &Ny);
+int gfits_vtable_from_ftable (FTable *ftable, VTable *vtable, off_t *row, off_t Nrow) {
+
+  off_t i, N, Nx, Ny;
+
+  gfits_scan (ftable[0].header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (ftable[0].header, "NAXIS2", "%lld", 1, (long long *) &Ny);
 
   /* make empty vtable from table */
-  vtable[0].header = ftable[0].header;  /* make this a copy? */
-  vtable[0].size   = ftable[0].size;
-  vtable[0].pad    = vtable[0].size - Nx*Ny;
-  vtable[0].Nrow   = Ny;
+  vtable[0].header   = ftable[0].header;  /* make this a copy? */
+  vtable[0].datasize = ftable[0].datasize;
+  vtable[0].pad      = vtable[0].datasize - Nx*Ny;
+  vtable[0].Nrow     = Ny;
 
   /* insert selected rows in vtable (mask rows marked with -1) */ 
-  ALLOCATE (vtable[0].row, int, Nrow);
+  ALLOCATE (vtable[0].row, off_t, Nrow);
   ALLOCATE (vtable[0].buffer, char *, Nrow);
   for (N = i = 0; i < Nrow; i++) {
@@ -181,6 +184,6 @@
 char *gfits_table_print (FTable *table,...) { 
   
-  int i, Nx, Nfields;
-  int off, Nchar, Nval, Nbytes;
+  off_t Nx, off;
+  int i, Nchar, Nval, Nbytes, Nfields;
   char *line, format[64], field[16], type[16];
   va_list argp;
@@ -188,5 +191,5 @@
   va_start (argp, table);
 
-  gfits_scan (table[0].header, "NAXIS1",  "%d", 1, &Nx);
+  gfits_scan (table[0].header, "NAXIS1",  "%lld", 1, (long long *) &Nx);
   gfits_scan (table[0].header, "TFIELDS", "%d", 1, &Nfields);
 
@@ -220,7 +223,8 @@
 // apply table tzero, tscal in situ (from storage to data)
 int gfits_table_scale_data (FTable *ftable) {
-
-  int i, j, n, Nx, Ny, Nfields;
-  int off, Nchar, Nval, Nbytes, status;
+  
+  off_t Nx, Ny, off;
+  int i, j, n, Nfields;
+  int Nchar, Nval, Nbytes, status;
   char format[64], field[16], type[16];
   double tzero, tscale;
@@ -232,6 +236,6 @@
   off = 0;
 
-  gfits_scan (ftable[0].header, "NAXIS1",  "%d", 1, &Nx);
-  gfits_scan (ftable[0].header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (ftable[0].header, "NAXIS1",  "%lld", 1, (long long *) &Nx);
+  gfits_scan (ftable[0].header, "NAXIS2",  "%lld", 1, (long long *) &Ny);
   gfits_scan (ftable[0].header, "TFIELDS", "%d", 1, &Nfields);
 
@@ -304,6 +308,7 @@
 int gfits_table_scale_storage (FTable *ftable) {
 
-  int i, j, n, Nx, Ny, Nfields;
-  int off, Nchar, Nval, Nbytes, status;
+  off_t Nx, Ny, off;
+  int i, j, n, Nfields;
+  int Nchar, Nval, Nbytes, status;
   char format[64], field[16], type[16];
   double tzero, tscale;
@@ -315,6 +320,6 @@
   off = 0;
 
-  gfits_scan (ftable[0].header, "NAXIS1",  "%d", 1, &Nx);
-  gfits_scan (ftable[0].header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (ftable[0].header, "NAXIS1",  "%lld", 1, (long long *) &Nx);
+  gfits_scan (ftable[0].header, "NAXIS2",  "%lld", 1, (long long *) &Ny);
   gfits_scan (ftable[0].header, "TFIELDS", "%d", 1, &Nfields);
 
Index: trunk/Ohana/src/libfits/table/F_table_row.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_table_row.c	(revision 27392)
+++ trunk/Ohana/src/libfits/table/F_table_row.c	(revision 27435)
@@ -3,14 +3,14 @@
 
 /*********************** fits table column ****************************/
-int gfits_add_rows (FTable *table, char *data, int Nrow, int Nbytes) {
+int gfits_add_rows (FTable *table, char *data, off_t Nrow, off_t Nbytes) {
 
-  int Nx, Ny;
-  int nbytes, Nstart;
+  off_t Nx, Ny;
+  off_t nbytes, Nstart;
   Header *header;
 
   header = table[0].header;
 
-  gfits_scan (header, "NAXIS1", "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2", "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2", "%lld", 1, (long long *) &Ny);
   
   if (header[0].Naxis[1] != Ny) return (FALSE);
@@ -23,9 +23,9 @@
   Ny += Nrow;
   header[0].Naxis[1] = Ny;
-  gfits_modify (header, "NAXIS2",  "%d", 1, Ny);
+  gfits_modify (header, "NAXIS2",  "%lld", 1, (long long) Ny);
 
   nbytes = gfits_data_size (header);
   REALLOCATE (table[0].buffer, char, MAX (nbytes, 1));
-  table[0].size = nbytes;
+  table[0].datasize = nbytes;
   
   memcpy (&table[0].buffer[Nstart], data, Nbytes*Nrow);
@@ -35,14 +35,14 @@
 
 /*********************** fits add (real) rows to virtual table ****************************/
-int gfits_vadd_rows (VTable *table, char *data, int Nrow, int Nbytes) {
+int gfits_vadd_rows (VTable *table, char *data, off_t Nrow, off_t Nbytes) {
 
-  int i, Nx, Ny;
-  int Nstart;
+  off_t i, Nx, Ny;
+  off_t Nstart;
   Header *header;
 
   header = table[0].header;
 
-  gfits_scan (header, "NAXIS1", "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2", "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2", "%lld", 1, (long long *) &Ny);
   
   if (header[0].Naxis[1] != Ny) return (FALSE);
@@ -54,5 +54,5 @@
   table[0].Nrow += Nrow;
   REALLOCATE (table[0].buffer, char *, table[0].Nrow);
-  REALLOCATE (table[0].row, int, table[0].Nrow);
+  REALLOCATE (table[0].row, off_t, table[0].Nrow);
   for (i = 0; i < Nrow; i++) {
     ALLOCATE (table[0].buffer[Nstart+i], char, MAX (1, Nx));
@@ -64,8 +64,8 @@
   Ny += Nrow;
   header[0].Naxis[1] = Ny;
-  gfits_modify (header, "NAXIS2",  "%d", 1, Ny);
+  gfits_modify (header, "NAXIS2", "%lld", 1, (long long) Ny);
 
-  table[0].size   = gfits_data_size (table[0].header);
-  table[0].pad    = table[0].size - Nx*Ny;
+  table[0].datasize = gfits_data_size (table[0].header);
+  table[0].pad      = table[0].datasize - Nx*Ny;
 
   return (TRUE);
@@ -73,14 +73,14 @@
 
 /*********************** fits table column ****************************/
-int gfits_delete_rows (FTable *table, int Nstart, int Nrow) {
+int gfits_delete_rows (FTable *table, off_t Nstart, off_t Nrow) {
 
-  int Nx, Ny, N0, N1, N2;
-  int nbytes;
+  off_t Nx, Ny, N0, N1, N2;
+  off_t nbytes;
   Header *header;
 
   header = table[0].header;
 
-  gfits_scan (header, "NAXIS1", "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2", "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2", "%lld", 1, (long long *) &Ny);
   
   if (header[0].Naxis[1] != Ny) return (FALSE);
@@ -97,9 +97,9 @@
   Ny -= Nrow;
   header[0].Naxis[1] = Ny;
-  gfits_modify (header, "NAXIS2",  "%d", 1, Ny);
+  gfits_modify (header, "NAXIS2", "%lld", 1, (long long) Ny);
 
   nbytes = gfits_data_size (header);
   REALLOCATE (table[0].buffer, char, MAX (nbytes, 1));
-  table[0].size = nbytes;
+  table[0].datasize = nbytes;
   return (TRUE);
 }
Index: trunk/Ohana/src/libfits/table/F_table_varlength.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_table_varlength.c	(revision 27392)
+++ trunk/Ohana/src/libfits/table/F_table_varlength.c	(revision 27435)
@@ -4,5 +4,6 @@
 int gfits_varlength_column_define (FTable *ftable, VarLengthColumn *def, int column) {
 
-  int i, Nv, Nb;
+  int i;
+  int Nv, Nb;
   char *p1, *p2, *p3;
   char field[81];
@@ -32,5 +33,6 @@
   // now p1 must be 'P';
   if (*p1 == 0) return (FALSE);
-  if (*p1 != 'P') return (FALSE);
+  if ((*p1 != 'P') && (*p1 != 'Q')) return (FALSE);
+  def->mode = *p1;
 
   // next value is the actual varlength column format
@@ -61,5 +63,6 @@
   }
 
-  if (!gfits_scan (ftable->header, "THEAP", "%d", 1, &def->heap_start)) {
+  // heap_start must be long long so file may be very large
+  if (!gfits_scan (ftable->header, "THEAP", "%lld", 1, (long long *) &def->heap_start)) {
     def->heap_start = ftable->header->Naxis[0]*ftable->header->Naxis[1];
   }
@@ -68,8 +71,12 @@
 }
 
-void *gfits_varlength_column_pointer (FTable *ftable, VarLengthColumn *column, int row, int *length) {
+// return the data and length for row 'row' of a variable length column
+// is this capable of handling large files (value holding length and offset is an int)?
+void *gfits_varlength_column_pointer (FTable *ftable, VarLengthColumn *column, off_t row, off_t *length) {
 
   void *result;
-  int offset, Nx, *ptr;
+  off_t offset, Nx;
+
+  if ((column->mode != 'P') && (column->mode != 'Q')) abort();
 
   // find the values for the specified row
@@ -89,7 +96,16 @@
 # endif
 
-  ptr = (int *) &ftable->buffer[row*Nx + column->Nstart];
-  *length = ptr[0];
-  offset = ptr[1];
+  if (column->mode == 'P') {
+    int *ptr;
+    ptr = (int *) &ftable->buffer[row*Nx + column->Nstart];
+    *length = ptr[0];
+    offset = ptr[1];
+  }
+  if (column->mode == 'Q') {
+    off_t *ptr;
+    ptr = (off_t *) &ftable->buffer[row*Nx + column->Nstart];
+    *length = ptr[0];
+    offset = ptr[1];
+  }
 
   result = (void *) (ftable->buffer + column->heap_start + offset);
Index: trunk/Ohana/src/libfits/table/F_write_T.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_write_T.c	(revision 27392)
+++ trunk/Ohana/src/libfits/table/F_write_T.c	(revision 27435)
@@ -13,5 +13,5 @@
   if (f == (FILE *) NULL) return (FALSE);
   
-  status = fseek (f, 0, SEEK_END);  /* write table to end of file! */
+  status = fseeko (f, 0LL, SEEK_END);  /* write table to end of file! */
   status = gfits_fwrite_table (f, table);
 
@@ -23,9 +23,9 @@
 int gfits_fwrite_table (FILE *f, FTable *table) {
   
-  int Nbytes;
+  off_t Nbytes;
   
-  Nbytes = fwrite (table[0].buffer, sizeof(char), table[0].size, f);
+  Nbytes = fwrite (table[0].buffer, sizeof(char), table[0].datasize, f);
   
-  if (Nbytes != table[0].size) return (FALSE);
+  if (Nbytes != table[0].datasize) return (FALSE);
   return (TRUE);
 }	
@@ -34,29 +34,29 @@
 int gfits_fwrite_vtable (FILE *f, VTable *table) {
   
-  int i, Nx, Ny, Npad, offset, start;
-  int Nbytes, *row, Nrow;
+  off_t i, Nx, Ny, Npad, offset, start;
+  off_t Nbytes, *row, Nrow;
   char *pad;
 
   Nrow = table[0].Nrow;
   row = table[0].row;
-  gfits_scan (table[0].header, "NAXIS1", "%d", 1, &Nx);
-  gfits_scan (table[0].header, "NAXIS2", "%d", 1, &Ny);
+  gfits_scan (table[0].header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (table[0].header, "NAXIS2", "%lld", 1, (long long *) &Ny);
 
   /* file pointer is at beginning of desired table data */
-  start = ftell (f);
+  start = ftello (f);
   
   for (i = 0; i < Nrow; i++) {
     offset = start + Nx*row[i];
-    fseek (f, offset, SEEK_SET);
+    fseeko (f, offset, SEEK_SET);
     Nbytes = fwrite (table[0].buffer[i], sizeof (char), Nx, f);
     if (Nbytes != Nx) { return (FALSE); }
   }
   
-  Npad = table[0].size - Nx*Ny;
+  Npad = table[0].datasize - Nx*Ny;
   ALLOCATE (pad, char, Npad);
   bzero (pad, Npad);
 
   offset = start + Nx*Ny;
-  fseek (f, offset, SEEK_SET);
+  fseeko (f, offset, SEEK_SET);
   Nbytes = fwrite (pad, sizeof (char), Npad, f);
   if (Nbytes != Npad) { return (FALSE); }
@@ -71,7 +71,7 @@
 
 /*********************** fits read ftable data ***********************************/
-int gfits_fwrite_ftable_range (FILE *f, FTable *ftable, int start, int Nrows, int Ndisk, int Ntotal) {
+int gfits_fwrite_ftable_range (FILE *f, FTable *ftable, off_t start, off_t Nrows, off_t Ndisk, off_t Ntotal) {
 
-  int Nbytes, Nwrite, Nskip, Nx, Npad;
+  off_t Nbytes, Nwrite, Nskip, Nx, Npad;
   char *pad;
 
@@ -79,9 +79,9 @@
   
   /* modify vtable to represent full disk table */
-  gfits_modify (ftable[0].header, "NAXIS2", "%d", 1, Ntotal);
+  gfits_modify (ftable[0].header, "NAXIS2", "%lld", 1, (long long) Ntotal);
   ftable[0].header[0].Naxis[1] = Ntotal;
 
   Nx = ftable[0].header[0].Naxis[0]; // final output table size on disk 
-  ftable[0].size = gfits_data_size (ftable[0].header);
+  ftable[0].datasize = gfits_data_size (ftable[0].header);
 
   Nskip = start * Nx;
@@ -95,5 +95,5 @@
 
   // cursor must be at start of the table (after table header)
-  fseek (f, Nskip, SEEK_CUR);
+  fseeko (f, Nskip, SEEK_CUR);
   Nwrite = fwrite (ftable[0].buffer, sizeof (char), Nbytes, f);
   if (Nwrite != Nbytes) {
@@ -102,5 +102,5 @@
 
   if (Ntotal >= Ndisk) {
-    Npad = ftable[0].size - Nx*Ntotal;
+    Npad = ftable[0].datasize - Nx*Ntotal;
     ALLOCATE (pad, char, Npad);
     bzero (pad, Npad);
Index: trunk/Ohana/src/libfits/table/F_write_TH.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_write_TH.c	(revision 27392)
+++ trunk/Ohana/src/libfits/table/F_write_TH.c	(revision 27435)
@@ -13,5 +13,5 @@
   if (f == (FILE *) NULL) return (FALSE);
   
-  status = fseek (f, 0, SEEK_END);  /* write header to end of file! */
+  status = fseeko (f, 0LL, SEEK_END);  /* write header to end of file! */
   status = gfits_fwrite_Theader (f, header);
 
@@ -23,9 +23,9 @@
 int gfits_fwrite_Theader (FILE *f, Header *header) {
   
-  int Nbytes;
+  off_t Nbytes;
   
-  Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].size, f);
+  Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].datasize, f);
 
-  if (Nbytes != header[0].size) return (FALSE);
+  if (Nbytes != header[0].datasize) return (FALSE);
   return (TRUE);
 }	
Index: trunk/Ohana/src/libkapa/include/kapa.h
===================================================================
--- trunk/Ohana/src/libkapa/include/kapa.h	(revision 27392)
+++ trunk/Ohana/src/libkapa/include/kapa.h	(revision 27435)
@@ -109,9 +109,9 @@
 
 /* IOfuncs.c */
-int KiiSendMessage (int device, char *format, ...);
-int KiiScanMessage (int device, char *format, ...);
-int KiiSendCommand (int device, int length, char *format, ...);
+int KiiSendMessage (int device, char *format, ...) OHANA_FORMAT(printf, 2, 3);
+int KiiScanMessage (int device, char *format, ...) OHANA_FORMAT(scanf, 2, 3);
+int KiiSendCommand (int device, int length, char *format, ...) OHANA_FORMAT(printf, 3, 4);
+int KiiScanCommand (int device, int length, char *format, ...) OHANA_FORMAT(scanf, 3, 4);
 int KiiSendCommandV (int device, int length, char *format, va_list argp);
-int KiiScanCommand (int device, int length, char *format, ...);
 int KiiSendData (int device, char *data, int Nbytes);
 char *KiiRecvData (int device);
Index: trunk/Ohana/src/libohana/Makefile
===================================================================
--- trunk/Ohana/src/libohana/Makefile	(revision 27392)
+++ trunk/Ohana/src/libohana/Makefile	(revision 27435)
@@ -17,12 +17,8 @@
 FULL_CPPFLAGS = $(BASE_CPPFLAGS)
 FULL_LDFLAGS  = $(BASE_LDFLAGS)
-TFLAGS        = $(FULL_CFLAGS) $(FULL_LDFLAGS) -ltap_ohana
+TFLAGS        = $(FULL_CFLAGS) $(FULL_CPPFLAGS) $(FULL_LDFLAGS) -lohana -ltap_ohana
 
 install: $(DESTLIB)/libohana.a $(DESTLIB)/libohana.$(DLLTYPE)
 libohana: $(LIB)/libohana.$(ARCH).a $(LIB)/libohana.$(ARCH).$(DLLTYPE)
-testcode: install $(TEST)
-test:
-	make testcode
-	for i in $(TEST); do $$i; done
 
 INCS = \
@@ -48,4 +44,9 @@
 $(TESTDIR)/string.$(ARCH)
 
+testcode: install $(TEST)
+test:
+	make testcode
+	for i in $(TEST); do $$i; done
+
 $(OBJS): $(INCS)
 
Index: trunk/Ohana/src/libohana/doc/largefiles.txt
===================================================================
--- trunk/Ohana/src/libohana/doc/largefiles.txt	(revision 27435)
+++ trunk/Ohana/src/libohana/doc/largefiles.txt	(revision 27435)
@@ -0,0 +1,24 @@
+
+2010.03.15 : converting libohana / libfits to handle large files:
+
+  * need to change all file I/O operations to be largefile safe:
+    * fseek -> fseeko + offset -> off_t
+    * read / fread -> size & nmemb -> off_t
+    * write / fwrite -> size & nmemb -> off_t
+    * ftell -> ftello + offset -> off_t
+
+  * I am changing FILE not IO interactions (thus CommOps.c & IOBuffers.c do not change)
+
+  * in Ohana : Fread, Fwrite, Fseek, ByteSwap 
+
+  * in libfits:
+    * added lld, llu, Ld, Lu support for gfits_scan, gfits_print, gfits_modify
+    * Header, Matrix, FTable, VTable : 
+      * size -> datasize (off_t)
+      * Naxis[i] -> off_t
+      * row, Nrow, pad -> off_t
+
+  * need to search for NAXIS1,2,3 etc
+  * need to search for tables
+  * need to search for fseek, read, write functions
+
Index: trunk/Ohana/src/libohana/include/ohana.h
===================================================================
--- trunk/Ohana/src/libohana/include/ohana.h	(revision 27392)
+++ trunk/Ohana/src/libohana/include/ohana.h	(revision 27435)
@@ -68,4 +68,10 @@
 # endif
 
+#ifdef __GNUC__
+#define OHANA_FORMAT(style, fmt, varargs) __attribute__((format(style, fmt, varargs)))
+#else // __GNUC__
+#define OHANA_FORMAT(style, fmt, varargs)
+#endif // __GNUC__
+
 enum {
  LCK_UNLOCK,        /* file is unlocked */
@@ -177,5 +183,5 @@
 char   *SelectConfigFile       PROTO((int *argc, char **argv, char *progname));
 char   *LoadConfigFile         PROTO((char *filename));
-char   *ScanConfig             PROTO((char *config, char *field, char *mode, int N,...));
+char   *ScanConfig             PROTO((char *config, char *field, char *mode, int N,...)) OHANA_FORMAT(scanf, 3, 5);
 char   *expandline             PROTO((char *line, char *config));
 char   *fileextname            PROTO((char *file));
@@ -214,5 +220,5 @@
 int 	EmptyIOBuffer  	       PROTO((IOBuffer *buffer, int Nmax, int fd));
 void    FreeIOBuffer   	       PROTO((IOBuffer *buffer));
-int 	PrintIOBuffer  	       PROTO((IOBuffer *buffer, char *format, ...));
+int 	PrintIOBuffer  	       PROTO((IOBuffer *buffer, char *format, ...)) OHANA_FORMAT(printf, 2, 3);
 int 	vPrintIOBuffer 	       PROTO((IOBuffer *buffer, char *format, va_list argp));
 
@@ -220,10 +226,13 @@
 int 	ExpectMessage 	       PROTO((int device, double timeout, IOBuffer *message));
 int 	ExpectCommand 	       PROTO((int device, int length, double timeout, IOBuffer *buffer));
-int 	SendMessage   	       PROTO((int device, char *format, ...));
+int 	SendMessage   	       PROTO((int device, char *format, ...)) OHANA_FORMAT(printf, 2, 3);
 int 	SendMessageFixed       PROTO((int device, int length, char *messge));
-int 	SendCommand   	       PROTO((int device, int length, char *format, ...));
+int 	SendCommand   	       PROTO((int device, int length, char *format, ...)) OHANA_FORMAT(printf, 3, 4);
 int 	SendCommandV  	       PROTO((int device, int length, char *format, va_list argp));
 
 char   *CheckForMessage        PROTO((IOBuffer *buffer));
+
+off_t   Fread                  PROTO((void *ptr, off_t size, off_t nitems, FILE *f, char *type));
+off_t   Fwrite                 PROTO((void *ptr, off_t size, off_t nitems, FILE *f, char *type));
 
 /*
Index: trunk/Ohana/src/libohana/include/ohana_sort.h
===================================================================
--- trunk/Ohana/src/libohana/include/ohana_sort.h	(revision 27392)
+++ trunk/Ohana/src/libohana/include/ohana_sort.h	(revision 27435)
@@ -70,4 +70,5 @@
 void dsortpair (double *X, double *Y, int N);
 void isortpair (int *X, int *Y, int N);
+void llsortpair (off_t *X, off_t *Y, off_t N);
 void fsortthree (float *X, float *Y, float *Z, int N);
 void dsortthree (double *X, double *Y, double *Z, int N);
Index: trunk/Ohana/src/libohana/src/CommOps.c
===================================================================
--- trunk/Ohana/src/libohana/src/CommOps.c	(revision 27392)
+++ trunk/Ohana/src/libohana/src/CommOps.c	(revision 27435)
@@ -103,5 +103,4 @@
 int SendMessageFixed (int device, int length, char *message) {
 
-  int status;
   int Nbytes, Nsent;
   struct timespec request, remain;
Index: trunk/Ohana/src/libohana/src/Fread.c
===================================================================
--- trunk/Ohana/src/libohana/src/Fread.c	(revision 27392)
+++ trunk/Ohana/src/libohana/src/Fread.c	(revision 27435)
@@ -1,5 +1,5 @@
 # include <ohana.h>
 
-int   ByteSwap (char *ptr, int size, int nitems, char *type);
+static int ByteSwap (char *ptr, off_t size, off_t nitems, char *type);
 
 # define BYTE_EXCHANGE(X,Y) tmp = byte[X]; byte[X] = byte[Y]; byte[Y] = tmp;
@@ -30,7 +30,8 @@
 /* add other architectures here, ie dec, alpha, etc */ 
 
-int Fread (void *ptr, int size, int nitems, FILE *f, char *type) {
+off_t Fread (void *ptr, off_t size, off_t nitems, FILE *f, char *type) {
 
-  int valid, status;
+  int valid;
+  off_t status;
 
   status = fread (ptr, size, nitems, f);
@@ -42,7 +43,8 @@
 }
 
-int Fwrite (void *ptr, int size, int nitems, FILE *f, char *type) {
+off_t Fwrite (void *ptr, off_t size, off_t nitems, FILE *f, char *type) {
 
-  int valid, status;
+  int valid;
+  off_t status;
 
   valid = ByteSwap (ptr, size, nitems, type);
@@ -54,9 +56,9 @@
 }
 
-int ByteSwap (char *ptr, int size, int nitems, char *type) {
+static int ByteSwap (char *ptr, off_t size, off_t nitems, char *type) {
 
 # ifdef BYTE_SWAP
 
-  int i;
+  off_t i;
   unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, tmp;
 
@@ -116,351 +118,4 @@
   }
 
-# if (0) /** now in autocode **/
-  if (!strcmp (type, "regimage")) {
-    if (size != REGIMAGE_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (RegImage) %d vs %d\n", size, REGIMAGE_SIZE);
-      return (FALSE);
-    }
-    byte = (unsigned char *)ptr;
-    for (i = 0; i < nitems; i++, byte += REGIMAGE_SIZE) {
-      SWAP_WORD (284); /* exptime */ 
-      SWAP_WORD (288); /* airmass */ 
-      SWAP_WORD (292); /* sky */     
-      SWAP_WORD (296); /* bias */    
-      SWAP_WORD (300); /* fwhm */    
-      SWAP_WORD (304); /* telfocus */ 
-      SWAP_WORD (308); /* xprobe */ 
-      SWAP_WORD (312); /* yprobe */ 
-      SWAP_WORD (316); /* zprobe */ 
-      SWAP_WORD (320); /* dettemp */ 
-      SWAP_WORD (324); /* teltemp[0] */ 
-      SWAP_WORD (328); /* teltemp[1] */  
-      SWAP_WORD (332); /* teltemp[2] */ 
-      SWAP_WORD (336); /* teltemp[3] */ 
-      SWAP_WORD (340); /* rotangle */
-      SWAP_WORD (344); /* ra */      
-      SWAP_WORD (348); /* dec */     
-      SWAP_WORD (352); /* obstime */ 
-      SWAP_WORD (356); /* regtime */  
-    }
-    return (TRUE);
-  }
-
-  if (!strcmp (type, "detreg")) {
-    if (size != DETREG_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (DetReg) %d vs %d\n", size, DETREG_SIZE);
-      return (FALSE);
-    }
-    byte = (unsigned char *)ptr;
-    for (i = 0; i < nitems; i++, byte += DETREG_SIZE) {
-      SWAP_WORD (0);   /* tstart */
-      SWAP_WORD (4);   /* tstop */
-      SWAP_WORD (8);   /* treg */
-      SWAP_WORD (12);  /* exptime */
-      SWAP_WORD (16);  /* type */
-      SWAP_WORD (20);  /* filter */
-      SWAP_WORD (24);  /* ccd */
-      SWAP_WORD (28);  /* Nentry */
-      SWAP_WORD (32);  /* Norder */
-    }
-    return (TRUE);
-  }
-
-  if (!strcmp (type, "photpars")) {
-    if (size != PHOTPARS_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (PhotPars) %d vs %d\n", size, PHOTPARS_SIZE);
-      return (FALSE);
-    }
-    byte = (unsigned char *)ptr;
-    for (i = 0; i < nitems; i++, byte += PHOTPARS_SIZE) {
-      SWAP_WORD (0);    /* ZP */
-      SWAP_WORD (4);    /* ZPo */
-      SWAP_WORD (8);    /* dZP */
-      SWAP_WORD (12);   /* K */
-      SWAP_WORD (16);   /* A */
-      SWAP_WORD (20);   /* tstart */
-      SWAP_WORD (24);   /* tstop */
-      SWAP_BYTE (28);   /* c1 */
-      SWAP_BYTE (30);   /* c2 */
-      SWAP_BYTE (32);   /* photcode */
-      SWAP_WORD (100);   /* Ntime */
-      SWAP_WORD (104);   /* Nmeas */
-    }
-    return (TRUE);
-  }
-
-  if (!strcmp (type, "missing")) {
-    if (size != MISSING_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (Missing) %d vs %d\n", size, MISSING_SIZE);
-      return (FALSE);
-    }
-    byte0 = (unsigned char *)ptr;
-    byte1 = (unsigned char *)ptr + 1;
-    byte2 = (unsigned char *)ptr + 2;
-    byte3 = (unsigned char *)ptr + 3;
-    for (i = 0; i < nitems; i++, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) {
-      tmp = *byte0;
-      *byte0 = *byte3;
-      *byte3 = tmp;
-      tmp = *byte1;
-      *byte1 = *byte2;
-      *byte2 = tmp;
-    }
-    return (TRUE);
-  }
-
-  if (!strcmp (type, "secfilt")) {
-    if (size != SECFILT_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (SecFilt) %d vs %d\n", size, SECFILT_SIZE);
-      return (FALSE);
-    }
-    byte = (unsigned char *) ptr;
-    for (i = 0; i < nitems; i++, byte += SECFILT_SIZE) {
-      SWAP_BYTE (0);   /* M */
-      SWAP_BYTE (2);   /* Xm */
-      SWAP_BYTE (4);   /* dM */
-    }
-    return (TRUE);
-  }
-
-  if (!strcmp (type, "spectrum")) {
-    if (size != SPECTRUM_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (Spectrum) %d vs %d\n", size, SPECTRUM_SIZE);
-      return (FALSE);
-    }
-    byte = (unsigned char *)ptr;
-    for (i = 0; i < nitems; i++, byte += SPECTRUM_SIZE) {
-      SWAP_WORD (0);  /* ra */ 
-      SWAP_WORD (4);  /* dec */ 
-      SWAP_WORD (8);  /* exptime */ 
-      SWAP_WORD (12); /* airmass */ 
-      SWAP_WORD (16); /* Ws */ 
-      SWAP_WORD (20); /* We */ 
-      SWAP_WORD (24); /* dW */ 
-      SWAP_WORD (28); /* Nspec */ 
-      SWAP_WORD (32); /* obstime */ 
-      SWAP_WORD (36); /* regtime */ 
-    }
-    return (TRUE);
-  }
-
-  if (!strcmp (type, "image")) {
-    if (size != IMAGE_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (Image) %d vs %d\n", size, IMAGE_SIZE);
-      return (FALSE);
-    }
-    byte = (unsigned char *)ptr;
-    for (i = 0; i < nitems; i++, byte += IMAGE_SIZE) {
-      SWAP_DBLE (0); /* coords.crval1 */
-      SWAP_DBLE (8); /* coords.crval2 */
-      for (j = 16; j < 104; j+=4) { /* coords.crpix, delt, pc_ij, polyterms[7][2] */
-	SWAP_WORD (j);
-      }
-      SWAP_WORD (120); /* tzero */
-      SWAP_WORD (124); /* nstar */
-      for (j = 128; j < 146; j+=2) { /* sec z, NX, NY, apmifit, dapmifit, source, Mcal, dMcal, Xm */
-	SWAP_BYTE (j);
-      }
-      SWAP_WORD (184); /* exptime */
-      SWAP_WORD (210); /* order */
-      /**** this (210) is an error! (don't fix, replaced with autocode) ****/
-      for (j = 212; j < 240; j+=2) {
-	SWAP_BYTE (j); /* Mx - Myyy */
-      }
-    }
-    return (TRUE);
-  }
-
-# if (PANSTARRS)
-  if (!strcmp (type, "average")) {
-    if (size != AVERAGE_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (Average) %d vs %d\n", size, AVERAGE_SIZE);
-      return (FALSE);
-    }
-    byte = (unsigned char *)ptr;
-    for (i = 0; i < nitems; i++, byte += AVERAGE_SIZE) {
-      SWAP_DBLE (0);   /* R */
-      SWAP_DBLE (8);   /* D */
-      SWAP_BYTE (16);  /* M */
-      SWAP_BYTE (18);  /* Nm */
-      SWAP_BYTE (20);  /* Nn */
-      SWAP_BYTE (22);  /* Xp */
-      SWAP_BYTE (24);  /* Xm */
-      SWAP_BYTE (26);  /* code */
-      SWAP_WORD (28);  /* offset */
-      SWAP_WORD (32);  /* missing */
-      SWAP_BYTE (36);  /* dM */
-      SWAP_BYTE (38);  /* Xg */
-    }
-    return (TRUE);
-  } 
-  if (!strcmp (type, "measure")) {
-    if (size != MEASURE_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (Measure) %d vs %d\n", size, MEASURE_SIZE);
-      return (FALSE);
-    }
-    byte = (unsigned char *)ptr;
-    for (i = 0; i < nitems; i++, byte += MEASURE_SIZE) {
-      SWAP_BYTE (0);   /* dR */
-      SWAP_BYTE (2);   /* dD */
-      SWAP_BYTE (4);   /* M  */
-      SWAP_BYTE (6);   /* Mcal */
-      SWAP_BYTE (8);   /* Mgal */
-      SWAP_BYTE (10);  /* Map  */
-      SWAP_BYTE (12);  /* FWx */
-      /* 14, 15, 16, 17 - char */
-      SWAP_BYTE (18);  /* source */
-      SWAP_WORD (20);  /* t */
-      SWAP_WORD (24);  /* averef */
-      SWAP_BYTE (28);  /* dt */
-      SWAP_BYTE (30);  /* flags */
-    }
-    return (TRUE);
-  }
-
-# endif /** PANSTARRS **/
-
-
-# if (ELIXIR)
-  if (!strcmp (type, "average")) {
-    if (size != AVERAGE_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (Average) %d vs %d\n", size, AVERAGE_SIZE);
-      return (FALSE);
-    }
-    byte = (unsigned char *)ptr;
-    for (i = 0; i < nitems; i++, byte += AVERAGE_SIZE) {
-      SWAP_WORD (0);   /* R */
-      SWAP_WORD (4);   /* D */
-      SWAP_BYTE (8);   /* M */
-      SWAP_BYTE (10);  /* Nm */
-      SWAP_BYTE (12);  /* Nn */
-      SWAP_BYTE (14);  /* Xp */
-      SWAP_BYTE (16);  /* Xm */
-      SWAP_BYTE (18);  /* code */
-      SWAP_WORD (20);  /* offset */
-      SWAP_WORD (24);  /* missing */
-      SWAP_BYTE (28);  /* dM */
-      SWAP_BYTE (30);  /* Xg */
-    }
-    return (TRUE);
-  } 
-  if (!strcmp (type, "measure")) {
-    if (size != MEASURE_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (Measure) %d vs %d\n", size, MEASURE_SIZE);
-      return (FALSE);
-    }
-    byte = (unsigned char *)ptr;
-    for (i = 0; i < nitems; i++, byte += MEASURE_SIZE) {
-      SWAP_BYTE (0);   /* dR */
-      SWAP_BYTE (2);   /* dD */
-      SWAP_BYTE (4);   /* M  */
-      SWAP_BYTE (6);   /* Mcal */
-      SWAP_BYTE (8);   /* Mgal */
-      SWAP_BYTE (10);  /* Map  */
-      SWAP_BYTE (12);  /* FWx */
-      /* 14, 15, 16, 17 - char */
-      SWAP_BYTE (18);  /* source */
-      SWAP_WORD (20);  /* t */
-      SWAP_WORD (24);  /* averef */
-      SWAP_BYTE (28);  /* dt */
-      SWAP_BYTE (30);  /* flags */
-    }
-    return (TRUE);
-  }
-
-# endif /** ELIXIR **/
-
-
-# if (LONEOS)
-  if (!strcmp (type, "average")) {
-    if (size != OLDAVERAGE_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (OldAverage) %d vs %d\n", size, OLDAVERAGE_SIZE);
-      return (FALSE);
-    }
-    byte = (unsigned char *)ptr;
-    for (i = 0; i < nitems; i++, byte += OLDAVERAGE_SIZE) {
-      SWAP_WORD (0);   /* R */
-      SWAP_WORD (4);   /* D */
-      SWAP_BYTE (8);   /* M */
-      SWAP_BYTE (10); /* Nm */
-      SWAP_BYTE (12); /* Nn */
-      SWAP_BYTE (14); /* Xp */
-      SWAP_BYTE (16); /* Xm */
-      SWAP_BYTE (18); /* code */
-      SWAP_WORD (20); /* offset */
-      SWAP_WORD (24); /* missing */
-    }
-    return (TRUE);
-  } 
-  if (!strcmp (type, "measure")) {
-    if (size != OLDMEASURE_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (OldMeasure) %d vs %d\n", size, OLDMEASURE_SIZE);
-      return (FALSE);
-    }
-    byte = (unsigned char *)ptr;
-    for (i = 0; i < nitems; i++, byte += OLDMEASURE_SIZE) {
-      SWAP_BYTE (0);   /* dR */
-      SWAP_BYTE (2);   /* dD */
-      SWAP_BYTE (4);   /* M  */
-      SWAP_BYTE (6);   /* Mcal */
-      SWAP_BYTE (10);  /* source */
-      SWAP_WORD (12);  /* t */
-      SWAP_WORD (16);  /* average */
-    }
-    return (TRUE);
-  }
-# endif /** LONEOS **/
-
-# if (0) /*** others ***/
-  if (!strcmp (type, "oldsecfilt")) {
-    if (size != OLDSECFILT_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (OldSecFilt) %d vs %d\n", size, OLDSECFILT_SIZE);
-      return (FALSE);
-    }
-    byte = (unsigned char *) ptr;
-    for (i = 0; i < nitems; i++, byte += OLDSECFILT_SIZE) {
-      SWAP_BYTE (0);   /* M */
-      SWAP_BYTE (2);   /* Xm */
-    }
-    return (TRUE);
-  }
-  if (!strcmp (type, "rufimage")) {
-    if (size != RUFIMAGE_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (RufImage) %d vs %d\n", size, RUFIMAGE_SIZE);
-      return (FALSE);
-    }
-    byte = (unsigned char *)ptr;
-    for (i = 0; i < nitems; i++, byte += RUFIMAGE_SIZE) {
-      SWAP_WORD (0);   /* sky */
-      SWAP_WORD (4);   /* bias */
-      SWAP_WORD (8);  /* fwhm */
-      SWAP_WORD (12); /* exptime */
-      SWAP_WORD (16); /* airmass */
-      SWAP_WORD (20); /* obstime */
-      SWAP_BYTE (24); /* ccdnum */
-    }
-    return (TRUE);
-  }
-  if (!strcmp (type, "olddetreg")) {
-    if (size != OLDDETREG_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (DetReg) %d vs %d\n", size, OLDDETREG_SIZE);
-      return (FALSE);
-    }
-    byte = (unsigned char *)ptr;
-    for (i = 0; i < nitems; i++, byte += OLDDETREG_SIZE) {
-      SWAP_WORD (0);   /* tstart */
-      SWAP_WORD (4);   /* tstop */
-      SWAP_WORD (8);   /* treg */
-      SWAP_WORD (12);  /* sigma */
-      SWAP_WORD (16);  /* clipsigma */
-      SWAP_WORD (20);  /* type */
-      SWAP_WORD (24);  /* filter */
-      SWAP_WORD (28);  /* ccd */
-    }
-    return (TRUE);
-  }
-# endif /** others **/
-# endif /** now in autocode **/
-
   fprintf (stderr, "unknown type %s\n", type);
   return (FALSE);
Index: trunk/Ohana/src/libohana/src/findexec.c
===================================================================
--- trunk/Ohana/src/libohana/src/findexec.c	(revision 27392)
+++ trunk/Ohana/src/libohana/src/findexec.c	(revision 27435)
@@ -391,15 +391,15 @@
 
 /* fseek with timeout - 0.5 sec */
-int Fseek (FILE *f, long offset, int whence) {
+int Fseek (FILE *f, off_t offset, int whence) {
 
   int status, k;
 
-  status = fseek (f, offset, whence);
+  status = fseeko (f, offset, whence);
   if (status == -1) {
-    for (k = 0; (k < 10) && ((status = fseek (f, 0, SEEK_SET)) == -1); k++) usleep (50000);
+    for (k = 0; (k < 10) && ((status = fseeko (f, 0, SEEK_SET)) == -1); k++) usleep (50000);
     if (status == -1) {
-      return (0);
-    }
-  }
-  return (1);
-}
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
Index: trunk/Ohana/src/libohana/src/glockfile.c
===================================================================
--- trunk/Ohana/src/libohana/src/glockfile.c	(revision 27392)
+++ trunk/Ohana/src/libohana/src/glockfile.c	(revision 27435)
@@ -117,5 +117,5 @@
   if (type == LCK_HARD) {
     /* we've really got the lock, write BUSY to protect it */
-    fseek (flock, 0, SEEK_SET);
+    fseeko (flock, 0LL, SEEK_SET);
     nbytes = fprintf (flock, "BUSY\n");
 
@@ -212,5 +212,5 @@
 
     /* set value to IDLE */
-    fseek (flock, 0, SEEK_SET);
+    fseeko (flock, 0LL, SEEK_SET);
     nbytes = fprintf (flock, "IDLE\n");
     if (nbytes != 5) {
Index: trunk/Ohana/src/libohana/src/sorts.c
===================================================================
--- trunk/Ohana/src/libohana/src/sorts.c	(revision 27392)
+++ trunk/Ohana/src/libohana/src/sorts.c	(revision 27435)
@@ -73,4 +73,20 @@
 }
 
+// sort two int vectors by first vector
+void llsortpair (off_t *X, off_t *Y, off_t N) {
+
+# define SWAPFUNC(A,B){ off_t tmp; \
+  tmp = X[A]; X[A] = X[B]; X[B] = tmp; \
+  tmp = Y[A]; Y[A] = Y[B]; Y[B] = tmp; \
+}
+# define COMPARE(A,B)(X[A] < X[B])
+
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+
+}
+
 void fsortthree (float *X, float *Y, float *Z, int N) {
 
Index: trunk/Ohana/src/libohana/src/string.c
===================================================================
--- trunk/Ohana/src/libohana/src/string.c	(revision 27392)
+++ trunk/Ohana/src/libohana/src/string.c	(revision 27435)
@@ -13,5 +13,4 @@
   string[++i] = 0;
   return (i);
-
 }
 
Index: trunk/Ohana/src/lightcurve/src/alter_headers.c
===================================================================
--- trunk/Ohana/src/lightcurve/src/alter_headers.c	(revision 27392)
+++ trunk/Ohana/src/lightcurve/src/alter_headers.c	(revision 27435)
@@ -46,8 +46,8 @@
     gfits_modify (&header, "NMcal",  "%d", 1,  images[i].Nstars);
 
-    gfits_modify (&header, "Mcal",   "%C", 1, "relphot: calibration magnitude");
-    gfits_modify (&header, "dMcal",  "%C", 1, "relphot: calibration error");
-    gfits_modify (&header, "clouds", "%C", 1, "relphot: cloud level");
-    gfits_modify (&header, "NMcal",  "%C", 1, "relphot: number of stars");
+    gfits_modify_alt (&header, "Mcal",   "%C", 1, "relphot: calibration magnitude");
+    gfits_modify_alt (&header, "dMcal",  "%C", 1, "relphot: calibration error");
+    gfits_modify_alt (&header, "clouds", "%C", 1, "relphot: cloud level");
+    gfits_modify_alt (&header, "NMcal",  "%C", 1, "relphot: number of stars");
 
     gfits_write_header (head, &header);
Index: trunk/Ohana/src/lightcurve/src/fix_header.c
===================================================================
--- trunk/Ohana/src/lightcurve/src/fix_header.c	(revision 27392)
+++ trunk/Ohana/src/lightcurve/src/fix_header.c	(revision 27435)
@@ -7,7 +7,5 @@
 */
 
-void
-  fix_header 
-  (Header     *header)
+void fix_header (Header *header)
 {
 
@@ -15,7 +13,7 @@
   char *p1, *p2;
 
-  Nbytes = 2880 * (int) (header[0].size / 2880 + 1);
+  Nbytes = 2880 * (int) (header[0].datasize / 2880 + 1);
   reallocate (header[0].buffer, char, Nbytes);
-  bzero (&header[0].buffer[header[0].size], Nbytes - header[0].size - 1);
+  bzero (&header[0].buffer[header[0].datasize], Nbytes - header[0].datasize - 1);
 
   p1 = header[0].buffer - 1;
@@ -24,9 +22,9 @@
   while (p2 != NULL) {
     if ((N = p2 - p1) != 80) {
-      bcopy (p2, p1 + 80, header[0].size - (p2 - header[0].buffer));
+      bcopy (p2, p1 + 80, header[0].datasize - (p2 - header[0].buffer));
       for (i = 0; i < 80 - N; i++) {
 	*(p2 + i) = ' ';
       }
-      header[0].size += 80 - N;
+      header[0].datasize += 80 - N;
     }
     p1 = strchr (p1 + 1, RETURN);
@@ -34,5 +32,5 @@
   }
 
-  header[0].size = Nbytes;
+  header[0].datasize = Nbytes;
   p1 = gfits_header_field (header, "END", 1);
   for (i = 3; i < 79; i++) 
@@ -40,5 +38,5 @@
   *(p1 + 79) = RETURN;
   
-  Nbytes = header[0].size - (p1 - header[0].buffer) - 80;
+  Nbytes = header[0].datasize - (p1 - header[0].buffer) - 80;
   
   for (i = 0; i < Nbytes; i++) {
@@ -48,11 +46,11 @@
   }
 
-  Nbytes = header[0].size - (p1 - header[0].buffer) - 80;
+  Nbytes = header[0].datasize - (p1 - header[0].buffer) - 80;
   while (Nbytes >= 2880) {
-    header[0].size -= 2880;
-    Nbytes = header[0].size - (p1 - header[0].buffer) - 80;
+    header[0].datasize -= 2880;
+    Nbytes = header[0].datasize - (p1 - header[0].buffer) - 80;
   }
 
-  reallocate (header[0].buffer, char, header[0].size);
+  reallocate (header[0].buffer, char, header[0].datasize);
 }
 
Index: trunk/Ohana/src/markrock/src/find_bright_stars.c
===================================================================
--- trunk/Ohana/src/markrock/src/find_bright_stars.c	(revision 27392)
+++ trunk/Ohana/src/markrock/src/find_bright_stars.c	(revision 27435)
@@ -3,10 +3,10 @@
 void find_bright_stars (Catalog *catalog, CatStats *catstats) {
 
-  int i, j, n, m, first_j, Nave, Ngsc, Nmark;
+  off_t i, j, n, m, first_j, Nave, Ngsc, Nmark;
   Catalog GSCdata;
   double MinRA, MinDEC, MaxRA, MaxDEC, RaCenter, DecCenter;
   Coords *tcoords;
   double *X1, *Y1, *X2, *Y2;
-  int *N1, *N2;
+  off_t *N1, *N2;
   char *mark;
   double dX, dY, dR, MaxDist, MaxDist1, MaxRadius, radius, radius2;
@@ -24,5 +24,5 @@
   ALLOCATE (X1, double, Ngsc);
   ALLOCATE (Y1, double, Ngsc);
-  ALLOCATE (N1, int, Ngsc);
+  ALLOCATE (N1, off_t, Ngsc);
   ALLOCATE (mark, char, Nave);
   bzero (mark, Nave);
Index: trunk/Ohana/src/markrock/src/gcatstats.c
===================================================================
--- trunk/Ohana/src/markrock/src/gcatstats.c	(revision 27392)
+++ trunk/Ohana/src/markrock/src/gcatstats.c	(revision 27435)
@@ -6,9 +6,8 @@
 {
 
-  int i;
+  off_t i;
   double RaCenter, DecCenter;
   double MinRA, MaxRA, MinDEC, MaxDEC;
   double *X1, *Y1;
-  int *N1;
   Coords tcoords;
   
@@ -31,5 +30,5 @@
   ALLOCATE (catstats[0].X, double, catalog[0].Naverage);
   ALLOCATE (catstats[0].Y, double, catalog[0].Naverage);
-  ALLOCATE (catstats[0].N, int,   catalog[0].Naverage);
+  ALLOCATE (catstats[0].N, off_t,   catalog[0].Naverage);
 
   /* project onto rectilinear grid with 1 arcsec pixels, sort by X */
Index: trunk/Ohana/src/markrock/src/wrocks.c
===================================================================
--- trunk/Ohana/src/markrock/src/wrocks.c	(revision 27392)
+++ trunk/Ohana/src/markrock/src/wrocks.c	(revision 27435)
@@ -16,5 +16,5 @@
   }
   /* position to begining of file to write header */
-  fseek (f, 0, SEEK_END);
+  fseeko (f, 0, SEEK_END);
 
   /* get statistics on rocks */
Index: trunk/Ohana/src/markstar/src/find_bright_stars.c
===================================================================
--- trunk/Ohana/src/markstar/src/find_bright_stars.c	(revision 27392)
+++ trunk/Ohana/src/markstar/src/find_bright_stars.c	(revision 27435)
@@ -3,10 +3,10 @@
 void find_bright_stars (Catalog *catalog, CatStats *catstats) {
 
-  int i, j, n, m, first_j, Nave, Ngsc;
+  off_t i, j, n, m, first_j, Nave, Ngsc;
   Catalog GSCdata;
   double MinRA, MinDEC, MaxRA, MaxDEC, RaCenter, DecCenter;
   Coords *tcoords;
   double *X1, *Y1, *X2, *Y2;
-  int *N1, *N2;
+  off_t *N1, *N2;
   char *mark;
   double dX, dY, dR, MaxDist, MaxDist1, MaxRadius, radius, radius2;
@@ -25,5 +25,5 @@
   ALLOCATE (X1, double, Ngsc);
   ALLOCATE (Y1, double, Ngsc);
-  ALLOCATE (N1, int, Ngsc);
+  ALLOCATE (N1, off_t, Ngsc);
   ALLOCATE (mark, char, Nave);
   bzero (mark, Nave);
Index: trunk/Ohana/src/markstar/src/find_matches.c
===================================================================
--- trunk/Ohana/src/markstar/src/find_matches.c	(revision 27392)
+++ trunk/Ohana/src/markstar/src/find_matches.c	(revision 27435)
@@ -7,5 +7,5 @@
   double *X1, *Y1, *X2, *Y2;
   double dX, dY, dR;
-  int *N1, *N2;
+  off_t *N1, *N2;
   int Nstar, Nghost, Ng;
   unsigned int flags;
@@ -25,5 +25,5 @@
   ALLOCATE (X1, double, Nghost);
   ALLOCATE (Y1, double, Nghost);
-  ALLOCATE (N1, int, Nghost);
+  ALLOCATE (N1, off_t, Nghost);
 
   /* project ghosts to the frame of the catalog */
Index: trunk/Ohana/src/markstar/src/gcatstats.c
===================================================================
--- trunk/Ohana/src/markstar/src/gcatstats.c	(revision 27392)
+++ trunk/Ohana/src/markstar/src/gcatstats.c	(revision 27435)
@@ -3,9 +3,8 @@
 void gcatstats (Catalog *catalog, CatStats *catstats) {
 
-  int i;
+  off_t i;
   double RaCenter, DecCenter;
   double MinRA, MaxRA, MinDEC, MaxDEC;
   double *X1, *Y1;
-  int *N1;
   Coords tcoords;
   
@@ -41,5 +40,5 @@
   ALLOCATE (catstats[0].X, double, catalog[0].Naverage);
   ALLOCATE (catstats[0].Y, double, catalog[0].Naverage);
-  ALLOCATE (catstats[0].N, int,   catalog[0].Naverage);
+  ALLOCATE (catstats[0].N, off_t,  catalog[0].Naverage);
 
   /* project onto rectilinear grid with 1 arcsec pixels, sort by X */
Index: trunk/Ohana/src/misc/src/addastro.c
===================================================================
--- trunk/Ohana/src/misc/src/addastro.c	(revision 27392)
+++ trunk/Ohana/src/misc/src/addastro.c	(revision 27435)
@@ -6,5 +6,6 @@
   /* USAGE: addastro (cmp) (ref) */
 
-  int i, j, nbytes, itmp, oldsize;
+  off_t nbytes, oldsize;
+  int i, j, itmp;
   double tmp;
   Header header, refhead;
@@ -22,5 +23,5 @@
     exit (1);
   }
-  oldsize = header.size;
+  oldsize = header.datasize;
 
   if (!gfits_read_header (argv[2], &refhead)) {
@@ -58,6 +59,6 @@
   gfits_modify (&header,  "CPRECISE", "%lf", 1, tmp);
 
-  gfits_modify (&header, "CERROR", "%C", 1, "scatter in astrometry soln (arcsec)");
-  gfits_modify (&header, "CPRECISE", "%C", 1, "precision of astrometry soln (arcsec)");
+  gfits_modify_alt (&header, "CERROR", "%C", 1, "scatter in astrometry soln (arcsec)");
+  gfits_modify_alt (&header, "CPRECISE", "%C", 1, "precision of astrometry soln (arcsec)");
 
   /* write to file */
@@ -72,6 +73,6 @@
     exit (1);
   }
-  nbytes = fwrite (header.buffer, 1, header.size, g);
-  fseek (g, header.size, SEEK_SET); 
+  nbytes = fwrite (header.buffer, 1, header.datasize, g);
+  fseeko (g, header.datasize, SEEK_SET); 
 
   /* read date from file */
Index: trunk/Ohana/src/misc/src/applyscat.c
===================================================================
--- trunk/Ohana/src/misc/src/applyscat.c	(revision 27392)
+++ trunk/Ohana/src/misc/src/applyscat.c	(revision 27435)
@@ -14,5 +14,6 @@
   Matrix matrix;
   Stars *stars;
-  int Nstar, Nbytes, nbytes;
+  int Nstar;
+  off_t Nbytes, nbytes;
   FILE *f;
   char *buffer, line[10];
@@ -37,5 +38,5 @@
     exit (1);
   }
-  fseek (f, header.size, SEEK_SET); 
+  fseeko (f, header.datasize, SEEK_SET); 
 
   /* find expected number of stars */
@@ -110,5 +111,5 @@
     exit (1);
   }
-  fseek (f, header.size, SEEK_SET); 
+  fseeko (f, header.datasize, SEEK_SET); 
 
   /* load in data */
Index: trunk/Ohana/src/misc/src/fakecmp.c
===================================================================
--- trunk/Ohana/src/misc/src/fakecmp.c	(revision 27392)
+++ trunk/Ohana/src/misc/src/fakecmp.c	(revision 27435)
@@ -4,6 +4,7 @@
 void main (int argc, char **argv) {
 
-  int i, j, N, status;
-  int Nreserved, start_size;
+  off_t start_size, status;
+  int i, j, N;
+  int Nreserved;
   char *p, keyword[16], line[256];
   FILE *f;
@@ -69,5 +70,5 @@
     exit (1);
   }
-  start_size = header.size;
+  start_size = header.datasize;
 
   /* run through the lines in the header data file */
@@ -94,5 +95,5 @@
     p = (char *) NULL;
     Nreserved = strlen (reserved);
-    for (i = 0; (i < header.size) && (p == (char *) NULL) ; i+= FT_LINE_LENGTH) {
+    for (i = 0; (i < header.datasize) && (p == (char *) NULL) ; i+= FT_LINE_LENGTH) {
       if (!strncmp (&header.buffer[i], reserved, Nreserved)) {
 	p = &header.buffer[i];
@@ -114,5 +115,5 @@
   */
 
-  if (header.size != start_size) {
+  if (header.datasize != start_size) {
     fprintf (stderr, "header changed size: should not happen!\n");
     exit (1);
@@ -125,7 +126,7 @@
   }
 
-  fseek (f, 0, SEEK_SET);
-  status = fwrite (header.buffer, 1, header.size, f);
-  if (status != header.size) {
+  fseeko (f, 0, SEEK_SET);
+  status = fwrite (header.buffer, 1, header.datasize, f);
+  if (status != header.datasize) {
     fprintf (stderr, "failed to write data to image header\n");
     exit (1);
Index: trunk/Ohana/src/misc/src/fakestars.c
===================================================================
--- trunk/Ohana/src/misc/src/fakestars.c	(revision 27392)
+++ trunk/Ohana/src/misc/src/fakestars.c	(revision 27435)
@@ -57,5 +57,5 @@
     exit (1);
   }
-  fseek (f, header.size, SEEK_SET); 
+  fseeko (f, header.datasize, SEEK_SET); 
 
   /* find expected number of stars */
@@ -108,5 +108,5 @@
     exit (1);
   }
-  fseek (f, header.size, SEEK_SET); 
+  fseeko (f, header.datasize, SEEK_SET); 
 
   for (i = 0; i < Nstar; i++) {
Index: trunk/Ohana/src/misc/src/fiximg.c
===================================================================
--- trunk/Ohana/src/misc/src/fiximg.c	(revision 27392)
+++ trunk/Ohana/src/misc/src/fiximg.c	(revision 27435)
@@ -31,5 +31,5 @@
   fprintf (stderr, "deleted %d comments\n", N);
   p = gfits_header_field (&header, "END", 1);
-  for (i = 3; i < header.size - (int) (p - header.buffer); i++) { 
+  for (i = 3; i < header.datasize - (int) (p - header.buffer); i++) { 
     p[i] = ' '; 
   }
Index: trunk/Ohana/src/misc/src/fixsimple.c
===================================================================
--- trunk/Ohana/src/misc/src/fixsimple.c	(revision 27392)
+++ trunk/Ohana/src/misc/src/fixsimple.c	(revision 27435)
@@ -26,5 +26,5 @@
   fprintf (stderr, "deleted %d comments\n", N);
   p = gfits_header_field (&header, "END", 1);
-  for (i = 3; i < header.size - (int) (p - header.buffer); i++) { 
+  for (i = 3; i < header.datasize - (int) (p - header.buffer); i++) { 
     p[i] = ' '; 
   }
@@ -47,7 +47,7 @@
   }
 
-  fseek (f, skip, SEEK_SET);
-  status = fwrite (header.buffer, 1, header.size, f);
-  if (status != header.size) {
+  fseeko (f, skip, SEEK_SET);
+  status = fwrite (header.buffer, 1, header.datasize, f);
+  if (status != header.datasize) {
     fprintf (stderr, "failed to write data to image header\n");
     exit (1);
Index: trunk/Ohana/src/misc/src/striphead.c
===================================================================
--- trunk/Ohana/src/misc/src/striphead.c	(revision 27392)
+++ trunk/Ohana/src/misc/src/striphead.c	(revision 27435)
@@ -51,5 +51,5 @@
     }
     
-    for (j = 79; j < header.size; j+= 80) {
+    for (j = 79; j < header.datasize; j+= 80) {
       header.buffer[j] = 10;
     }
Index: trunk/Ohana/src/mosastro/src/LoadStars.c
===================================================================
--- trunk/Ohana/src/mosastro/src/LoadStars.c	(revision 27392)
+++ trunk/Ohana/src/mosastro/src/LoadStars.c	(revision 27435)
@@ -50,5 +50,5 @@
 
     extend = FALSE;
-    gfits_scan (&chip[Nchip].header, "EXTEND",  "%t", 1, &extend);
+    gfits_scan_alt (&chip[Nchip].header, "EXTEND",  "%t", 1, &extend);
     if (extend) {
       status = rfits (&chip[Nchip]);
Index: trunk/Ohana/src/mosastro/src/SaveResiduals.c
===================================================================
--- trunk/Ohana/src/mosastro/src/SaveResiduals.c	(revision 27392)
+++ trunk/Ohana/src/mosastro/src/SaveResiduals.c	(revision 27435)
@@ -12,5 +12,5 @@
   header[0].Naxes = 0;
   gfits_modify (header, "NAXIS",   "%d", 1, 0);
-  gfits_modify (header, "EXTEND",  "%t", 1, TRUE);
+  gfits_modify_alt (header, "EXTEND",  "%t", 1, TRUE);
   gfits_modify (header, "NEXTEND", "%d", 1, 1);
 
Index: trunk/Ohana/src/mosastro/src/getusno.c
===================================================================
--- trunk/Ohana/src/mosastro/src/getusno.c	(revision 27392)
+++ trunk/Ohana/src/mosastro/src/getusno.c	(revision 27435)
@@ -11,6 +11,6 @@
 StarData *getusno (CatStats *catstats, int *Nstars) {
 
-  long int offset;
-  int i, bin, first, last, nitems, Nitems, Nbins;
+  off_t offset, nitems, Nitems;
+  int i, bin, first, last, Nbins;
   float hours[100];
   int start[100], number[100], *buffer, *buf;
@@ -91,5 +91,5 @@
     /* advance file pointer to first slice */
     offset = 3*sizeof(int)*(start[first] - 1);
-    fseek (f, offset, SEEK_SET);
+    fseeko (f, offset, SEEK_SET);
     /* on each loop, load data from an RA slice of the catalog */
     for (bin = first; bin < last; bin++) {
Index: trunk/Ohana/src/mosastro/src/getusnob.c
===================================================================
--- trunk/Ohana/src/mosastro/src/getusnob.c	(revision 27392)
+++ trunk/Ohana/src/mosastro/src/getusnob.c	(revision 27435)
@@ -5,6 +5,6 @@
 StarData *getusnob (CatStats *catstats, int *Nstars) {
 
-  long int offset;
-  int i, bin, first, last, nitems, Nitems, Nbins;
+  off_t offset, nitems, Nitems;
+  int i, bin, first, last, Nbins;
   float hours[100];
   int start[100], number[100], *buffer, *buf;
@@ -76,5 +76,5 @@
     /* advance file pointer to first slice */
     offset = NELEM*NBYTE*(start[first] - 1);
-    fseek (f, offset, SEEK_SET);
+    fseeko (f, offset, SEEK_SET);
 
     /* sum the number of stars in data segment of interest */
Index: trunk/Ohana/src/mosastro/src/match.c
===================================================================
--- trunk/Ohana/src/mosastro/src/match.c	(revision 27392)
+++ trunk/Ohana/src/mosastro/src/match.c	(revision 27435)
@@ -8,5 +8,5 @@
   double dp, dq, radius, Radius;
   double *p, *q, *P, *Q;
-  int *U, *u;
+  off_t *U, *u;
 
   /* requested radius is in arcsec ; internally radius is in pixels */
@@ -17,5 +17,5 @@
   ALLOCATE (P, double, Nrefcat);
   ALLOCATE (Q, double, Nrefcat);
-  ALLOCATE (U, int, Nrefcat);
+  ALLOCATE (U, off_t, Nrefcat);
   for (i = 0; i < Nrefcat; i++) {
     U[i] = i;
@@ -35,5 +35,5 @@
     ALLOCATE (p, double, chip[i].Nstars);
     ALLOCATE (q, double, chip[i].Nstars);
-    ALLOCATE (u, int, chip[i].Nstars);
+    ALLOCATE (u, off_t,  chip[i].Nstars);
     for (j = 0; j < chip[i].Nstars; j++) {
       u[j] = j;
Index: trunk/Ohana/src/mosastro/src/output.c
===================================================================
--- trunk/Ohana/src/mosastro/src/output.c	(revision 27392)
+++ trunk/Ohana/src/mosastro/src/output.c	(revision 27435)
@@ -41,5 +41,5 @@
   }
 
-  fwrite (header[0].buffer, 1, header[0].size, f);
+  fwrite (header[0].buffer, 1, header[0].datasize, f);
   fclose (f);
 }
Index: trunk/Ohana/src/mosastro/src/rfits.c
===================================================================
--- trunk/Ohana/src/mosastro/src/rfits.c	(revision 27392)
+++ trunk/Ohana/src/mosastro/src/rfits.c	(revision 27435)
@@ -14,5 +14,5 @@
     exit (1);
   }
-  fseek (f, mychip[0].header.size, SEEK_SET); 
+  fseeko (f, mychip[0].header.datasize, SEEK_SET); 
 
   /* init & load in table data */
@@ -30,5 +30,7 @@
   }
 
-  stars = gfits_table_get_SMPData (&table, &mychip[0].Nstars, NULL);
+  off_t Nstars;
+  stars = gfits_table_get_SMPData (&table, &Nstars, NULL);
+  mychip[0].Nstars = Nstars;
   gfits_scan (table.header, "NAXIS1", "%d", 1, &Nx);
 
Index: trunk/Ohana/src/mosastro/src/rtext.c
===================================================================
--- trunk/Ohana/src/mosastro/src/rtext.c	(revision 27392)
+++ trunk/Ohana/src/mosastro/src/rtext.c	(revision 27435)
@@ -12,5 +12,5 @@
     return (FALSE);
   }
-  fseek (f, mychip[0].header.size, SEEK_SET); 
+  fseeko (f, mychip[0].header.datasize, SEEK_SET); 
 
   /* find expected number of stars */
Index: trunk/Ohana/src/mosastro/src/wfits.c
===================================================================
--- trunk/Ohana/src/mosastro/src/wfits.c	(revision 27392)
+++ trunk/Ohana/src/mosastro/src/wfits.c	(revision 27435)
@@ -10,5 +10,5 @@
   header[0].Naxes = 0;
   gfits_modify (header, "NAXIS",   "%d", 1, 0);
-  gfits_modify (header, "EXTEND",  "%t", 1, TRUE);
+  gfits_modify_alt (header, "EXTEND",  "%t", 1, TRUE);
   gfits_modify (header, "NEXTEND", "%d", 1, 1);
 
Index: trunk/Ohana/src/mosastro/src/wstars.c
===================================================================
--- trunk/Ohana/src/mosastro/src/wstars.c	(revision 27392)
+++ trunk/Ohana/src/mosastro/src/wstars.c	(revision 27435)
@@ -16,5 +16,5 @@
     }
 
-    fwrite (data[0].header.buffer, 1, data[0].header.size, g);
+    fwrite (data[0].header.buffer, 1, data[0].header.datasize, g);
     fwrite (data[0].buffer, 1, data[0].Nbuffer, g);
     fclose (g);
@@ -34,5 +34,5 @@
   }
 
-  fwrite (header[0].buffer, 1, header[0].size, g);
+  fwrite (header[0].buffer, 1, header[0].datasize, g);
 
   for (i = 0; i < Nstars; i++) {
Index: trunk/Ohana/src/opihi/cmd.astro/altaz.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/altaz.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.astro/altaz.c	(revision 27435)
@@ -4,85 +4,164 @@
 # define dSIN(A)   ((double) sin ((double)RAD_DEG*A))
 
+int HD_to_AZ(double *alt, double *az, double *rot, double ha, double dec, double lat);
+int AZ_to_HD(double *ha, double *dec, double *rot, double alt, double az, double lat);
+
 double atan2 (double y, double x);
 
 int altaz (int argc, char **argv) {
   
+  int i;
   double alt, az, lat, rot;
   double ha, dec;
-  double sind, sinh, cosh;
   char *latstr;
+  Vector *hvec, *dvec, *avec, *zvec, *rvec;
+  opihi_flt *Hv, *Dv, *Av, *Zv, *Rv;
 
-  if (argc != 6) goto usage;
-
-  if (!strcmp (argv[1], "-h")) goto radec;
-  if (!strcmp (argv[1], "-c")) goto altaz;
-
- radec:
-  /* ha/dec -> alt/az */
-  ha  = atof (argv[2]);
-  dec = atof (argv[3]);
+  if (argc != 7) goto usage;
+  if (strcasecmp (argv[4], "to")) goto usage;
 
   latstr = get_variable ("LATITUDE");
   if (latstr == (char *) NULL) {
     gprint (GP_ERR, "please define $LATITUDE\n");
-    return (FALSE);
+    return FALSE;
   }
   lat = atof (latstr);
+  gprint (GP_ERR, "using latitude of %f\n", lat);
   free (latstr);
- 
+
+  if (!strcmp (argv[1], "-az")) goto radec;
+  if (!strcmp (argv[1], "-hd")) goto altaz;
+
+ radec:
+  if (ISNUM(argv[2][0]) && ISNUM(argv[3][0])) {
+    /* ha/dec -> alt/az */
+    ha  = atof (argv[2]);
+    dec = atof (argv[3]);
+  
+    HD_to_AZ (&alt, &az, &rot, ha, dec, lat);
+
+    set_variable (argv[5], alt);
+    set_variable (argv[6], az);
+    set_variable ("ROT", rot);
+    return TRUE;
+  } 
+
+  /* find vectors */
+  if ((hvec = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return FALSE;
+  if ((dvec = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return FALSE;
+  if ((avec = SelectVector (argv[5], ANYVECTOR, TRUE)) == NULL) return FALSE;
+  if ((zvec = SelectVector (argv[6], ANYVECTOR, TRUE)) == NULL) return FALSE;
+  if ((rvec = SelectVector ("ROT",   ANYVECTOR, TRUE)) == NULL) return FALSE;
+
+  if (hvec[0].Nelements != dvec[0].Nelements) {
+    gprint (GP_ERR, "vectors %s and %s not the same length\n", argv[2], argv[3]);
+    return FALSE;
+  }
+  
+  // cast xvec or yvec to FLT if it is type INT
+  CastVector (hvec, OPIHI_FLT);
+  CastVector (dvec, OPIHI_FLT);
+  ResetVector (avec, OPIHI_FLT, hvec[0].Nelements);
+  ResetVector (zvec, OPIHI_FLT, hvec[0].Nelements);
+  ResetVector (rvec, OPIHI_FLT, hvec[0].Nelements);
+
+  Hv = hvec[0].elements.Flt;
+  Dv = dvec[0].elements.Flt;
+  Av = avec[0].elements.Flt;
+  Zv = zvec[0].elements.Flt;
+  Rv = rvec[0].elements.Flt;
+
+  for (i = 0; i < hvec[0].Nelements; i++, Hv++, Dv++, Av++, Zv++, Rv++) {
+    HD_to_AZ (Av, Zv, Rv, *Hv, *Dv, lat);
+  }
+  return TRUE;
+  
+ altaz:
+  if (ISNUM(argv[2][0]) && ISNUM(argv[3][0])) {
+    /* alt/az -> ha/dec */
+    alt = atof (argv[2]);
+    az  = atof (argv[3]);
+
+    AZ_to_HD (&ha, &dec, &rot, alt, az, lat);
+
+    set_variable (argv[5], ha);
+    set_variable (argv[6], dec);
+    set_variable ("ROT", rot);
+    return TRUE;
+  }
+  
+  /* find vectors */
+  if ((avec = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return FALSE;
+  if ((zvec = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return FALSE;
+  if ((hvec = SelectVector (argv[5], ANYVECTOR, TRUE)) == NULL) return FALSE;
+  if ((dvec = SelectVector (argv[6], ANYVECTOR, TRUE)) == NULL) return FALSE;
+  if ((rvec = SelectVector ("ROT",   ANYVECTOR, TRUE)) == NULL) return FALSE;
+
+  if (avec[0].Nelements != zvec[0].Nelements) {
+    gprint (GP_ERR, "vectors %s and %s not the same length\n", argv[2], argv[3]);
+    return FALSE;
+  }
+  
+  // cast xvec or yvec to FLT if it is type INT
+  CastVector (avec, OPIHI_FLT);
+  CastVector (zvec, OPIHI_FLT);
+  ResetVector (hvec, OPIHI_FLT, avec[0].Nelements);
+  ResetVector (dvec, OPIHI_FLT, avec[0].Nelements);
+  ResetVector (rvec, OPIHI_FLT, avec[0].Nelements);
+
+  Hv = hvec[0].elements.Flt;
+  Dv = dvec[0].elements.Flt;
+  Av = avec[0].elements.Flt;
+  Zv = zvec[0].elements.Flt;
+  Rv = rvec[0].elements.Flt;
+
+  for (i = 0; i < hvec[0].Nelements; i++, Hv++, Dv++, Av++, Zv++, Rv++) {
+    AZ_to_HD (Hv, Dv, Rv, *Av, *Zv, lat);
+  }
+  return TRUE;
+  
+ usage:
+  gprint (GP_ERR, "USAGE: altaz -az (ha) (dec) to (alt) (az)\n");
+  gprint (GP_ERR, "USAGE: altaz -hd (alt) (az) to (ha) (dec)\n");
+  gprint (GP_ERR, "       -hd alt/az to ha/dec, -az ha/dec to alt/az\n");
+  gprint (GP_ERR, "       returned values in variables or vectors provided\n");
+  return FALSE;
+}
+
+int HD_to_AZ(double *alt, double *az, double *rot, double ha, double dec, double lat) {
+
+  double sind, sinh, cosh;
+
   sind = dSIN (dec) * dSIN (lat) + dCOS (dec) * dCOS (ha) * dCOS (lat);
-  alt  = DEG_RAD * asin (sind);
+  *alt  = DEG_RAD * asin (sind);
 
   sinh = - dCOS (dec) * dSIN (ha);
   cosh =   dSIN (dec) * dCOS (lat) - dCOS (dec) * dCOS (ha) * dSIN (lat);
 
-  az = DEG_RAD * atan2 (sinh, cosh);
-  set_variable (argv[4], alt);
-  set_variable (argv[5], az);
+  *az = DEG_RAD * atan2 (sinh, cosh);
+  
+  sinh = -dCOS(*az) * dSIN(*alt) * dSIN(ha) * dSIN(lat) + dSIN(*az) * dSIN(*alt) * dCOS(ha) - dSIN(ha) * dCOS(*alt) * dCOS(lat);
+  cosh = -dSIN(*az) * dSIN(ha) * dSIN(lat) - dCOS(*az) * dCOS(ha);
+  *rot = -DEG_RAD * atan2 (sinh, cosh);
+  
+  return TRUE;
+}
 
-  sinh = -dCOS(az) * dSIN(alt) * dSIN(ha) * dSIN(lat) + dSIN(az) * dSIN(alt) * dCOS(ha) - dSIN(ha) * dCOS(alt) * dCOS(lat);
-  cosh = -dSIN(az) * dSIN(ha) * dSIN(lat) - dCOS(az) * dCOS(ha);
-  rot = -DEG_RAD * atan2 (sinh, cosh);
-  set_variable ("ROT", rot);
+int AZ_to_HD(double *ha, double *dec, double *rot, double alt, double az, double lat) {
 
-  return (TRUE);
-  
- altaz:
-  /* alt/az -> ha/dec */
-  alt = atof (argv[4]);
-  az  = atof (argv[5]);
-
-  latstr = get_variable ("LATITUDE");
-  if (latstr == (char *) NULL) {
-    gprint (GP_ERR, "please define $LATITUDE\n");
-    return (FALSE);
-  }
-  lat = atof (latstr);
-  free (latstr);
+  double sind, sinh, cosh;
 
   sind = dSIN (alt) * dSIN (lat) + dCOS (alt) * dCOS (az) * dCOS (lat);
-  dec  = DEG_RAD * asin (sind);
+  *dec  = DEG_RAD * asin (sind);
 
   sinh = -dCOS (alt) * dSIN (az);
   cosh =  dSIN (alt) * dCOS (lat) - dCOS (alt) * dCOS (az) * dSIN (lat);
 
-  ha = DEG_RAD * atan2 (sinh, cosh);
-  set_variable (argv[2], ha);
-  set_variable (argv[3], dec);
+  *ha = DEG_RAD * atan2 (sinh, cosh);
 
-  sinh = -dCOS(az) * dSIN(alt) * dSIN(ha) * dSIN(lat) + dSIN(az) * dSIN(alt) * dCOS(ha) - dSIN(ha) * dCOS(alt) * dCOS(lat);
-  cosh = -dSIN(az) * dSIN(ha) * dSIN(lat) - dCOS(az) * dCOS(ha);
-  rot = -DEG_RAD * atan2 (sinh, cosh);
-  set_variable ("ROT", rot);
+  sinh = -dCOS(az) * dSIN(alt) * dSIN(*ha) * dSIN(lat) + dSIN(az) * dSIN(alt) * dCOS(*ha) - dSIN(*ha) * dCOS(alt) * dCOS(lat);
+  cosh = -dSIN(az) * dSIN(*ha) * dSIN(lat) - dCOS(az) * dCOS(*ha);
+  *rot = -DEG_RAD * atan2 (sinh, cosh);
 
-  return (TRUE);
-  
- usage:
-  gprint (GP_ERR, "USAGE: altaz -h (ha) (dec) (alt) (az)\n");
-  gprint (GP_ERR, "USAGE: altaz -c (ha) (dec) (alt) (az)\n");
-  gprint (GP_ERR, "       -h alt/az to ha/dec, -c ha/dec to alt/az\n");
-  gprint (GP_ERR, "       returned values in variables provided\n");
-  return (FALSE);
-
+  return TRUE;
 }
-
Index: trunk/Ohana/src/opihi/cmd.astro/elliprofile.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/elliprofile.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.astro/elliprofile.c	(revision 27435)
@@ -3,10 +3,10 @@
 int elliprofile (int argc, char **argv) {
   
-  int i, ix, iy, Nx, Ny, N, center;
+  int i, ix, iy, Nx, Ny;
   float *in;
-  double Rmaj, Rmin, phi, alpha, Io, ARatio;
+  double Rmaj, Rmin, phi;
   double root1, root2, R, A1, A2, A3;
   double Sx, Sy, Sxy;
-  double x, y, r, f, Xo, Yo;
+  double x, y, Xo, Yo;
   Buffer *buf;
   Vector *rvec, *fvec;
Index: trunk/Ohana/src/opihi/cmd.astro/galprofiles.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/galprofiles.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.astro/galprofiles.c	(revision 27435)
@@ -5,5 +5,5 @@
 int galprofiles (int argc, char **argv) {
   
-  int i, j, Nx, Ny, N, Nsec, NELEMENTS;
+  int i, Nx, Ny, N, Nsec, NELEMENTS;
   float *in;
   double theta, dtheta, x, y, Xo, Yo, r, Rmax, value;
Index: trunk/Ohana/src/opihi/cmd.astro/galradbins.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/galradbins.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.astro/galradbins.c	(revision 27435)
@@ -12,5 +12,5 @@
   
   int i, Nbin;
-  double Rmin, Rmax;
+  double Rmax;
   Vector *fvec, *rvec, *Fvec, *Rvec, *Avec;
 
Index: trunk/Ohana/src/opihi/cmd.astro/galradius.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/galradius.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.astro/galradius.c	(revision 27435)
@@ -6,11 +6,9 @@
 int galradius (int argc, char **argv) {
   
-  int i, j, Nx, Ny, N, Nsec, NELEMENTS, Rbin, Nout, above;
-  double theta, dtheta, x, y, Xo, Yo, r, Rmax, Rmin, value;
+  int i, j, N, Rbin, Nout, above;
+  double Rmax, Rmin;
   double Fmin, Fmax, dF, Fm, Fp, Fo, Rsum, Rnpt, Ro;
   opihi_flt *flux, *radius, *values;
-  Buffer *buf;
-  Vector *fvec, *rvec, *tvec, *Fvec, *Rvec;
-  char name[128];
+  Vector *fvec, *rvec, *Fvec, *Rvec;
 
   if (argc != 5) {
Index: trunk/Ohana/src/opihi/cmd.astro/petrosian.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/petrosian.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.astro/petrosian.c	(revision 27435)
@@ -4,5 +4,4 @@
   
   int i, above;
-  float *in;
   double Fsum, Asum, Area, R_90, rad_90, flux_90;
   Vector *rvec, *avec, *fvec, *Rvec, *Fvec, *Svec, *Avec;
@@ -40,4 +39,5 @@
   ResetVector (Avec, OPIHI_FLT, fvec[0].Nelements);
 
+  R_90 = 0.1;
   above = TRUE;
   Fsum = 0.0;
Index: trunk/Ohana/src/opihi/cmd.astro/precess.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/precess.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.astro/precess.c	(revision 27435)
@@ -97,5 +97,5 @@
   opihi_flt *Dv = yvec[0].elements.Flt;
 
-  for (i = 0; i < xvec[0].Nelements; i++, Av, Dv) {
+  for (i = 0; i < xvec[0].Nelements; i++, Av++, Dv++) {
     A = *Av;
     D = *Dv;
Index: trunk/Ohana/src/opihi/cmd.astro/region.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/region.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.astro/region.c	(revision 27435)
@@ -3,5 +3,4 @@
 int region (int argc, char **argv) {
   
-  char string[256];
   double Ra, Dec, Radius;
   float dx, dy;
Index: trunk/Ohana/src/opihi/cmd.basic/cd.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.basic/cd.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.basic/cd.c	(revision 27435)
@@ -51,5 +51,5 @@
   }
   
-  if ((cwd = getcwd(NULL, 64)) == NULL) {
+  if ((cwd = getcwd(NULL, 1024)) == NULL) {
     gprint (GP_ERR, "error getting cwd\n");
     if (var != NULL) free (var);
Index: trunk/Ohana/src/opihi/cmd.basic/date.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.basic/date.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.basic/date.c	(revision 27435)
@@ -40,5 +40,5 @@
       set_int_variable (varName, now.tv_sec - REFTIME);
     } else {
-      gprint (GP_ERR, "%d\n", now.tv_sec - REFTIME);
+      gprint (GP_ERR, "%d\n", (int) now.tv_sec - REFTIME);
     }
   } else {
Index: trunk/Ohana/src/opihi/cmd.basic/inthash.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.basic/inthash.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.basic/inthash.c	(revision 27435)
@@ -3,5 +3,5 @@
 int inthash (int argc, char **argv) {
 
-  int i, N, modulus, value, input;
+  int N, modulus, value, input;
   char *varName;
 
Index: trunk/Ohana/src/opihi/cmd.basic/test/for.sh
===================================================================
--- trunk/Ohana/src/opihi/cmd.basic/test/for.sh	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.basic/test/for.sh	(revision 27435)
@@ -169,5 +169,5 @@
  $PASS = 1
 
- if ($endmem - $startmem > 10)
+ if ($endmem - $startmem > 80)
    $PASS = 0
    echo "growth: {$endmem-$startmem}"
Index: trunk/Ohana/src/opihi/cmd.data/dbconnect.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/dbconnect.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.data/dbconnect.c	(revision 27435)
@@ -47,5 +47,4 @@
     gprint (GP_ERR, "failed to set interactive timout\n");
     gprint (GP_ERR, "%s\n", mysql_error (connection));
-    free (query);
     return (FALSE);
   }
@@ -57,5 +56,4 @@
     gprint (GP_ERR, "failed to set wait timout\n");
     gprint (GP_ERR, "%s\n", mysql_error (connection));
-    free (query);
     return (FALSE);
   }
@@ -71,5 +69,4 @@
     gprint (GP_ERR, "failed to get timout\n");
     gprint (GP_ERR, "%s\n", mysql_error (connection));
-    free (query);
     return (FALSE);
   }
@@ -84,5 +81,4 @@
     gprint (GP_ERR, "failed to get timout\n");
     gprint (GP_ERR, "%s\n", mysql_error (connection));
-    free (query);
     return (FALSE);
   }
Index: trunk/Ohana/src/opihi/cmd.data/extract.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/extract.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.data/extract.c	(revision 27435)
@@ -70,6 +70,6 @@
     if ((out[0].header.Naxis[1] != Ny) || (out[0].header.Naxis[0] != Nx)) {
       gprint (GP_ERR, "matrix sizes mis-matched\n");
-      gprint (GP_ERR, "%d x %d  vs  %d x %d\n", Nx, Ny, 
-	       out[0].header.Naxis[0], out[0].header.Naxis[1]);
+      gprint (GP_ERR, "%d x %d  vs  %lld x %lld\n", Nx, Ny, 
+	      (long long) out[0].header.Naxis[0], (long long) out[0].header.Naxis[1]);
       return (FALSE);
     }
Index: trunk/Ohana/src/opihi/cmd.data/keyword.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/keyword.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.data/keyword.c	(revision 27435)
@@ -107,11 +107,11 @@
       }
       ivalue = !strcasecmp (line, "T");
-      gfits_modify (&buf[0].header, argv[2], "%t", 1, ivalue);
+      gfits_modify_alt (&buf[0].header, argv[2], "%t", 1, ivalue);
       return (TRUE);
     case KEYCOMMENT:
-      gfits_modify (&buf[0].header, argv[2], "%C", 1, line);
+      gfits_modify_alt (&buf[0].header, argv[2], "%C", 1, line);
       return (TRUE);
     case COMMENT:
-      gfits_modify (&buf[0].header, argv[2], "%S", 0, line);
+      gfits_modify_alt (&buf[0].header, argv[2], "%S", 0, line);
       return (TRUE);
     }
@@ -135,5 +135,5 @@
 
   if (ascomment) {
-    status = gfits_scan (&buf[0].header, argv[2], "%C", 1, line);
+    status = gfits_scan_alt (&buf[0].header, argv[2], "%C", 1, line);
     if (!status) goto failure;
     if (argc == 4) 
Index: trunk/Ohana/src/opihi/cmd.data/list_header.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/list_header.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.data/list_header.c	(revision 27435)
@@ -49,5 +49,5 @@
     gfits_modify (&buf[0].header, "BSCALE", "%lf", 1, bscale);
     gfits_modify (&buf[0].header, "BZERO",  "%lf", 1, bzero);
-    gfits_modify (&buf[0].header, "UNSIGN", "%t",  1, unsign);
+    gfits_modify_alt (&buf[0].header, "UNSIGN", "%t",  1, unsign);
     
   } else {
Index: trunk/Ohana/src/opihi/cmd.data/matrix.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/matrix.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.data/matrix.c	(revision 27435)
@@ -23,7 +23,7 @@
 
     if (bufB[0].matrix.Naxis[0] != bufC[0].matrix.Naxis[1]) {
-      gprint (GP_ERR, "size mis-match in matrices: (%d x %d) * (%d x %d)\n", 
-	      bufB[0].matrix.Naxis[0], bufB[0].matrix.Naxis[1], 
-	      bufC[0].matrix.Naxis[0], bufC[0].matrix.Naxis[1]);
+      gprint (GP_ERR, "size mis-match in matrices: (%lld x %lld) * (%lld x %lld)\n", 
+	      (long long) bufB[0].matrix.Naxis[0], (long long) bufB[0].matrix.Naxis[1], 
+	      (long long) bufC[0].matrix.Naxis[0], (long long) bufC[0].matrix.Naxis[1]);
       return (FALSE);
     }
Index: trunk/Ohana/src/opihi/cmd.data/rd.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/rd.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.data/rd.c	(revision 27435)
@@ -153,5 +153,5 @@
     buf[0].header.Naxes = 0;
     ALLOCATE (buf[0].matrix.buffer, char, 1);
-    buf[0].matrix.size = 0;
+    buf[0].matrix.datasize = 0;
     buf[0].bitpix = 16;
     buf[0].bzero = 0;
@@ -222,6 +222,6 @@
   buf[0].unsign = buf[0].header.unsign;
 
-  gprint (GP_LOG, "read %d bytes from %s into buffer %s\n", 
-	   buf[0].header.size + buf[0].matrix.size, argv[2], argv[1]);
+  gprint (GP_LOG, "read %lld bytes from %s into buffer %s\n", 
+	  (long long) buf[0].header.datasize + buf[0].matrix.datasize, argv[2], argv[1]);
 
   blank = 0xffff;
Index: trunk/Ohana/src/opihi/cmd.data/rdseg.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/rdseg.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.data/rdseg.c	(revision 27435)
@@ -62,6 +62,5 @@
   buf[0].bzero  = buf[0].header.bzero;     /* store the original values */
   buf[0].unsign = buf[0].header.unsign;
-  gprint (GP_LOG, "read %d bytes from %s into buffer %s\n", 
-	   buf[0].header.size + buf[0].matrix.size, argv[2], argv[1]);
+  gprint (GP_LOG, "read %lld bytes from %s into buffer %s\n", (long long) buf[0].header.datasize + buf[0].matrix.datasize, argv[2], argv[1]);
 
   gfits_scan (&buf[0].header, "BLANK", "%d", 1, &blank);
Index: trunk/Ohana/src/opihi/cmd.data/read_vectors.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/read_vectors.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.data/read_vectors.c	(revision 27435)
@@ -57,5 +57,5 @@
     return (FALSE);
   }
-  fseek (f, 0, SEEK_SET);
+  fseeko (f, 0LL, SEEK_SET);
 
   Nvec = (argc - 1) / 2;
@@ -159,5 +159,6 @@
 int read_table_vectors (int argc, char **argv, char *extname) {
 
-  int i, j, k, N, Nbytes, Nextend, Ny, Binary, vecType;
+  off_t Nbytes;
+  int i, j, k, N, Nextend, Ny, Binary, vecType;
   char type[16], ID[80], *CCDKeyword;
   FTable table;
@@ -184,5 +185,5 @@
 
   if (f == NULL) ESCAPE ("file not found");
-  fseek (f, 0, SEEK_SET);
+  fseeko (f, 0LL, SEEK_SET);
   table.header = &header;
 
@@ -193,5 +194,5 @@
     if (!gfits_load_header (f, &header)) ESCAPE ("error reading primary header for file");
     Nbytes = gfits_data_size (&header);
-    fseek (f, Nbytes, SEEK_CUR);
+    fseeko (f, Nbytes, SEEK_CUR);
     gfits_free_header (&header);
 
@@ -200,5 +201,5 @@
       Nbytes = gfits_data_size (&header);
       /* skip the prior data buffers */
-      fseek (f, Nbytes, SEEK_CUR);
+      fseeko (f, Nbytes, SEEK_CUR);
       gfits_free_header (&header);
     }
@@ -215,14 +216,14 @@
 
     while (1) {
-      if (!gfits_load_header (f, &header)) ESCAPE ("extensio not found in file");
+      if (!gfits_load_header (f, &header)) ESCAPE ("extension not found in file");
       Nbytes = gfits_data_size (&header);
 
       if (!gfits_scan (&header, CCDKeyword, "%s", 1, ID)) {
-	fseek (f, Nbytes, SEEK_CUR);
+	fseeko (f, Nbytes, SEEK_CUR);
 	gfits_free_header (&header);
 	continue;
       }
       if (strcmp (ID, extname)) {
-	fseek (f, Nbytes, SEEK_CUR);
+	fseeko (f, Nbytes, SEEK_CUR);
 	gfits_free_header (&header);
 	continue;
Index: trunk/Ohana/src/opihi/cmd.data/rebin.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/rebin.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.data/rebin.c	(revision 27435)
@@ -63,5 +63,5 @@
     }      
   }
-  if (VERBOSE) gprint (GP_LOG, "rebin %s to %s (%d,%d to %d,%d)\n", argv[1], argv[2], in[0].header.Naxis[0], in[0].header.Naxis[1], nx, ny);
+  if (VERBOSE) gprint (GP_LOG, "rebin %s to %s (%lld,%lld to %d,%d)\n", argv[1], argv[2], (long long) in[0].header.Naxis[0], (long long) in[0].header.Naxis[1], nx, ny);
 
   Nx = in[0].header.Naxis[0];
Index: trunk/Ohana/src/opihi/cmd.data/relocate.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/relocate.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.data/relocate.c	(revision 27435)
@@ -3,5 +3,4 @@
 int relocate (int argc, char **argv) {
 
-  char *end;
   int x, y;
   int N, kapa;
Index: trunk/Ohana/src/opihi/cmd.data/rotate.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/rotate.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.data/rotate.c	(revision 27435)
@@ -43,5 +43,5 @@
     gfits_modify (&buf[0].header, "NAXIS1", "%d", 1, NY);
     gfits_modify (&buf[0].header, "NAXIS2", "%d", 1, NX);
-    gfits_print  (&buf[0].header, "HISTORY", "%S", 1, "WARNING: rotated image!");
+    gfits_print_alt (&buf[0].header, "HISTORY", "%S", 1, "WARNING: rotated image!");
     gfits_create_matrix (&buf[0].header, &buf[0].matrix);
     out_buff = (float *)buf[0].matrix.buffer;
@@ -82,5 +82,5 @@
     gfits_modify (&buf[0].header, "NAXIS1", "%d", 1, NY);
     gfits_modify (&buf[0].header, "NAXIS2", "%d", 1, NX);
-    gfits_print  (&buf[0].header, "HISTORY", "%S", 1, "WARNING: rotated image!");
+    gfits_print_alt (&buf[0].header, "HISTORY", "%S", 1, "WARNING: rotated image!");
     gfits_create_matrix (&buf[0].header, &buf[0].matrix);
     out_buff = (float *)buf[0].matrix.buffer;
@@ -120,5 +120,5 @@
 
   if (!strcasecmp (argv[2], "UPSIDE") || (atof (argv[2]) == -180) || (atof (argv[2]) == 180)) {
-    gfits_print  (&buf[0].header, "HISTORY", "%S", 1, "WARNING: rotated image!");
+    gfits_print_alt (&buf[0].header, "HISTORY", "%S", 1, "WARNING: rotated image!");
     gfits_create_matrix (&buf[0].header, &buf[0].matrix);
     out_buff = (float *)buf[0].matrix.buffer;
@@ -155,5 +155,5 @@
 
   if (!strcasecmp (argv[2], "FLIPY")) {
-    gfits_print  (&buf[0].header, "HISTORY", "%S", 1, "WARNING: rotated image!");
+    gfits_print_alt (&buf[0].header, "HISTORY", "%S", 1, "WARNING: rotated image!");
     gfits_create_matrix (&buf[0].header, &buf[0].matrix);
     out_buff = (float *)buf[0].matrix.buffer;
@@ -190,5 +190,5 @@
 
   if (!strcasecmp (argv[2], "FLIPX")) {
-    gfits_print  (&buf[0].header, "HISTORY", "%S", 1, "WARNING: rotated image!");
+    gfits_print_alt (&buf[0].header, "HISTORY", "%S", 1, "WARNING: rotated image!");
     gfits_create_matrix (&buf[0].header, &buf[0].matrix);
     out_buff = (float *)buf[0].matrix.buffer;
@@ -272,5 +272,5 @@
   gfits_modify (&buf[0].header, "NAXIS2", "%d", 1, Ly);
   gfits_create_matrix (&buf[0].header, &buf[0].matrix);
-  gfits_print  (&buf[0].header, "HISTORY", "%S", 1, "WARNING: rotated image!");
+  gfits_print_alt (&buf[0].header, "HISTORY", "%S", 1, "WARNING: rotated image!");
   out_buff = (float *)buf[0].matrix.buffer;
   for (j = 0; j < Ly; j++) {
Index: trunk/Ohana/src/opihi/cmd.data/test/dimendown.sh
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/test/dimendown.sh	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.data/test/dimendown.sh	(revision 27435)
@@ -42,5 +42,5 @@
  $startmem = $word:1
 
- for i 0 1000
+ for i 0 10000
   dimendown timg val
   dimendown timg xc -x
@@ -53,5 +53,5 @@
  $PASS = 1
 
- if ($endmem - $startmem > 10)
+ if ($endmem - $startmem > 128)
    $PASS = 0
    echo "growth: {$endmem-$startmem}"
Index: trunk/Ohana/src/opihi/cmd.data/test/integrate.sh
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/test/integrate.sh	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.data/test/integrate.sh	(revision 27435)
@@ -40,5 +40,5 @@
  $PASS = 1
 
- if ($endmem - $startmem > 10)
+ if ($endmem - $startmem > 128)
    $PASS = 0
    echo "growth: {$endmem-$startmem}"
Index: trunk/Ohana/src/opihi/cmd.data/test/interpolate.sh
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/test/interpolate.sh	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.data/test/interpolate.sh	(revision 27435)
@@ -41,5 +41,5 @@
  $PASS = 1
 
- if ($endmem - $startmem > 10)
+ if ($endmem - $startmem > 128)
    $PASS = 0
    echo "growth: {$endmem-$startmem}"
Index: trunk/Ohana/src/opihi/cmd.data/test/periodogram.sh
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/test/periodogram.sh	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.data/test/periodogram.sh	(revision 27435)
@@ -136,5 +136,5 @@
  $PASS = 1
 
- if ($endmem - $startmem > 10)
+ if ($endmem - $startmem > 180)
    $PASS = 0
    echo "growth: {$endmem-$startmem}"
Index: trunk/Ohana/src/opihi/cmd.data/wd.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/wd.c	(revision 27392)
+++ trunk/Ohana/src/opihi/cmd.data/wd.c	(revision 27435)
@@ -75,9 +75,9 @@
   /* save the (float) version, write out a temporary buffer */
   temp_matrix = buf[0].matrix;
-  ALLOCATE (temp_matrix.buffer, char, MAX(1, temp_matrix.size));
-  memcpy (temp_matrix.buffer, buf[0].matrix.buffer, temp_matrix.size);
+  ALLOCATE (temp_matrix.buffer, char, MAX(1, temp_matrix.datasize));
+  memcpy (temp_matrix.buffer, buf[0].matrix.buffer, temp_matrix.datasize);
   temp_header = buf[0].header;
-  ALLOCATE (temp_header.buffer, char, MAX(1, temp_header.size));
-  memcpy (temp_header.buffer, buf[0].header.buffer, temp_header.size);
+  ALLOCATE (temp_header.buffer, char, MAX(1, temp_header.datasize));
+  memcpy (temp_header.buffer, buf[0].header.buffer, temp_header.datasize);
 
   if (temp_header.Naxes) {
@@ -88,5 +88,5 @@
     gfits_modify (&temp_header, "BSCALE", "%lf", 1, outScale);
     gfits_modify (&temp_header, "BZERO",  "%lf", 1, outZero);
-    gfits_modify (&temp_header, "UNSIGN", "%t", 1, outUnsign);
+    gfits_modify_alt (&temp_header, "UNSIGN", "%t", 1, outUnsign);
   }
 
@@ -94,4 +94,5 @@
     Header Xhead;
     FILE *f;
+    off_t nbytes;
     int status, Nextend;
 
@@ -109,5 +110,5 @@
     }
 
-    gfits_modify (&Xhead, "EXTEND", "%t", 1, TRUE);
+    gfits_modify_alt (&Xhead, "EXTEND", "%t", 1, TRUE);
 
     Nextend = 0;
@@ -125,7 +126,7 @@
     
     /* position to begining of file to write header */
-    fseek (f, 0, SEEK_SET);
-    status = fwrite (Xhead.buffer, 1, Xhead.size, f);
-    if (status != Xhead.size) {
+    fseeko (f, 0LL, SEEK_SET);
+    nbytes = fwrite (Xhead.buffer, 1, Xhead.datasize, f);
+    if (nbytes != Xhead.datasize) {
       gprint (GP_ERR, "ERROR: failed writing data to image header\n");
       status = FALSE;
@@ -144,8 +145,8 @@
 
     /* position to end of file to write new extend */
-    fseek (f, 0, SEEK_END);
-    status = fwrite (temp_header.buffer, 1, temp_header.size, f);
+    fseeko (f, 0LL, SEEK_END);
+    nbytes = fwrite (temp_header.buffer, 1, temp_header.datasize, f);
     fclose (f);
-    if (status != temp_header.size) {
+    if (nbytes != temp_header.datasize) {
       gprint (GP_ERR, "failed to write file\n");
       status = FALSE;
Index: trunk/Ohana/src/opihi/dvo/ImageOps.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/ImageOps.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/ImageOps.c	(revision 27435)
@@ -1,12 +1,12 @@
 # include "dvoshell.h"
 
-void image_subset (Image *image, int Nimage, int **Subset, int *Nsubset,
+void image_subset (Image *image, off_t Nimage, off_t **Subset, off_t *Nsubset,
 		   SkyRegionSelection *selection, 
 		   unsigned long int tzero, double trange, int TimeSelect) 
 {
 
-  int i, j, flipped, status, InPic;
-  int *subset;
-  int N, n, npts;
+  int j, flipped, status, InPic;
+  off_t i, n, *subset;
+  int npts;
   double r, d, X, Y, x[4], y[4], Rmin, Rmax, Rmid;
   Graphdata graph;
@@ -44,6 +44,6 @@
 
   npts = 200;
-  ALLOCATE (subset, int, npts);
-  n = N = 0;
+  ALLOCATE (subset, off_t, npts);
+  n = 0;
   for (i = 0; i < Nimage; i++) {
     if (TimeSelect && ((image[i].tzero < tzero) || (image[i].tzero+image[i].trate*image[i].NY > tzero + trange))) continue;
@@ -114,9 +114,9 @@
     if (n > npts - 1) {
       npts += 200;
-      REALLOCATE (subset, int, npts);
+      REALLOCATE (subset, off_t, npts);
     }
   }
 
-  REALLOCATE (subset, int, MAX (n, 1));
+  REALLOCATE (subset, off_t, MAX (n, 1));
   *Subset = subset;
   *Nsubset = n;
Index: trunk/Ohana/src/opihi/dvo/ImageSelection.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/ImageSelection.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/ImageSelection.c	(revision 27435)
@@ -3,7 +3,7 @@
 /* db image table */
 static Image *image = NULL;
-static int *subset = NULL;
-static int Nimage = 0;
-static int Nsubset = 0;
+static off_t *subset = NULL;
+static off_t Nimage = 0;
+static off_t Nsubset = 0;
 static Coords mosaic;
 
Index: trunk/Ohana/src/opihi/dvo/LoadImages.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/LoadImages.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/LoadImages.c	(revision 27435)
@@ -1,5 +1,5 @@
 # include "dvoshell.h"
 
-Image *LoadImages (int *nimage) {
+Image *LoadImages (off_t *Nimage) {
 
   int status;
@@ -25,5 +25,5 @@
     gprint (GP_ERR, "note: image catalog is empty\n");
     ALLOCATE (image, Image, 1);
-    *nimage = 1;
+    *Nimage = 1;
     return (image);
   }
@@ -37,5 +37,5 @@
   }
 
-  image = gfits_table_get_Image (&db.ftable, nimage, &db.swapped);
+  image = gfits_table_get_Image (&db.ftable, Nimage, &db.swapped);
   return (image);
 }
Index: trunk/Ohana/src/opihi/dvo/Makefile
===================================================================
--- trunk/Ohana/src/opihi/dvo/Makefile	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/Makefile	(revision 27435)
@@ -26,7 +26,7 @@
 $(SRC)/compare.$(ARCH).o                \
 $(SRC)/match_image.$(ARCH).o		\
-$(SRC)/photometry.$(ARCH).o             \
 $(SRC)/dvomisc.$(ARCH).o		\
 $(SRC)/region_list.$(ARCH).o		\
+$(SRC)/photometry.$(ARCH).o             \
 $(SRC)/dbBooleanCond.$(ARCH).o		\
 $(SRC)/dbCheckStack.$(ARCH).o		\
Index: trunk/Ohana/src/opihi/dvo/aregion.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/aregion.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/aregion.c	(revision 27435)
@@ -44,5 +44,5 @@
     NLINES += NDecLines[i];
   }
-  fseek (f, 5*2880 + 48*NLINES, SEEK_SET);
+  fseeko (f, 5*2880 + 48*NLINES, SEEK_SET);
       
   done = FALSE;
Index: trunk/Ohana/src/opihi/dvo/avextract.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/avextract.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/avextract.c	(revision 27435)
@@ -3,5 +3,6 @@
 int avextract (int argc, char **argv) {
   
-  int i, j, n, m, N, Npts, NPTS, last, next, state, Nfields, Nreturn, Ncstack, Nstack;
+  off_t i, j, n, m;
+  int N, Npts, NPTS, last, next, state, Nfields, Nreturn, Ncstack, Nstack;
   int Nsecfilt, mode, VERBOSE;
   char **cstack, name[1024];
@@ -79,4 +80,6 @@
 
   /* create output storage vectors */
+  Npts = 0;
+  NPTS = 100;
   ALLOCATE (values, dbValue, Nfields);
   ALLOCATE (vec, Vector *, Nreturn);
@@ -90,7 +93,4 @@
     ResetVector (vec[i], fields[i].type, NPTS);
   }
-
-  Npts = 0;
-  NPTS = 1;
 
   // grab data from all selected sky regions
@@ -103,5 +103,5 @@
     catalog.Nsecfilt = 0;
 
-    if (VERBOSE) gprint (GP_ERR, "trying %s (%d of %d)\n", catalog.filename, i, skylist[0].Nregions);
+    if (VERBOSE) gprint (GP_ERR, "trying %s (%lld of %lld)\n", catalog.filename, (long long) i, (long long) skylist[0].Nregions);
       
     // an error exit status here is a significant error
Index: trunk/Ohana/src/opihi/dvo/badimages.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/badimages.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/badimages.c	(revision 27435)
@@ -8,5 +8,6 @@
 int badimages (int argc, char **argv) {
   
-  int i, Nimage, entry, First, Cross;
+  off_t i, Nimage;
+  int entry, First, Cross;
   float *ptr;
   double nominal, big, small, value;
@@ -38,5 +39,5 @@
     ptr = &image[entry].coords.crpix1;
     for (i = 0; i < 22; i++) {
-      gprint (GP_LOG, "%2d: %g\n", i, ptr[i]);
+      gprint (GP_LOG, "%2lld: %g\n", (long long) i, ptr[i]);
     }
     value = image[entry].coords.pc1_1*image[entry].coords.pc2_2 + image[entry].coords.pc1_2*image[entry].coords.pc2_1;
@@ -57,5 +58,5 @@
       value = image[i].coords.pc1_1*image[i].coords.pc2_2 + image[i].coords.pc1_2*image[i].coords.pc2_1;
       if ((value > big) || (value < small)) {
-	gprint (GP_LOG, "%5d %s: %d %g\n", i, image[i].name, image[i].tzero, value);
+	gprint (GP_LOG, "%5lld %s: %d %g\n", (long long) i, image[i].name, image[i].tzero, value);
       }
     }
@@ -64,5 +65,5 @@
       ptr = &image[i].coords.crpix1;
       if ((ptr[entry] > big) || (ptr[entry] < small)) {
-	gprint (GP_LOG, "%5d %s: %d %g\n", i, image[i].name, image[i].tzero, ptr[entry]);
+	gprint (GP_LOG, "%5lld %s: %d %g\n", (long long) i, image[i].name, image[i].tzero, ptr[entry]);
       }
     }
Index: trunk/Ohana/src/opihi/dvo/calextract.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/calextract.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/calextract.c	(revision 27435)
@@ -5,6 +5,6 @@
 int calextract (int argc, char **argv) {
   
-  int i, N, Nr, mode[2];
-  int Nsecfilt, NSTAR;
+  off_t i, Nr;
+  int Nsecfilt, NSTAR, N, mode[2];
 
   PhotCode *code[2];
Index: trunk/Ohana/src/opihi/dvo/calmextract.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/calmextract.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/calmextract.c	(revision 27435)
@@ -6,6 +6,6 @@
 int calmextract (int argc, char **argv) {
   
-  int i, k, N, Nr, mode[2];
-  int NSTAR, Nstar, Nsecfilt;
+  off_t i, k, Nr;
+  int NSTAR, Nstar, Nsecfilt, N, mode[2];
 
   Catalog catalog;
@@ -169,5 +169,6 @@
 int ConcatMeasures (Vector *vec, PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, int Nin, int param) {
 
-  int i, Ns, N;
+  off_t i, N;
+  int Ns;
   double *value;
 
Index: trunk/Ohana/src/opihi/dvo/ccd.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/ccd.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/ccd.c	(revision 27435)
@@ -4,6 +4,7 @@
   
   double *M1, *M2;
-  int i, m, k, Npts, NPTS, N;
-  int N1, N2, i1, i2, mode[4];
+  off_t i, m, k, N1, N2, i1, i2;
+  int Npts, NPTS, N;
+  int mode[4];
   int Nsecfilt, KeepNulls;
   void *Signal;
Index: trunk/Ohana/src/opihi/dvo/cmatch.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/cmatch.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/cmatch.c	(revision 27435)
@@ -37,5 +37,5 @@
   }
   dvo_catalog_unlock (&catalog1);
-  gprint (GP_ERR, "read %d stars from phot catalog file %s\n", catalog1.Naverage, filename);
+  gprint (GP_ERR, "read %lld stars from phot catalog file %s\n", (long long) catalog1.Naverage, filename);
 
   /* this is for loading from a text file, presumably hstgsc or usno
Index: trunk/Ohana/src/opihi/dvo/cmd.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/cmd.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/cmd.c	(revision 27435)
@@ -4,5 +4,6 @@
   
   double *M1, *M3;
-  int i, j, m, i1, i3, N1, N3, N;
+  off_t i, j, m, N1, N3, i1, i3;
+  int N;
   int Npts, NPTS, mode[3];
   int Nsecfilt, KeepNulls;
Index: trunk/Ohana/src/opihi/dvo/cmpReadFile.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/cmpReadFile.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/cmpReadFile.c	(revision 27435)
@@ -4,7 +4,7 @@
 # define BLOCK 1000
 
-CMPstars *cmpReadFits (FILE *f, int *nstars) {
+CMPstars *cmpReadFits (FILE *f, off_t *nstars) {
 
-  int i, Nstars;
+  off_t i, Nstars;
   Header theader;
   FTable table;
@@ -44,7 +44,8 @@
 }
 
-CMPstars *cmpReadText (FILE *f, int *nstars) {
+CMPstars *cmpReadText (FILE *f, off_t *nstars) {
 
-  int j, N, Nextra, Ninstar, Nskip, Nbytes, nbytes;
+  off_t N;
+  int j, Nextra, Ninstar, Nskip, Nbytes, nbytes;
   int done;
   char *buffer, *c, *c2;
Index: trunk/Ohana/src/opihi/dvo/cmpload.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/cmpload.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/cmpload.c	(revision 27435)
@@ -56,5 +56,5 @@
     return (FALSE);
   }
-  fseek (f, header.size, SEEK_SET); 
+  fseeko (f, header.datasize, SEEK_SET); 
 
   Noverlay = 0;
Index: trunk/Ohana/src/opihi/dvo/cmpread.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/cmpread.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/cmpread.c	(revision 27435)
@@ -6,5 +6,6 @@
 int cmpread (int argc, char **argv) {
   
-  int i, field, Naxis, Nbytes, Nstars;
+  off_t i, Nbytes, Nstars;
+  int field, Naxis;
   double tR, tD;
   float value;
@@ -61,8 +62,8 @@
     return (FALSE);
   }
-  fseek (f, header.size, SEEK_SET); 
+  fseeko (f, header.datasize, SEEK_SET); 
 
   /* find expected number of stars */
-  if (!gfits_scan (&header, "NSTARS", "%d", 1, &Nstars)) {
+  if (!gfits_scan (&header, "NSTARS", "%lld", 1, (long long *) &Nstars)) {
     gprint (GP_ERR, "ERROR: can't get NSTARS from header\n");
     gfits_free_header (&header);
@@ -76,5 +77,5 @@
     /* allocate space for stars */
     gprint (GP_ERR, "reading from TEXT cmp file %s\n", argv[2]);
-    if (!gfits_scan (&header, "NSTARS", "%d", 1, &Nstars)) {
+    if (!gfits_scan (&header, "NSTARS", "%lld", 1, (long long *) &Nstars)) {
       gprint (GP_ERR, "ERROR: failed to find NSTARS\n");
       exit (1);
@@ -84,5 +85,5 @@
     gprint (GP_ERR, "reading from FITS cmp file %s\n", argv[2]);
     Nbytes = gfits_data_size (&header);
-    fseek (f, Nbytes, SEEK_CUR); 
+    fseeko (f, Nbytes, SEEK_CUR); 
     stars = cmpReadFits (f, &Nstars);
   }
@@ -138,5 +139,5 @@
   free (stars);
   gfits_free_header (&header);
-  gprint (GP_ERR, "loaded %d objects\n", Nstars);
+  gprint (GP_ERR, "loaded %lld objects\n", (long long) Nstars);
   return (TRUE);
 }
Index: trunk/Ohana/src/opihi/dvo/compare.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/compare.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/compare.c	(revision 27435)
@@ -5,5 +5,5 @@
 	      Vector *rvec,  Vector *dvec,  Vector *mvec, Vector *drvec, Vector *ddvec, Vector *dmvec, double radius) {
 
-  int i, j, first_j, Nmatch, NMATCH;
+  off_t i, j, first_j, Nmatch, NMATCH;
   double dX, dY, dR;
 
Index: trunk/Ohana/src/opihi/dvo/dbExtractAverages.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/dbExtractAverages.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/dbExtractAverages.c	(revision 27435)
@@ -42,5 +42,6 @@
 dbValue dbExtractAverages (Average *average, SecFilt *secfilt, Measure *measure, dbField *field) {
 
-  int i, Nsec;
+  off_t i;
+  int Nsec;
   dbValue value;
 
Index: trunk/Ohana/src/opihi/dvo/dbExtractImages.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/dbExtractImages.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/dbExtractImages.c	(revision 27435)
@@ -54,5 +54,5 @@
 
 /* return image.field based on the selection */
-dbValue dbExtractImages (Image *image, int Nimage, int N, dbField *field) {
+dbValue dbExtractImages (Image *image, off_t Nimage, off_t N, dbField *field) {
 
   double x, y;
Index: trunk/Ohana/src/opihi/dvo/detrend.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/detrend.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/detrend.c	(revision 27435)
@@ -7,5 +7,6 @@
  
   FILE *f;
-  int i, Nimage, status, N, TimeSelect;
+  off_t i, Nimage, status;
+  int N, TimeSelect;
   char DataBase[256];
   time_t tzero, tend;
@@ -133,8 +134,8 @@
     return (FALSE);
   }
-  fseek (f, header.size, SEEK_SET);
+  fseeko (f, header.datasize, SEEK_SET);
 
   /* load existing data from database */
-  gfits_scan (&header, "NIMAGES", "%d", 1, &Nimage);
+  gfits_scan (&header, "NIMAGES", "%lld", 1, (long long *) &Nimage);
   ALLOCATE (pimage, RegImage, Nimage);
   status = fread (pimage, sizeof(RegImage), Nimage, f);
@@ -142,5 +143,5 @@
 
   if (status != Nimage) {
-    gprint (GP_ERR, "ERROR: header and data in dB don't match (%d vs %d)\n", Nimage, status);
+    gprint (GP_ERR, "ERROR: header and data in dB don't match (%lld vs %lld)\n", (long long) Nimage, (long long) status);
     gfits_free_header (&header);
     free (pimage);
Index: trunk/Ohana/src/opihi/dvo/dmt.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/dmt.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/dmt.c	(revision 27435)
@@ -10,6 +10,7 @@
 # if (0)
 
-  int i, m, k, N, kapa, SaveVectors;
-  int Nsec, Nsecfilt, NPTS;
+  int kapa, SaveVectors;
+  int Nsec, Nsecfilt;
+  off_t i, m, k, N, NPTS;
   double Radius;
   float dt1, dt2, dmt1, dmt2;
Index: trunk/Ohana/src/opihi/dvo/dvomisc.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/dvomisc.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/dvomisc.c	(revision 27435)
@@ -1,7 +1,7 @@
 # include "dvoshell.h"
 
-void cprecess (Average *average, int Naverage, double in_epoch, double out_epoch) {
+void cprecess (Average *average, off_t Naverage, double in_epoch, double out_epoch) {
 
-  int i;
+  off_t i;
   double T;
   double A, D, RA, DEC, zeta, z, theta;
Index: trunk/Ohana/src/opihi/dvo/elixir.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/elixir.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/elixir.c	(revision 27435)
@@ -73,5 +73,5 @@
 
   /* write message to end of file */
-  fseek (f, 0, SEEK_END);
+  fseeko (f, 0LL, SEEK_END);
   fprintf (f, "%s\n", message);
 
Index: trunk/Ohana/src/opihi/dvo/find_regions.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/find_regions.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/find_regions.c	(revision 27435)
@@ -13,5 +13,6 @@
   double RA0, RA1, DEC0, DEC1;
   int i, j, NBigDec;
-  int NLINES, done, NREGIONS, nregion;
+  int done, NREGIONS, nregion;
+  off_t NLINES;
   
   VarConfig ("GSCFILE", "%s", filename);
@@ -91,5 +92,5 @@
     NLINES += NDecLines[i];
   }
-  fseek (f, 5*2880 + 48*NLINES, SEEK_SET);
+  fseeko (f, 5*2880 + 48*NLINES, SEEK_SET);
   
   /* should be in this section.  if not, there is a problem counting... */
@@ -140,5 +141,5 @@
 	NLINES += NDecLines[i];
       }
-      fseek (f, 5*2880 + 48*NLINES, SEEK_SET);
+      fseeko (f, 5*2880 + 48*NLINES, SEEK_SET);
       done = FALSE;
       j = 12;
Index: trunk/Ohana/src/opihi/dvo/fitcolors.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/fitcolors.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/fitcolors.c	(revision 27435)
@@ -10,6 +10,7 @@
   
   int *list, Nlist;
-  int i, k, m, N, NP1, NP2, NP, Np, Npts, NPTS;
-  int N1, N2, i1, i2, mode[4];
+  off_t i, k, m, N1, N2, i1, i2;
+  int N, NP1, NP2, NP, Np, Npts, NPTS;
+  int mode[4];
   int Nsecfilt, status;
   void *oldsignal;
@@ -173,5 +174,5 @@
     // the selection criteria
   }
-  gprint (GP_ERR, "using %d possible regions\n", skylist[0].Nregions);
+  gprint (GP_ERR, "using %lld possible regions\n", (long long) skylist[0].Nregions);
 
   /* vectors to save data */
Index: trunk/Ohana/src/opihi/dvo/fitsed.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/fitsed.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/fitsed.c	(revision 27435)
@@ -24,5 +24,6 @@
   
   int *hashcode;
-  int i, j, k, m, N, done, Nfit;
+  off_t i, j, k, m;
+  int N, done, Nfit;
   int Nsecfilt, status;
   void *oldsignal;
@@ -184,5 +185,5 @@
   /* loop over regions, extract data for each region */
   // XXX add interrupt checks
-  gprint (GP_ERR, "using %d possible regions\n", skylist[0].Nregions);
+  gprint (GP_ERR, "using %lld possible regions\n", (long long) skylist[0].Nregions);
   for (k = 0; k < skylist[0].Nregions; k++) {
     /* lock, load, unlock catalog */
Index: trunk/Ohana/src/opihi/dvo/gimages.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/gimages.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/gimages.c	(revision 27435)
@@ -5,5 +5,6 @@
 int gimages (int argc, char **argv) {
   
-  int i, j, N, Nimage, Nfound, *subset, Nsubset, status;
+  off_t i, j, Nimage, *subset, Nsubset;
+  int N, Nfound, status;
   double ra, dec, Ra, Dec, X, Y, Yo;
   double trange, t;
@@ -114,5 +115,5 @@
     { 
       Coords local;
-      double Ro, Do, Xo, Yo, Xs, Ys, Xe, Ye, Radius;
+      double Ro, Do, Xo, Yo, Xs, Ys, Radius;
       
       if (typehash == DistortImage) {
Index: trunk/Ohana/src/opihi/dvo/gstar.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/gstar.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/gstar.c	(revision 27435)
@@ -11,6 +11,8 @@
   double Mcat, Mrel;
   double *RA, *DEC;
-  int i, j, k, m, N, *N1, Nsecfilt, NPTS, QUIET, FULL_OUTPUT, INST;
-  int Nstars, found, GetMeasures, Nlo, Nhi;
+  off_t i, Nstars, *N1;
+  off_t j, k, m, N, Nlo, Nhi;
+  int Nsecfilt, NPTS, QUIET, FULL_OUTPUT, INST;
+  int found, GetMeasures;
   int SaveVectors;
   Vector *vec1, *vec2, *vec3, *vec4, *vec5, *vec6;
@@ -102,5 +104,5 @@
   ALLOCATE (RA, double, Nstars);
   ALLOCATE (DEC, double, Nstars);
-  ALLOCATE (N1, int, Nstars);
+  ALLOCATE (N1, off_t, Nstars);
 
   /* find star(s) in RA, DEC list -- use a dumb algorithm for now, improve later */
@@ -157,5 +159,5 @@
       k = N1[i];
       if (!QUIET) {
-	gprint (GP_LOG, "star: %d\n", k);
+	gprint (GP_LOG, "star: %lld\n", (long long) k);
 	gprint (GP_LOG, "%11.7f ", catalog.average[k].R);
 	gprint (GP_LOG, "%11.7f ", catalog.average[k].D);
Index: trunk/Ohana/src/opihi/dvo/images.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/images.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/images.c	(revision 27435)
@@ -11,5 +11,6 @@
 int images (int argc, char **argv) {
 
-  int i, j, Nimage, status, InPic, leftside, *plist, TimeSelect, ByName;
+  off_t i, Nimage;
+  int j, status, InPic, leftside, *plist, TimeSelect, ByName;
   int WITH_MOSAIC, SOLO_MOSAIC, HIDDEN;
   time_t tzero, tend;
Index: trunk/Ohana/src/opihi/dvo/imbox.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/imbox.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/imbox.c	(revision 27435)
@@ -1,7 +1,9 @@
 # include "dvoshell.h"
 
+// LARGEFILES: this function is currently limited to images with Nx,Ny each < 2^31
 int imbox (int argc, char **argv) {
   
-  int j, kapa, Nskip, status, InPic, flipped, N, haveNx, haveNy, Nx, Ny, SOLO_PHU, Npts, NPTS;
+  off_t Nskip;
+  int j, kapa, status, InPic, flipped, N, haveNx, haveNy, Nx, Ny, SOLO_PHU, Npts, NPTS;
   Vector Xvec, Yvec;
   double r, d, x[4], y[4], Rmin, Rmax, Rmid;
@@ -112,5 +114,5 @@
   skip:
     Nskip = gfits_data_size (&header);
-    fseek (f, Nskip, SEEK_CUR); 
+    fseeko (f, Nskip, SEEK_CUR); 
     gfits_free_header (&header);
   }
Index: trunk/Ohana/src/opihi/dvo/imdata.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/imdata.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/imdata.c	(revision 27435)
@@ -3,8 +3,8 @@
 int imdata (int argc, char **argv) {
   
-  int i, j, k, I;
-  int Nimage, N, NPTS, found, mode, TimeSelect;
-  int n, Nregions, NREGIONS, TimeFormat;
-  int *subset, Nsubset;
+  off_t i, j, k, n, I;
+  int N, NPTS, found, mode, TimeSelect, TimeFormat;
+  off_t Nregions, NREGIONS;
+  off_t *subset, Nsubset, Nimage;
   double trange;
   time_t tzero, start, stop, TimeReference;
Index: trunk/Ohana/src/opihi/dvo/imdense.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/imdense.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/imdense.c	(revision 27435)
@@ -5,5 +5,6 @@
   
   long A, B;
-  int i, kapa, N, Nimage, status, NPTS;
+  off_t i, Nimage;
+  int kapa, N, status, NPTS;
   double r, d, x, y, Rmin, Rmax;
   Vector Xvec, Yvec;
Index: trunk/Ohana/src/opihi/dvo/imextract.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/imextract.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/imextract.c	(revision 27435)
@@ -3,8 +3,7 @@
 int imextract (int argc, char **argv) {
   
-  // int *subset, Nsubset;  -- not sure if we need to use this or not...
-
-  int i, j, n, N, Npts, NPTS, last, next, state, Nfields, Nreturn, Ncstack, Nstack;
-  int Nimage, VERBOSE;
+  off_t i, j, Nimage;
+  int n, N, Npts, NPTS, last, next, state, Nfields, Nreturn, Ncstack, Nstack;
+  int VERBOSE;
   char **cstack, name[1024];
   void *Signal;
@@ -73,4 +72,6 @@
 
   /* create output storage vectors */
+  Npts = 0;
+  NPTS = 100;
   ALLOCATE (values, dbValue, Nfields);
   ALLOCATE (vec, Vector *, Nreturn);
@@ -84,7 +85,4 @@
     ResetVector (vec[i], fields[i].type, NPTS);
   }
-
-  Npts = 0;
-  NPTS = 1;
 
   if ((image = LoadImages (&Nimage)) == NULL) goto escape;
Index: trunk/Ohana/src/opihi/dvo/imlist.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/imlist.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/imlist.c	(revision 27435)
@@ -3,5 +3,6 @@
 int imlist (int argc, char **argv) {
   
-  int i, j, N, Nimage, *subset, Nsubset, TimeSelect, RegionSelect, TimeFormat, NameSelect;
+  off_t i, j, Nimage, *subset, Nsubset;
+  int N, TimeSelect, RegionSelect, TimeFormat, NameSelect;
   int PhotcodeSelect;
   time_t tzero, TimeReference;
@@ -103,6 +104,6 @@
       XY_to_RD (&r, &d, 0.5*image[i].NX, 0.5*image[i].NY, &image[i].coords);
     }
-    gprint (GP_LOG, "%3d %s %8.4f %8.4f %f %5d %2d %4.2f %5.3f %5.3f\n", 
-	     i, image[i].name, r, d, t, image[i].nstar, image[i].photcode, image[i].secz, image[i].Mcal, image[i].dMcal);
+    gprint (GP_LOG, "%3lld %s %8.4f %8.4f %f %5d %2d %4.2f %5.3f %5.3f\n", 
+	    (long long) i, image[i].name, r, d, t, image[i].nstar, image[i].photcode, image[i].secz, image[i].Mcal, image[i].dMcal);
   }
 
Index: trunk/Ohana/src/opihi/dvo/imphot.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/imphot.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/imphot.c	(revision 27435)
@@ -6,5 +6,5 @@
   double trange;
   int N, GreyScale;
-  int i, j, Nimage, Nsubset, *subset;
+  off_t i, j, Nimage, Nsubset, *subset;
   char bufname[64];
   float *p;
Index: trunk/Ohana/src/opihi/dvo/imrough.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/imrough.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/imrough.c	(revision 27435)
@@ -1,4 +1,4 @@
 # include "dvoshell.h"
-RegImage *load_imreg (char *DataBase, int *nimage);
+RegImage *load_imreg (char *DataBase, off_t *nimage);
 
 # define NVALUE 22
@@ -8,5 +8,6 @@
 int imrough (int argc, char **argv) {
  
-  int i, N, Nimage, TimeSelect;
+  off_t i, Nimage;
+  int N, TimeSelect;
   int ModeSelect, TypeSelect, CCDSelect, FilterSelect, TimeFormat;
   int type, value, mode, CCD, NVEC;
@@ -231,7 +232,8 @@
 }
 
-RegImage *load_imreg (char *DataBase, int *nimage) {
-
-  int Nimage, status;
+RegImage *load_imreg (char *DataBase, off_t *nimage) {
+
+  off_t Nimage;
+  int status;
   char line[80];
   FILE *f;
@@ -262,8 +264,8 @@
   if (!strcmp (line, "MDM Observatory")) {
 
-    fseek (f, header.size, SEEK_SET);
+    fseeko (f, header.datasize, SEEK_SET);
     
     /* load existing data from database */
-    gfits_scan (&header, "NIMAGES", "%d", 1, &Nimage);
+    gfits_scan (&header, "NIMAGES", "%lld", 1, (long long *) &Nimage);
     ALLOCATE (image, RegImage, Nimage);
     status = fread (image, sizeof(RegImage), Nimage, f);
@@ -271,5 +273,5 @@
     
     if (status != Nimage) {
-      gprint (GP_ERR, "ERROR: header and data in dB don't match (%d vs %d)\n", Nimage, status);
+      gprint (GP_ERR, "ERROR: header and data in dB don't match (%lld vs %d)\n", (long long) Nimage, status);
       gfits_free_header (&header);
       free (image);
@@ -302,5 +304,5 @@
   /* convert to internal format */
   image = (RegImage *) table.buffer;
-  gfits_scan (table.header, "NAXIS2", "%d", 1, &Nimage);
+  gfits_scan (table.header, "NAXIS2", "%lld", 1, (long long *) &Nimage);
   gfits_convert_RegImage (image, sizeof (RegImage), Nimage);
 
Index: trunk/Ohana/src/opihi/dvo/imsearch.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/imsearch.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/imsearch.c	(revision 27435)
@@ -7,5 +7,6 @@
   Header header;
   RegImage *pimage;
-  int i, Nimage, status, N, TimeSelect, SaveNames;
+  off_t i, Nimage, status;
+  int N, TimeSelect, SaveNames;
   int ModeSelect, TypeSelect, CCDSelect, FilterSelect;
   char *Filter, *obstime;
@@ -102,13 +103,13 @@
     return (FALSE);
   }
-  fseek (f, header.size, SEEK_SET);
+  fseeko (f, header.datasize, SEEK_SET);
 
   /* load existing data from database */
-  gfits_scan (&header, "NIMAGES", "%d", 1, &Nimage);
+  gfits_scan (&header, "NIMAGES", "%lld", 1, (long long *) &Nimage);
   ALLOCATE (pimage, RegImage, Nimage);
   status = fread (pimage, sizeof(RegImage), Nimage, f);
   fclose (f);
   if (status != Nimage) {
-    gprint (GP_ERR, "ERROR: header and data in dB don't match (%d vs %d)\n", Nimage, status);
+    gprint (GP_ERR, "ERROR: header and data in dB don't match (%lld vs %lld)\n", (long long) Nimage, (long long) status);
     gfits_free_header (&header);
     free (pimage);
@@ -130,5 +131,5 @@
     obstime[strlen(obstime)-1] = 0;
 
-    gprint (GP_LOG, "%5d %6s %6s %2d %2d   ", i, get_type_name(pimage[i].type), get_mode_name(pimage[i].mode), pimage[i].ccd, pimage[i].type);
+    gprint (GP_LOG, "%5lld %6s %6s %2d %2d   ", (long long) i, get_type_name(pimage[i].type), get_mode_name(pimage[i].mode), pimage[i].ccd, pimage[i].type);
     gprint (GP_LOG, "%s %s  ", pimage[i].pathname, pimage[i].filename);
     gprint (GP_LOG, "%s %s %f %s\n", pimage[i].filter, pimage[i].instrument, pimage[i].exptime, obstime);
Index: trunk/Ohana/src/opihi/dvo/imstats.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/imstats.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/imstats.c	(revision 27435)
@@ -3,5 +3,6 @@
 int imstats (int argc, char **argv) {
   
-  int i, kapa, Nimage, N;
+  off_t i, Nimage;
+  int kapa, N;
   int Mcal, AutoLimits;
   double r, d;
Index: trunk/Ohana/src/opihi/dvo/lcurve.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/lcurve.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/lcurve.c	(revision 27435)
@@ -7,6 +7,7 @@
   double *RA, *DEC;
   int kapa, TimeFormat;
-  int Nstars, found, AutoLimits, ErrorBars, GalMag, AbsPhot, SaveVectors;
-  int i, j, m, N, NPTS, *N1;
+  int found, AutoLimits, ErrorBars, GalMag, AbsPhot, SaveVectors;
+  off_t i, j, m, Nstars, *N1;
+  int N, NPTS;
   time_t TimeReference;
   struct tm *timeptr;
@@ -88,5 +89,5 @@
   ALLOCATE (RA, double, Nstars);
   ALLOCATE (DEC, double, Nstars);
-  ALLOCATE (N1, int, Nstars);
+  ALLOCATE (N1, off_t, Nstars);
 
   /* find star(s) in RA, DEC list -- use a dumb algorithm for now, improve later */
Index: trunk/Ohana/src/opihi/dvo/lightcurve.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/lightcurve.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/lightcurve.c	(revision 27435)
@@ -5,6 +5,7 @@
   double Ra, Dec, Radius, Radius2, r;
   double *RA, *DEC;
-  int Nstars, found, PhotCodeSelect;
-  int i, j, k, m, N, NPTS, Nsecfilt, RELPHOT, *N1, TimeFormat;
+  off_t i, j, k, m, Nstars, *N1;
+  int found, PhotCodeSelect;
+  int N, NPTS, Nsecfilt, RELPHOT, TimeFormat;
   time_t TimeReference;
 
@@ -71,5 +72,5 @@
   ALLOCATE (RA, double, Nstars);
   ALLOCATE (DEC, double, Nstars);
-  ALLOCATE (N1, int, Nstars);
+  ALLOCATE (N1, off_t, Nstars);
 
   /* find star(s) in RA, DEC list -- use a dumb algorithm for now, improve later */
Index: trunk/Ohana/src/opihi/dvo/match_image.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/match_image.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/match_image.c	(revision 27435)
@@ -1,7 +1,7 @@
 # include "dvoshell.h"
 
-int match_image (Image *image, int Nimage, unsigned int T, short int S) {
+off_t match_image (Image *image, off_t Nimage, unsigned int T, short int S) {
 
-  int N, Nlo, Nhi, N1, N2;
+  off_t N, Nlo, Nhi, N1, N2;
 
   /* bracket first value of interest */
@@ -37,7 +37,7 @@
 }
 
-int match_image_subset (Image *image, int *subset, int Nsubset, unsigned int T, short int S) {
+off_t match_image_subset (Image *image, off_t *subset, off_t Nsubset, unsigned int T, short int S) {
 
-  int N, Nlo, Nhi, N1, N2;
+  off_t N, Nlo, Nhi, N1, N2;
 
   /* bracket first value of interest */
Index: trunk/Ohana/src/opihi/dvo/mextract.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/mextract.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/mextract.c	(revision 27435)
@@ -3,5 +3,6 @@
 int mextract (int argc, char **argv) {
   
-  int i, j, k, m, n, N, Npts, NPTS, last, next, state, Nfields, Nreturn, Ncstack, Nstack;
+  off_t i, j, k, m; // used for counter averages and measures
+  int n, N, Npts, NPTS, last, next, state, Nfields, Nreturn, Ncstack, Nstack;
   int Nsecfilt, VERBOSE, loadImages, mosaicMode;
   char **cstack, name[1024];
@@ -119,5 +120,5 @@
     catalog.Nsecfilt = Nsecfilt;
 
-    if (VERBOSE) gprint (GP_ERR, "trying %s (%d of %d)\n", catalog.filename, i, skylist[0].Nregions);
+    if (VERBOSE) gprint (GP_ERR, "trying %s (%lld of %lld)\n", catalog.filename, (long long) i, (long long) skylist[0].Nregions);
       
     // an error exit status here is a significant error
Index: trunk/Ohana/src/opihi/dvo/mmextract.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/mmextract.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/mmextract.c	(revision 27435)
@@ -3,5 +3,6 @@
 int mmextract (int argc, char **argv) {
   
-  int i, j, k, m, n, N, Npts, NPTS, last, next, state;
+  off_t i, j, k, m;
+  int n, N, Npts, NPTS, last, next, state;
   int Nfields, Nreturn, Nreturn_base, Ncstack1, Ncstack2, Nstack1, Nstack2;
   int Nwhere, Iwhere, Nmatch, Imatch, NTABLE, Nt1, Nt2, n1, n2;
@@ -185,5 +186,5 @@
     catalog.Nsecfilt = Nsecfilt;
 
-    if (VERBOSE) gprint (GP_ERR, "trying %s (%d of %d)\n", catalog.filename, i, skylist[0].Nregions);
+    if (VERBOSE) gprint (GP_ERR, "trying %s (%lld of %lld)\n", catalog.filename, (long long) i, (long long) skylist[0].Nregions);
       
     // an error exit status here is a significant error
Index: trunk/Ohana/src/opihi/dvo/paverage.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/paverage.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/paverage.c	(revision 27435)
@@ -5,5 +5,6 @@
   
   FILE *f;
-  int i, j, kapa, Narg, Npts, NPTS, status, VERBOSE;
+  off_t i, j;
+  int kapa, Narg, Npts, NPTS, status, VERBOSE;
   int Nsecfilt, Nsec, Nloaded;
   double Mz, Mr, mag;
Index: trunk/Ohana/src/opihi/dvo/photometry.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/photometry.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/photometry.c	(revision 27435)
@@ -336,5 +336,5 @@
 int ListPhotSelections () {
 
-  gprint (GP_ERR, "TimeSelect: %d, %d - %d\n",      TimeSelect, tzero, tend);
+  gprint (GP_ERR, "TimeSelect: %d, %s - %s\n",      TimeSelect, ctime(&tzero), ctime(&tend));
   gprint (GP_ERR, "MagSelect: %d, %f - %f\n",       MagSelect, MagMax, MagMin);
   gprint (GP_ERR, "TypeSelect: %d, %d\n",           TypeSelect, TypeValue);
@@ -555,7 +555,7 @@
 
 /* extract a list of measure parameters from the specified average entry based on the pre-set selections */
-double *ExtractMeasures (PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist, int param) {
-
-  int i, Nlist, NLIST;
+double *ExtractMeasures (PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, off_t *nlist, int param) {
+
+  off_t i, Nlist, NLIST;
   double M, *list;
   
@@ -585,5 +585,5 @@
 double ExtractAverages (PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, int param) {
 
-  int i;
+  off_t i;
   double value;
 
@@ -714,5 +714,6 @@
 
   double frac;
-  int k, Nc, Nt;
+  int Nc, Nt;
+  off_t k;
   
   Nt = Nc = 0;
@@ -730,5 +731,6 @@
 int DetermineTypeCode (Average *average, Measure *measure, int code) {
 
-  int k, N, Nt[3];
+  off_t k;
+  int N, Nt[3];
   
   Nt[0] = Nt[1] = Nt[2] = 0;
@@ -788,5 +790,6 @@
 int TestAverage (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure) {
 
-  int i, Nm, Type, Select;
+  off_t i, Nm;
+  int Type, Select;
   double fwhm, typefrac, dM, Xm;
 
@@ -937,8 +940,8 @@
 
 
-double *ExtractMagnitudes (PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, int *n) {
+double *ExtractMagnitudes (PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, off_t *n) {
   
   double *M, mag;
-  int N;
+  off_t N;
 
   if ((mode == MAG_AVE) || (mode == MAG_REF)) {
@@ -960,7 +963,8 @@
 
 /* extract delta-mag pairs applying specified selections */
-double *ExtractDMag (PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist) {
-
-  int i, j, A1, A2, N1, N2, Np, Nlist, NLIST;
+double *ExtractDMag (PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, off_t *nlist) {
+
+  int A1, A2;
+  off_t i, j, N1, N2, Np, Nlist, NLIST;
   double *M1, *M2, *list;
 
@@ -1009,7 +1013,8 @@
 /* extract a list of delta-measure-mags from the specified average entry based on the 
    pre-set selections - does not return self-matched measurements */
-double *ExtractMeasuresDMag (PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist) {
-
-  int i, j, Np0, Np1, Nlist, NLIST;
+double *ExtractMeasuresDMag (PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, off_t *nlist) {
+
+  int Np0, Np1;
+  off_t i, j, Nlist, NLIST;
   double *list, M1, M2;
   
@@ -1056,7 +1061,8 @@
 
 /* extract a measurement list matching the number of dmag entries */
-double *ExtractByDMag (PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist, int param) {
-
-  int A1, A2, N1;
+double *ExtractByDMag (PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, off_t *nlist, int param) {
+
+  off_t N1;
+  int A1, A2;
   double *list;
 
@@ -1080,7 +1086,7 @@
   
 /* extract a list of delta-measure-mags from the specified average entry based on the pre-set selections */
-double *ExtractMeasuresByDMag (PhotCode **code, int *mode, int use_first, Average *average, SecFilt *secfilt, Measure *measure, int *nlist, int param) {
-
-  int i, j, n, Nlist, NLIST;
+double *ExtractMeasuresByDMag (PhotCode **code, int *mode, int use_first, Average *average, SecFilt *secfilt, Measure *measure, off_t *nlist, int param) {
+
+  off_t i, j, n, Nlist, NLIST;
   double *list, M1, M2;
   
Index: trunk/Ohana/src/opihi/dvo/pmeasure.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/pmeasure.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/pmeasure.c	(revision 27435)
@@ -7,5 +7,6 @@
   
   FILE *f;
-  int i, j, k, m, kapa, Narg, Npts, NPTS, status, VERBOSE, TimeSelect, Nloaded;
+  off_t i, j, k, m;
+  int kapa, Narg, Npts, NPTS, status, VERBOSE, TimeSelect, Nloaded;
   double Mz, Mr, mag;
   double Radius, Rmin, Rmax, R, D, trange;
Index: trunk/Ohana/src/opihi/dvo/simage.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/simage.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/simage.c	(revision 27435)
@@ -89,5 +89,5 @@
     return (FALSE);
   }
-  fseek (f, header.size, SEEK_SET); 
+  fseeko (f, header.datasize, SEEK_SET); 
 
   /* set up storage buffers */
Index: trunk/Ohana/src/opihi/dvo/skycoverage.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/skycoverage.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/skycoverage.c	(revision 27435)
@@ -6,5 +6,6 @@
 
   int WITH_MOSAIC, SOLO_MOSAIC;
-  int i, N, Nimage, status, TimeSelect, ByName, xs, ys;
+  off_t i, Nimage;
+  int N, status, TimeSelect, ByName, xs, ys;
   time_t tzero, tend;
   double pixscale, dX, dY, Npts, r, d, Xi, Yi, Xs, Ys, x[2], y[2], trange, RaCenter, DecCenter;
Index: trunk/Ohana/src/opihi/dvo/subpix.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/subpix.c	(revision 27392)
+++ trunk/Ohana/src/opihi/dvo/subpix.c	(revision 27435)
@@ -3,8 +3,8 @@
 int subpix (int argc, char **argv) {
   
-  int i, j, I, Nlo, Nhi, Nentry, Nstars, Nimage, Nmeasure;
-  int *index, *entry;
-  int Nmin, Nsub, NSUB, status;
-  int TimeFormat;
+  off_t Nlo, Nhi, *entry, Nentry;
+  off_t j, i, I, *index, Nstars, Nimage, Nmeasure;
+  off_t Nmin, Nsub, NSUB;
+  int status, TimeFormat;
   time_t Timage, TimeReference;
   double X, Y, Mabs, t;
@@ -54,5 +54,5 @@
   ALLOCATE (RA, double, Nstars);
   ALLOCATE (DEC, double, Nstars);
-  ALLOCATE (index, int, Nstars);
+  ALLOCATE (index, off_t, Nstars);
   for (i = 0; i < Nstars; i++) {
     RA[i] = catalog.average[i].R;
@@ -65,5 +65,5 @@
   Nlo = bracket (DEC, Nstars, FALSE, Dec - Radius);
   Nhi = bracket (DEC, Nstars, TRUE,  Dec + Radius);
-  ALLOCATE (entry, int, MAX (Nhi - Nlo, 1));
+  ALLOCATE (entry, off_t, MAX (Nhi - Nlo, 1));
   Nentry = 0;
 
@@ -111,5 +111,5 @@
   Nsub = 0;
   NSUB = 100;
-  ALLOCATE (index, int, NSUB);
+  ALLOCATE (index, off_t, NSUB);
 
   /* load all images, extract those touching Ra, Dec */
@@ -125,5 +125,5 @@
     if (Nsub == NSUB - 1) {
       NSUB += 100;
-      REALLOCATE (index, int, NSUB);
+      REALLOCATE (index, off_t, NSUB);
     }
   }
Index: trunk/Ohana/src/opihi/include/data.h
===================================================================
--- trunk/Ohana/src/opihi/include/data.h	(revision 27392)
+++ trunk/Ohana/src/opihi/include/data.h	(revision 27435)
@@ -77,5 +77,5 @@
 /* in fft.c */
 void fft1D (float *dataRe, float *dataIm, int N, int Nbit, int forward);
-int fftND (float *dataRe, float *dataIm, int Ndim, int *Nsize, int forward);
+int fftND (float *dataRe, float *dataIm, int Ndim, off_t *Nsize, int forward);
 void dfft1D (double *dataRe, double *dataIm, int N, int Nbit, int forward);
 int dfftND (double *dataRe, double *dataIm, int Ndim, int *Nsize, int forward);
Index: trunk/Ohana/src/opihi/include/display.h
===================================================================
--- trunk/Ohana/src/opihi/include/display.h	(revision 27392)
+++ trunk/Ohana/src/opihi/include/display.h	(revision 27435)
@@ -36,6 +36,6 @@
 int SendLabel (char *string, int Xgraph, int mode);
 
-int SendGraphMessage (int device, char *format, ...);
-int SendGraphCommand (int device, int length, char *format, ...);
+int SendGraphMessage (int device, char *format, ...) OHANA_FORMAT(printf, 2, 3);
+int SendGraphCommand (int device, int length, char *format, ...) OHANA_FORMAT(printf, 3, 4);
 int SendGraphCommandV (int device, int length, char *format, va_list argp);
 
Index: trunk/Ohana/src/opihi/include/dvoshell.h
===================================================================
--- trunk/Ohana/src/opihi/include/dvoshell.h	(revision 27392)
+++ trunk/Ohana/src/opihi/include/dvoshell.h	(revision 27435)
@@ -260,10 +260,10 @@
 double        DetermineTypefrac     PROTO((Average *average, Measure *measure, PhotCode *code));
 double        ExtractAverages       PROTO((PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, int param));
-double       *ExtractByDMag         PROTO((PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist, int param));
-double       *ExtractDMag           PROTO((PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist));
-double       *ExtractMagnitudes     PROTO((PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, int *n));
-double       *ExtractMeasures       PROTO((PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist, int param));
-double       *ExtractMeasuresByDMag PROTO((PhotCode **code, int *mode, int use_first, Average *average, SecFilt *secfilt, Measure *measure, int *nlist, int param));
-double       *ExtractMeasuresDMag   PROTO((PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist));
+double       *ExtractByDMag         PROTO((PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, off_t *nlist, int param));
+double       *ExtractDMag           PROTO((PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, off_t *nlist));
+double       *ExtractMagnitudes     PROTO((PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, off_t *n));
+double       *ExtractMeasures       PROTO((PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, off_t *nlist, int param));
+double       *ExtractMeasuresByDMag PROTO((PhotCode **code, int *mode, int use_first, Average *average, SecFilt *secfilt, Measure *measure, off_t *nlist, int param));
+double       *ExtractMeasuresDMag   PROTO((PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, off_t *nlist));
 void          FreeImageSelection    PROTO((void));
 void          FreeImageSelection    PROTO((void));
@@ -280,5 +280,5 @@
 void          FreeDVO               PROTO((void));
 int           InitPhotcodes         PROTO((void));
-Image        *LoadImages            PROTO((int *Nimage));
+Image        *LoadImages            PROTO((off_t *Nimage));
 Image        *MatchImage            PROTO((unsigned int time, short int source));
 Coords       *MatchMosaic           PROTO((unsigned int time, short int source));
@@ -300,14 +300,11 @@
 int           TestPhotSelections    PROTO((PhotCode **code, int *mode, int param));
 void          compare               PROTO((Catalog *catlog1, Catalog *catlog2, Vector *rvec,  Vector *dvec,  Vector *mvec, Vector *drvec, Vector *ddvec, Vector *dmvec, double radius));
-void          cprecess              PROTO((Average *average, int Naverage, double in_epoch, double out_epoch));
-void          image_subset          PROTO((Image *image, int Nimage, int **Subset, int *Nsubset, SkyRegionSelection *selection, unsigned long int tzero, double trange, int TimeSelect));
-int           match_image           PROTO((Image *image, int Nimage, unsigned int T, short int S));
-int           match_image_subset    PROTO((Image *image, int *subset, int Nsubset, unsigned int T, short int S));
+void          cprecess              PROTO((Average *average, off_t Naverage, double in_epoch, double out_epoch));
+void          image_subset          PROTO((Image *image, off_t Nimage, off_t **Subset, off_t *Nsubset, SkyRegionSelection *selection, unsigned long int tzero, double trange, int TimeSelect));
+off_t         match_image           PROTO((Image *image, off_t Nimage, unsigned int T, short int S));
+off_t         match_image_subset    PROTO((Image *image, off_t *subset, off_t Nsubset, unsigned int T, short int S));
 void          print_value           PROTO((double value, short int ival));
-void          sort_image_subset     PROTO((Image *image, int *subset, int N));
-void          sort_images           PROTO((Image *image, int N));
-void          sortave               PROTO((Average *ave, int N));
-CMPstars     *cmpReadFits           PROTO((FILE *f, int *nstars));
-CMPstars     *cmpReadText           PROTO((FILE *f, int *nstars));
+CMPstars     *cmpReadFits           PROTO((FILE *f, off_t *nstars));
+CMPstars     *cmpReadText           PROTO((FILE *f, off_t *nstars));
 int           RD_to_XYpic           PROTO((double *x, double *y, double r, double d, Coords *coords, double Rmin, double Rmax, double Rmid, int *leftside));
 
@@ -334,5 +331,5 @@
 dbValue      dbExtractAverages      PROTO((Average *average, SecFilt *secfilt, Measure *measure, dbField *field));
 dbValue      dbExtractMeasures      PROTO((Average *average, SecFilt *secfilt, Measure *measure, dbField *field));
-dbValue      dbExtractImages        PROTO((Image *image, int Nimage, int N, dbField *field));
+dbValue      dbExtractImages        PROTO((Image *image, off_t Nimage, off_t N, dbField *field));
 
 void 	     dbInitField            PROTO((dbField *field));
Index: trunk/Ohana/src/opihi/include/pantasks.h
===================================================================
--- trunk/Ohana/src/opihi/include/pantasks.h	(revision 27392)
+++ trunk/Ohana/src/opihi/include/pantasks.h	(revision 27435)
@@ -269,7 +269,4 @@
 int CheckJobsGetState (void);
 
-// void *CheckTasksThread (void *data);
-// void *CheckJobsThread (void *data);
-
 void CheckControllerSetState (int state);
 int CheckControllerGetState (void);
@@ -287,12 +284,12 @@
 void CheckInputs (void);
 
-void ClientThreadLock (void);
-void ClientThreadUnlock (void);
-void CommandThreadLock (void);
-void CommandThreadUnlock (void);
-void ControlThreadLock (void);
-void ControlThreadUnlock (void);
-void JobTaskThreadLock (void);
-void JobTaskThreadUnlock (void);
+void ClientLock (void);
+void ClientUnlock (void);
+void CommandLock (void);
+void CommandUnlock (void);
+void ControlLock (const char *func);
+void ControlUnlock (const char *func);
+void JobTaskLock (void);
+void JobTaskUnlock (void);
 
 int InitPassword (void);
Index: trunk/Ohana/src/opihi/include/shell.h
===================================================================
--- trunk/Ohana/src/opihi/include/shell.h	(revision 27392)
+++ trunk/Ohana/src/opihi/include/shell.h	(revision 27435)
@@ -153,5 +153,5 @@
 
 char 	     *memstr        		PROTO((char *m1, char *m2, int n));
-int  	      write_fmt     		PROTO((int fd, char *format, ...));
+int  	      write_fmt     		PROTO((int fd, char *format, ...)) OHANA_FORMAT(printf, 2, 3);
 char 	     *opihi_version 		PROTO((void));
 char 	     *strip_version 		PROTO((char *input));
@@ -167,7 +167,7 @@
 FILE         *gprintGetFile   		PROTO((gpDest dest));
 char         *gprintGetName   		PROTO((gpDest dest));
-int           gprint          		PROTO((gpDest dest, char *format, ...));
+int           gprint          		PROTO((gpDest dest, char *format, ...)) OHANA_FORMAT(printf, 2, 3);
 int           gwrite          		PROTO((char *buffer, int size, int N, gpDest dest));
-int           gprint_syserror           PROTO((gpDest dest, int myError, char *format, ...));
+int           gprint_syserror           PROTO((gpDest dest, int myError, char *format, ...)) OHANA_FORMAT(printf, 3, 4);
 int           gprintv                   PROTO((gpDest dest, char *format, va_list argp));
 
Index: trunk/Ohana/src/opihi/lib.data/fft.c
===================================================================
--- trunk/Ohana/src/opihi/lib.data/fft.c	(revision 27392)
+++ trunk/Ohana/src/opihi/lib.data/fft.c	(revision 27435)
@@ -72,5 +72,5 @@
 // This requires 2(Nx*Ny*...) mem copies, but the fft operations are likely to happen in
 // cache.
-int fftND (float *x, float *y, int Ndim, int *Nsize, int forward) {
+int fftND (float *x, float *y, int Ndim, off_t *Nsize, int forward) {
 
   int i, nIndex, minor, major, iDim;
Index: trunk/Ohana/src/opihi/lib.shell/BufferOps.c
===================================================================
--- trunk/Ohana/src/opihi/lib.shell/BufferOps.c	(revision 27392)
+++ trunk/Ohana/src/opihi/lib.shell/BufferOps.c	(revision 27435)
@@ -83,5 +83,5 @@
   return (buffers[i]);
 
- error:
+error:
   if (verbose) gprint (GP_ERR, "invalid matrix %s\n", name);
   return (NULL);
@@ -238,9 +238,9 @@
     gprint (GP_LOG, "    N       name                      file     X     Y    bytes BP  U   bzero     bscale  \n");
     for (i = 0; i < Nbuffers; i++) {
-      gprint (GP_LOG, "%5d %10s %25s %5d %5d %10d %3d %1d %10.4e %10.4e\n",
-	       i, buffers[i][0].name, buffers[i][0].file, 
-	       buffers[i][0].header.Naxis[0], buffers[i][0].header.Naxis[1],
-	       buffers[i][0].header.size + buffers[i][0].matrix.size, buffers[i][0].bitpix, 
-	       buffers[i][0].unsign, buffers[i][0].bzero, buffers[i][0].bscale);
+      gprint (GP_LOG, "%5d %10s %25s %5lld %5lld %10lld %3d %1d %10.4e %10.4e\n",
+	      i, buffers[i][0].name, buffers[i][0].file, 
+	      (long long) buffers[i][0].header.Naxis[0], (long long) buffers[i][0].header.Naxis[1],
+ 	      (long long) buffers[i][0].header.datasize + buffers[i][0].matrix.datasize, buffers[i][0].bitpix, 
+	      buffers[i][0].unsign, buffers[i][0].bzero, buffers[i][0].bscale);
     }
     return (TRUE);
@@ -249,9 +249,9 @@
   gprint (GP_LOG, "    N       name                      file     X     Y    bytes\n");
   for (i = 0; i < Nbuffers; i++) {
-    gprint (GP_LOG, "%5d %10s %25s %5d %5d %10d\n",
-	     i, buffers[i][0].name, buffers[i][0].file, 
-	     buffers[i][0].header.Naxis[0], buffers[i][0].header.Naxis[1],
-	     buffers[i][0].header.size + buffers[i][0].matrix.size);
-  }
-  return (TRUE);
-}
+    gprint (GP_LOG, "%5d %10s %25s %5lld %5lld %10lld\n",
+	    i, buffers[i][0].name, buffers[i][0].file, 
+	    (long long) buffers[i][0].header.Naxis[0], (long long) buffers[i][0].header.Naxis[1],
+	    (long long) buffers[i][0].header.datasize + buffers[i][0].matrix.datasize);
+  }
+  return (TRUE);
+}
Index: trunk/Ohana/src/opihi/lib.shell/gprint.c
===================================================================
--- trunk/Ohana/src/opihi/lib.shell/gprint.c	(revision 27392)
+++ trunk/Ohana/src/opihi/lib.shell/gprint.c	(revision 27435)
@@ -352,8 +352,8 @@
   // there are two strerror_r implementations; choose the right one:
 #if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE)
-  errorMsg = strerror_r (myError, errorBuf, MAX_ERROR_LENGTH);
-#else
   strerror_r (myError, errorBuf, MAX_ERROR_LENGTH);
   errorMsg = errorBuf;
+#else
+  errorMsg = strerror_r (myError, errorBuf, MAX_ERROR_LENGTH);
 #endif
 
@@ -362,5 +362,5 @@
   va_end (argp);
 
-  gprintv (dest, "%s\n", errorMsg);
+  gprint (dest, "%s\n", errorMsg);
   return TRUE;
 }
Index: trunk/Ohana/src/opihi/lib.shell/multicommand.c
===================================================================
--- trunk/Ohana/src/opihi/lib.shell/multicommand.c	(revision 27392)
+++ trunk/Ohana/src/opihi/lib.shell/multicommand.c	(revision 27435)
@@ -32,5 +32,5 @@
   /* here we can perform the security handshaking */
   VarConfig ("PASSWORD", "%s", PASSWORD);
-  SendCommand (server, strlen(PASSWORD), PASSWORD);
+  SendCommand (server, strlen(PASSWORD), "%s", PASSWORD);
   
   return;
@@ -82,5 +82,5 @@
 	if (server) {
 	  // send the command to the server instead
-	  if (!SendMessage (server, outline)) {
+	  if (!SendMessage (server, "%s", outline)) {
 	    switch (errno) {
 	      case EPIPE:
Index: trunk/Ohana/src/opihi/lib.shell/stack_math.c
===================================================================
--- trunk/Ohana/src/opihi/lib.shell/stack_math.c	(revision 27392)
+++ trunk/Ohana/src/opihi/lib.shell/stack_math.c	(revision 27435)
@@ -1135,13 +1135,13 @@
   /* copy all but the matrix */
 
-  matrix2[0].unsign = matrix1[0].unsign;
-  matrix2[0].bitpix = matrix1[0].bitpix;
-  matrix2[0].size   = matrix1[0].size;
-  matrix2[0].bzero  = matrix1[0].bzero;
-  matrix2[0].bscale = matrix1[0].bscale;
-  matrix2[0].Naxes  = matrix1[0].Naxes;
-  for (i = 0; i < FT_MAX_NAXES; i++) 
+  matrix2[0].unsign   = matrix1[0].unsign;
+  matrix2[0].bitpix   = matrix1[0].bitpix;
+  matrix2[0].datasize = matrix1[0].datasize;
+  matrix2[0].bzero    = matrix1[0].bzero;
+  matrix2[0].bscale   = matrix1[0].bscale;
+  matrix2[0].Naxes    = matrix1[0].Naxes;
+  for (i = 0; i < FT_MAX_NAXES; i++) {
     matrix2[0].Naxis[i] = matrix1[0].Naxis[i];
-
+  }
 
   return (TRUE);
Index: trunk/Ohana/src/opihi/pantasks/JobOps.c
===================================================================
--- trunk/Ohana/src/opihi/pantasks/JobOps.c	(revision 27392)
+++ trunk/Ohana/src/opihi/pantasks/JobOps.c	(revision 27435)
@@ -73,7 +73,4 @@
 
   int i;
-  int status;
-  char command[1024];
-  IOBuffer buffer;
 
   gprint (GP_LOG, "\n");
Index: trunk/Ohana/src/opihi/pantasks/ListenClients.c
===================================================================
--- trunk/Ohana/src/opihi/pantasks/ListenClients.c	(revision 27392)
+++ trunk/Ohana/src/opihi/pantasks/ListenClients.c	(revision 27435)
@@ -70,5 +70,5 @@
   
   int i, Ncurrent, Nmax, status, Nread;
-  char *line, log_stdout[128], log_stderr[128];
+  char *line;
   fd_set fdSet;
   struct timeval timeout;
Index: trunk/Ohana/src/opihi/pantasks/status_server.c
===================================================================
--- trunk/Ohana/src/opihi/pantasks/status_server.c	(revision 27392)
+++ trunk/Ohana/src/opihi/pantasks/status_server.c	(revision 27435)
@@ -1,3 +1,5 @@
 # include "pantasks.h"
+
+int status_scheduler(void);
 
 int status_server (int argc, char **argv) {
@@ -103,5 +105,5 @@
 }
 
-int status_scheduler() {
+int status_scheduler(void) {
   
   gprint (GP_LOG, "\n");
Index: trunk/Ohana/src/opihi/pantasks/thread_locks.c
===================================================================
--- trunk/Ohana/src/opihi/pantasks/thread_locks.c	(revision 27392)
+++ trunk/Ohana/src/opihi/pantasks/thread_locks.c	(revision 27435)
@@ -4,9 +4,9 @@
 static pthread_mutex_t ClientMutex = PTHREAD_MUTEX_INITIALIZER;
 
-void ClientLock () {
+void ClientLock (void) {
   pthread_mutex_lock (&ClientMutex);
 }
 
-void ClientUnlock () {
+void ClientUnlock (void) {
   pthread_mutex_unlock (&ClientMutex);
 }
@@ -15,10 +15,10 @@
 static pthread_mutex_t CommandMutex = PTHREAD_MUTEX_INITIALIZER;
 
-void CommandLock () {
+void CommandLock (void) {
   //  fprintf (stderr, "command lock\n");
   pthread_mutex_lock (&CommandMutex);
 }
 
-void CommandUnlock () {
+void CommandUnlock (void) {
   //  fprintf (stderr, "command unlock\n");
   pthread_mutex_unlock (&CommandMutex);
@@ -28,10 +28,10 @@
 static pthread_mutex_t ControlMutex = PTHREAD_MUTEX_INITIALIZER;
 
-void ControlLock (char *func) {
+void ControlLock (const char *func) {
   // fprintf (stderr, "control lock %s\n", func);
   pthread_mutex_lock (&ControlMutex);
 }
 
-void ControlUnlock (char *func) {
+void ControlUnlock (const char *func) {
   // fprintf (stderr, "control unlock %s\n", func);
   pthread_mutex_unlock (&ControlMutex);
@@ -41,10 +41,10 @@
 static pthread_mutex_t JobTaskMutex = PTHREAD_MUTEX_INITIALIZER;
 
-void JobTaskLock () {
+void JobTaskLock (void) {
   //  fprintf (stderr, "jobtask lock\n");
   pthread_mutex_lock (&JobTaskMutex);
 }
 
-void JobTaskUnlock () {
+void JobTaskUnlock (void) {
   //  fprintf (stderr, "jobtask unlock\n");
   pthread_mutex_unlock (&JobTaskMutex);
Index: trunk/Ohana/src/opihi/pcontrol/PclientCommand.c
===================================================================
--- trunk/Ohana/src/opihi/pcontrol/PclientCommand.c	(revision 27392)
+++ trunk/Ohana/src/opihi/pcontrol/PclientCommand.c	(revision 27435)
@@ -63,5 +63,5 @@
   }
   if (status ==  0) {
-    gprint (GP_ERR, "pclient read returns 0 for %s\n", command);
+    gprint (GP_ERR, "pclient read returns 0 for %s\n", response);
     return (PCLIENT_DOWN);
   }
Index: trunk/Ohana/src/opihi/pcontrol/StartHost.c
===================================================================
--- trunk/Ohana/src/opihi/pcontrol/StartHost.c	(revision 27392)
+++ trunk/Ohana/src/opihi/pcontrol/StartHost.c	(revision 27435)
@@ -14,5 +14,5 @@
   if (VarConfig ("SHELL", "%s", shell)     == NULL) strcpy (shell, "pclient");
 
-  if (VerboseMode()) gprint (GP_ERR, "starting host within thread %d\n", pthread_self());
+  if (VerboseMode()) gprint (GP_ERR, "starting host within thread %lld\n", (long long) pthread_self());
 
   pid = rconnect (command, host[0].hostname, shell, stdio);
Index: trunk/Ohana/src/opihi/pcontrol/StopHosts.c
===================================================================
--- trunk/Ohana/src/opihi/pcontrol/StopHosts.c	(revision 27392)
+++ trunk/Ohana/src/opihi/pcontrol/StopHosts.c	(revision 27435)
@@ -121,5 +121,5 @@
   int i, result, waitstatus;
 
-  if (VerboseMode()) gprint (GP_ERR, "harvesting within thread %p\n", pthread_self());
+  if (VerboseMode()) gprint (GP_ERR, "harvesting within thread %lld\n", (long long) pthread_self());
   if (VerboseMode()) gprint (GP_ERR, "child process %d is down, wait for exit status\n", pid);
   
Index: trunk/Ohana/src/photdbc/include/photdbc.h
===================================================================
--- trunk/Ohana/src/photdbc/include/photdbc.h	(revision 27392)
+++ trunk/Ohana/src/photdbc/include/photdbc.h	(revision 27435)
@@ -104,5 +104,5 @@
 void          check_directory (char *basefile);
 
-int Shutdown (char *format, ...);
+int Shutdown (char *format, ...) OHANA_FORMAT(printf, 1, 2);
 void set_db (FITS_DB *in);
 void lock_image_db (FITS_DB *db, char *filename);
Index: trunk/Ohana/src/photdbc/src/join_stars.c
===================================================================
--- trunk/Ohana/src/photdbc/src/join_stars.c	(revision 27392)
+++ trunk/Ohana/src/photdbc/src/join_stars.c	(revision 27435)
@@ -3,10 +3,10 @@
 void join_stars (Catalog *catalog) {
 
-  int i, j, k, m, M, Ni, Nj, first_j;
-  int Naves, Nmeas, Ncurr;
-  int Naverage, Nmeasure, *found, *index;
+  off_t i, j, k, m, M, Ni, Nj, first_j, Nfirst;
+  off_t Naves, Nmeas, Ncurr;
+  off_t Naverage, Nmeasure, *index;
   double *X, *Y, dX, dY, dR, RADIUS2;
   double Sr, Sd, Rmid, Dmid;
-  int basecode, baseNsec, Nsecfilt, Nfirst;
+  int basecode, baseNsec, Nsecfilt, *found;
 
   Average *naverage, *average;
@@ -61,5 +61,5 @@
   ALLOCATE (X, double, Naverage);
   ALLOCATE (Y, double, Naverage);
-  ALLOCATE (index, int, Naverage);
+  ALLOCATE (index, off_t, Naverage);
   for (i = 0; i < Naverage; i++) {
     index[i] = i;
Index: trunk/Ohana/src/relastro/doc/notes.txt
===================================================================
--- trunk/Ohana/src/relastro/doc/notes.txt	(revision 27392)
+++ trunk/Ohana/src/relastro/doc/notes.txt	(revision 27435)
@@ -1,2 +1,61 @@
+
+2010.03.24
+
+  I have finished only part of the optimizations listed below: I have
+  made the detection->image and image->mosaic lookups use bracket
+  searches.  I have NOT converted the image->mosaic lookups to use the
+  parentID, so these matches are still based on time ranges.  I have
+  also added a bit of positional constraint to the image match
+  function in 'select_images' (comparing Rmax of the sky regions to
+  Rmin of the images).  These have had a huge improvement.  Here is
+  the execution time for the SAS data (~450 images) with the old vs
+  the new code on pikake:
+
+  old : 39min
+  new :  7min
+
+  The bulk of the time for the new code is now disk I/O.
+
+2010.03.23
+
+  I've been working on optimization.  I've updated ImageOps to make
+  the measure->image relationship generation use the image IDs along
+  with a bracket search -- this goes much faster as a result.  More
+  work is needed:
+
+  * select_images needs to apply astrometry to all image corners: 
+    -> cache the image center and radius and use this to narrow down
+       the searches.
+
+  * MosaicOps uses the time to match mosaics.  I've added sorting to
+    speed this up, but this should be done based on the image and
+    parent index.
+
+    -> make a tool to create the parent ID for existing DBs.
+    -> make sure addstar is populating the parent IDs
+    -> use the parent IDs to make the link.
+
+load image data: 0.006347 sec
+  setup sky: 0.091475 sec
+  convert image table: 0.091498 sec
+  select images: 2.925978 sec
+  init images: 2.926957 sec
+  init mosaics: 2.927319 sec
+load images: 2.933762 sec
+load catalog data: 9.772259 sec
+make image bins: 9.780618 sec
+set up image indexes: 10.196519 sec
+
+load image data: 0.006746 sec
+  setup sky: 0.091440 sec
+  convert image table: 0.091467 sec
+  select images: 0.374193 sec
+  init images: 0.375355 sec
+  init mosaics: 0.375753 sec
+load images: 0.382606 sec
+load catalog data: 7.260094 sec
+make image bins: 7.268564 sec
+set up image indexes: 7.687485 sec
+
 
 2008.03.01
Index: trunk/Ohana/src/relastro/include/relastro.h
===================================================================
--- trunk/Ohana/src/relastro/include/relastro.h	(revision 27392)
+++ trunk/Ohana/src/relastro/include/relastro.h	(revision 27435)
@@ -140,5 +140,5 @@
 char         *GetPhotnamebyCode   PROTO((PhotCodeData *photcodes, int code));
 void          InterpolateGrid     PROTO((float *buffer, int Nx, int Ny, Coords *ccd, Coords *gcoords));
-int          *SelectRefMosaic     PROTO((Mosaic **refmosaic, int *Nimage));
+off_t          *SelectRefMosaic     PROTO((Mosaic **refmosaic, off_t *Nimage));
 int           args                PROTO((int argc, char **argv));
 int           bcatalog            PROTO((Catalog *subcatalog, Catalog *catalog));
@@ -153,12 +153,12 @@
 void          findImages          PROTO((Catalog *catalog, int Ncatalog));
 int           findMosaics         PROTO((Catalog *catalog, int Ncatalog));
-Image        *find_images         PROTO((FITS_DB *db, GSCRegion *region, int Nregion, int *Nimage, int **LineNum));
+Image        *find_images         PROTO((FITS_DB *db, GSCRegion *region, off_t Nregion, off_t *Nimage, off_t **LineNum));
 void set_db (FITS_DB *in);
-int Shutdown (char *format, ...);
+int Shutdown (char *format, ...) OHANA_FORMAT(printf, 1, 2);
 void TrapSignal (int sig);
 void SetProtect (int mode);
 int SetSignals (void);
 
-GSCRegion    *find_regions        PROTO((Image *image, int Nimage, int *Nregions, GSCRegion *fullregion));
+GSCRegion    *find_regions        PROTO((Image *image, off_t Nimage, int *Nregions, GSCRegion *fullregion));
 void          freeGridBins        PROTO((int Ncatalog));
 void          freeImageBins       PROTO((int Ncatalog));
@@ -166,21 +166,21 @@
 void          free_catalogs       PROTO((Catalog *catalog, int Ncatalog));
 int           gcatalog            PROTO((Catalog *catalog, int FINAL));
-Coords       *getCoords           PROTO((int meas, int cat));
-float         getMcal             PROTO((int meas, int cat));
-float         getMgrid            PROTO((int meas, int cat));
-float         getMmos             PROTO((int meas, int cat));
-float         getMrel             PROTO((Catalog *catalog, int meas, int cat));
-GSCRegion    *get_regions         PROTO((double minRa, double maxRa, double minDec, double maxDec, int *Nregions));
-void          getfullregion       PROTO((Image *image, int Nimage, GSCRegion *fullregion));
-Image        *getimage            PROTO((int N));
-Image        *getimages           PROTO((int *N));
+Coords       *getCoords           PROTO((off_t meas, int cat));
+float         getMcal             PROTO((off_t meas, int cat));
+float         getMgrid            PROTO((off_t meas, int cat));
+float         getMmos             PROTO((off_t meas, int cat));
+float         getMrel             PROTO((Catalog *catalog, off_t meas, int cat));
+GSCRegion    *get_regions         PROTO((double minRa, double maxRa, double minDec, double maxDec, off_t *Nregions));
+void          getfullregion       PROTO((Image *image, off_t Nimage, GSCRegion *fullregion));
+Image        *getimage            PROTO((off_t N));
+Image        *getimages           PROTO((off_t *N));
 void          global_stats        PROTO((Catalog *catalog, int Ncatalog));
 void          initGrid            PROTO((int dX, int dY));
 void          initGridBins        PROTO((Catalog *catalog, int Ncatalog));
 void          initImageBins       PROTO((Catalog *catalog, int Ncatalog));
-void          initImages          PROTO((Image *input, int N));
+void          initImages          PROTO((Image *input, off_t N));
 void          initMosaicBins      PROTO((Catalog *catalog, int Ncatalog));
-void          initMosaicGrid      PROTO((Image *image, int Nimage));
-void          initMosaics         PROTO((Image *image, int Nimage));
+void          initMosaicGrid      PROTO((Image *image, off_t Nimage));
+void          initMosaics         PROTO((Image *image, off_t Nimage));
 void          initMrel            PROTO((Catalog *catalog, int Ncatalog));
 void          initialize          PROTO((int argc, char **argv));
@@ -189,5 +189,5 @@
 Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog, int subselect));
 SkyList      *load_images         PROTO((FITS_DB *db, SkyRegion *region));
-Image        *select_images       PROTO((SkyList *skylist, Image *timage, int Ntimage, int **LineNumber, int *Nimage));
+Image        *select_images       PROTO((SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage));
 
 void check_permissions (char *basefile);
@@ -198,8 +198,8 @@
 
 int           main                PROTO((int argc, char **argv));
-void          mark_images         PROTO((Image *image, int Nimage, Image *timage, int Ntimage));
-void          matchImage          PROTO((Catalog *catalog, int meas, int cat));
-void          matchMosaics        PROTO((Catalog *catalog, int meas, int cat));
-GSCRegion    *name_region         PROTO((char *name, int *Nregions));
+void          mark_images         PROTO((Image *image, off_t Nimage, Image *timage, off_t Ntimage));
+void          matchImage          PROTO((Catalog *catalog, off_t meas, int cat));
+void          matchMosaics        PROTO((Catalog *catalog, off_t meas, int cat));
+GSCRegion    *name_region         PROTO((char *name, off_t *Nregions));
 double        opening_angle       PROTO((double x1, double y1, double x2, double y2, double x3, double y3));
 void          plot_chisq          PROTO((Catalog *catalog, int Ncatalog));
@@ -224,5 +224,5 @@
 int           setMrelOutput       PROTO((Catalog *catalog, int Ncatalog, int mark));
 void          set_ZP              PROTO((double ZERO));
-int           setrefcode          PROTO((Image *image, int Nimage));
+int           setrefcode          PROTO((Image *image, off_t Nimage));
 void          skip_measurements   PROTO((Catalog *catalog, int pass));
 void          sortA               PROTO((double *X, int N));
@@ -268,5 +268,5 @@
 int UpdateMosaic (Catalog *catalog, int Ncatalog);
 int UpdateMeasures (Catalog *catalog, int Ncatalog);
-void fixImageRaw (Catalog *catalog, int Ncatalog, int im);
+void fixImageRaw (Catalog *catalog, int Ncatalog, off_t im);
 void FlagOutliers(Catalog *catalog);
 int MeasFilterTest(Measure *measure);
@@ -278,14 +278,14 @@
 int FitPMandPar (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *T, double *pR, double *pD, int Npts);
 
-Mosaic *getMosaicForImage (int N);
-
-StarData *getImageRef (Catalog *catalog, int Ncatalog, int im, int *Nstars, CoordMode mode);
-StarData *getImageRaw (Catalog *catalog, int Ncatalog, int im, int *Nstars, CoordMode mode);
-
-Mosaic *getmosaics (int *N);
-void initMosaics (Image *image, int Nimage);
-StarData *getMosaicRaw (Catalog *catalog, int Ncatalog, int mos, int *Nstars);
-StarData *getMosaicRef (Catalog *catalog, int Ncatalog, int mos, int *Nstars);
-Mosaic *getMosaicForImage (int im);
+Mosaic *getMosaicForImage (off_t N);
+
+StarData *getImageRef (Catalog *catalog, int Ncatalog, off_t im, off_t *Nstars, CoordMode mode);
+StarData *getImageRaw (Catalog *catalog, int Ncatalog, off_t im, off_t *Nstars, CoordMode mode);
+
+Mosaic *getmosaics (off_t *N);
+void initMosaics (Image *image, off_t Nimage);
+StarData *getMosaicRaw (Catalog *catalog, int Ncatalog, off_t mos, off_t *Nstars);
+StarData *getMosaicRef (Catalog *catalog, int Ncatalog, off_t mos, off_t *Nstars);
+Mosaic *getMosaicForImage (off_t im);
 
 double getMeanR (Measure *measure, Average *average, SecFilt *secfilt);
@@ -297,2 +297,8 @@
 int relastro_objects (void);
 int UpdateObjectOffsets (SkyList *skylist);
+
+int relastroVisualPlotRawRef(StarData *raw, StarData *ref, double dRmax, int numObj);
+int relastroVisualPlotScatter(double values[], double thresh, int npts);
+int relastroVisualPlotOutliers(Catalog *catalog, int offset, int Nmeasure, 
+			       StatType statsR, StatType statsD, double thresh);
+
Index: trunk/Ohana/src/relastro/src/FitSimple.c
===================================================================
--- trunk/Ohana/src/relastro/src/FitSimple.c	(revision 27392)
+++ trunk/Ohana/src/relastro/src/FitSimple.c	(revision 27435)
@@ -17,5 +17,5 @@
 
     // XXX the value needs to be set in a more intelligent way
-    if (dR > 0.15) continue;
+    if (dR > 0.50) continue;
     
     fit_add (fit, raw[i].X, raw[i].Y, ref[i].P, ref[i].Q, 1.0);
Index: trunk/Ohana/src/relastro/src/ImageOps.c
===================================================================
--- trunk/Ohana/src/relastro/src/ImageOps.c	(revision 27392)
+++ trunk/Ohana/src/relastro/src/ImageOps.c	(revision 27435)
@@ -1,35 +1,52 @@
 # include "relastro.h"
-#define TESTING
-
+# define TESTING
+# define USE_IMAGE_ID 1
+
+static off_t       **bin;     // link from catalog,measure to image
+static int         **clist;   // catalog which supplied measurement on image
+static off_t       **mlist;   // measure reference for measurement on image
+static off_t        *Nlist;   // number of measurements on image
+static off_t        *NLIST;   // allocated number of measurements on image
+
+static Image        *image;   // list of available images
+static off_t        Nimage;   // number of available images
+
+# if USE_IMAGE_ID
+// we sort (imageIDs, imageIdx) by imageIDs to get a sorted index
+static off_t        *imageIDs; // list of all image IDs
+static off_t        *imageIdx; // list of index for image IDs 
+# else
 static unsigned int *start;
 static unsigned int *stop;
-static int         **bin;
-
-static int         **clist;
-static int         **mlist;
-static int          *Nlist;
-static int          *NLIST;
-
-static Image        *image;
-static int          Nimage;
-
-Image *getimages (int *N) {
+# endif
+
+Image *getimages (off_t *N) {
   *N = Nimage;
   return (image);
 }
 
-Image *getimage (int N) {
+Image *getimage (off_t N) {
   return (&image[N]);
 }
 
-void initImages (Image *input, int N) {
-
-  int i;
+void initImages (Image *input, off_t N) {
+
+  off_t i;
 
   image = input;
   Nimage = N;
 
-  ALLOCATE (start,   unsigned, Nimage);
-  ALLOCATE (stop,    unsigned, Nimage);
+# if USE_IMAGE_ID
+  ALLOCATE (imageIDs, off_t, Nimage);
+  ALLOCATE (imageIdx, off_t, Nimage);
+
+  for (i = 0; i < Nimage; i++) {
+    imageIdx[i] = i;
+    imageIDs[i] = image[i].imageID;
+  }
+  llsortpair (imageIDs, imageIdx, Nimage);
+# else
+  ALLOCATE (start, unsigned, Nimage);
+  ALLOCATE (stop, unsigned, Nimage);
 
   for (i = 0; i < Nimage; i++) {
@@ -37,20 +54,49 @@
     stop[i]  = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1);
   }
+# endif
+
+}
+
+off_t getImageByID (off_t ID) {
+
+  // we have a pair of vectors (imageIDs, imageIdx) sorted by imageIDs
+  // use bisection to find the specified image ID
+
+# if USE_IMAGE_ID
+  off_t Nlo, Nhi, N;
+
+  Nlo = 0; Nhi = Nimage;
+  while (Nhi - Nlo > 10) {
+    N = 0.5*(Nlo + Nhi);
+    if (imageIDs[N] < ID) {
+      Nlo = MAX(N, 0);
+    } else {
+      Nhi = MIN(N + 1, Nimage);
+    }
+  }
+
+  for (N = Nlo; N < Nhi; N++) {
+    if (imageIDs[N] == ID)
+      return (imageIdx[N]);
+  }
+# endif
+
+  return (-1);
 }
 
 void initImageBins (Catalog *catalog, int Ncatalog) {
 
-  int i, j;
-
-  ALLOCATE (bin, int *, Ncatalog);
+  off_t i, j;
+
+  ALLOCATE (bin, off_t *, Ncatalog);
   for (i = 0; i < Ncatalog; i++) {
-    ALLOCATE (bin[i], int, MAX (catalog[i].Nmeasure, 1));
+    ALLOCATE (bin[i], off_t, MAX (catalog[i].Nmeasure, 1));
     for (j = 0; j < catalog[i].Nmeasure; j++) bin[i][j] = -1;
   }
 
-  ALLOCATE (Nlist, int, Nimage);
-  ALLOCATE (NLIST, int, Nimage);
-  ALLOCATE (clist, int *, Nimage);
-  ALLOCATE (mlist, int *, Nimage);
+  ALLOCATE (Nlist, off_t,   Nimage);
+  ALLOCATE (NLIST, off_t,   Nimage);
+  ALLOCATE (clist, int *,   Nimage);
+  ALLOCATE (mlist, off_t *, Nimage);
 
   for (i = 0; i < Nimage; i++) {
@@ -58,5 +104,5 @@
     NLIST[i] = 100;
     ALLOCATE (clist[i], int, NLIST[i]);
-    ALLOCATE (mlist[i], int, NLIST[i]);
+    ALLOCATE (mlist[i], off_t, NLIST[i]);
   }
 }
@@ -64,5 +110,5 @@
 void freeImageBins (int Ncatalog) {
 
-  int i;
+  off_t i;
 
   for (i = 0; i < Ncatalog; i++) {
@@ -81,5 +127,5 @@
 void findImages (Catalog *catalog, int Ncatalog) {
 
-  int i, j;
+  off_t i, j;
   char *name;
 
@@ -92,13 +138,48 @@
   for (i = 0; VERBOSE && (i < Nimage); i++) {
     name = GetPhotcodeNamebyCode (image[i].photcode);
-    fprintf (stderr, "image %d has %d measures (%s, %s)\n", i, Nlist[i],
+    fprintf (stderr, "image %lld has %lld measures (%s, %s)\n", (long long) i, (long long) Nlist[i],
              ohana_sec_to_date(image[i].tzero), name);
   }
 }
 
+# if USE_IMAGE_ID
 /* modify this function to use the measure->imageID field */
-void matchImage (Catalog *catalog, int meas, int cat) {
-
-  int i;
+void matchImage (Catalog *catalog, off_t meas, int cat) {
+
+  off_t idx, ID;
+  Measure *measure;
+
+  measure = &catalog[cat].measure[meas];
+
+  ID = measure[0].imageID;
+  idx = getImageByID (ID);
+  if (idx == -1) {
+    fprintf (stderr, "can't match detection to image?\n");
+    abort();
+  }
+
+  // index for (catalog, measure) -> image
+  bin[cat][meas] = idx;
+
+  // index for image, Nentry -> catalog
+  clist[idx][Nlist[idx]] = cat;
+
+  // index for image, Nentry -> measure
+  mlist[idx][Nlist[idx]] = meas;
+  Nlist[idx] ++;
+
+  if (Nlist[idx] == NLIST[idx]) {
+    NLIST[idx] += 100;
+    REALLOCATE (clist[idx], int,   NLIST[idx]);
+    REALLOCATE (mlist[idx], off_t, NLIST[idx]);
+  }
+  return;
+}
+
+# else
+/* modify this function to use the measure->imageID field */
+void matchImage (Catalog *catalog, off_t meas, int cat) {
+
+  off_t i;
   Measure *measure;
 
@@ -107,4 +188,6 @@
   /* find the image that supplied this measurement */
   for (i = 0; i < Nimage; i++) {
+    // let's try the very slow method first before adding a bisection search
+    // if (image[i].imageID != measure[0].imageID) continue;
     if (image[0].photcode == -1) continue;
     if (measure[0].photcode != image[i].photcode) continue;
@@ -124,14 +207,17 @@
     if (Nlist[i] == NLIST[i]) {
       NLIST[i] += 100;
-      REALLOCATE (clist[i], int, NLIST[i]);
-      REALLOCATE (mlist[i], int, NLIST[i]);
+      REALLOCATE (clist[i], int,   NLIST[i]);
+      REALLOCATE (mlist[i], off_t, NLIST[i]);
     }
     return;
   }
-}
-
-Coords *getCoords (int meas, int cat) {
-
-  int i;
+  fprintf (stderr, "can't match detection to image?\n");
+  abort();
+}
+# endif
+
+Coords *getCoords (off_t meas, int cat) {
+
+  off_t i;
 
   i = bin[cat][meas];
@@ -142,5 +228,5 @@
 void plot_images () {
 
-  int i, bin;
+  off_t i, bin;
   double *xlist, *Mlist, *dlist;
   Graphdata graphdata;
@@ -188,7 +274,7 @@
 // return StarData values for detections in the specified image, converting coordinates from the
 // chip positions: X,Y -> L,M -> P,Q -> R,D
-void fixImageRaw (Catalog *catalog, int Ncatalog, int im) {
-
-  int i, m, c, n;
+void fixImageRaw (Catalog *catalog, int Ncatalog, off_t im) {
+
+  off_t i, m, c, n;
   double X, Y, L, M, P, Q, R, D, dR, dD;
 
@@ -199,5 +285,5 @@
   mosaic = getMosaicForImage (im);
   if (mosaic != NULL) {
-      moscoords = &mosaic[0].coords;
+    moscoords = &mosaic[0].coords;
   }
   imcoords = &image[im].coords;
@@ -257,7 +343,7 @@
 // chip positions: X,Y -> L,M -> P,Q -> R,D.  This function is used by the image fitting steps, for
 // which the detections have already been filtered when they were loaded (bcatalog)
-StarData *getImageRaw (Catalog *catalog, int Ncatalog, int im, int *Nstars, CoordMode mode) {
-
-  int i, m, c, n;
+StarData *getImageRaw (Catalog *catalog, int Ncatalog, off_t im, off_t *Nstars, CoordMode mode) {
+
+  off_t i, m, c, n;
 
   Mosaic *mosaic;
@@ -270,10 +356,10 @@
   moscoords = NULL;
   if (mode == MODE_MOSAIC) {
-      mosaic = getMosaicForImage (im);
-      if (mosaic == NULL) {
-        fprintf (stderr, "mosaic not found for image %s\n", image[im].name);
-        exit (1);
-      }
-      moscoords = &mosaic[0].coords;
+    mosaic = getMosaicForImage (im);
+    if (mosaic == NULL) {
+      fprintf (stderr, "mosaic not found for image %s\n", image[im].name);
+      exit (1);
+    }
+    moscoords = &mosaic[0].coords;
   }
 
@@ -319,7 +405,7 @@
         LM_to_RD (&raw[i].R, &raw[i].D, raw[i].P, raw[i].Q, moscoords);
         break;
-    default:
-      fprintf (stderr, "error: invalid mode in getImageRaw");
-      abort ();
+      default:
+	fprintf (stderr, "error: invalid mode in getImageRaw");
+	abort ();
     }
   }
@@ -332,7 +418,7 @@
 // the sky positions: R,D -> P,Q -> L,M -> X,Y
 
-StarData *getImageRef (Catalog *catalog, int Ncatalog, int im, int *Nstars, CoordMode mode) {
-
-  int i, m, c, n;
+StarData *getImageRef (Catalog *catalog, int Ncatalog, off_t im, off_t *Nstars, CoordMode mode) {
+
+  off_t i, m, c, n;
 
   Mosaic *mosaic;
@@ -371,14 +457,14 @@
     switch (mode) {
       case MODE_SIMPLE:
-      RD_to_LM (&ref[i].P, &ref[i].Q, ref[i].R, ref[i].D, &image[im].coords);
-      ref[i].L = ref[i].P;
-      ref[i].M = ref[i].Q;
-      LM_to_XY (&ref[i].X, &ref[i].Y, ref[i].L, ref[i].M, &image[im].coords);
-      break;
+	RD_to_LM (&ref[i].P, &ref[i].Q, ref[i].R, ref[i].D, &image[im].coords);
+	ref[i].L = ref[i].P;
+	ref[i].M = ref[i].Q;
+	LM_to_XY (&ref[i].X, &ref[i].Y, ref[i].L, ref[i].M, &image[im].coords);
+	break;
       case MODE_MOSAIC:
-      RD_to_LM (&ref[i].P, &ref[i].Q, ref[i].R, ref[i].D, moscoords);
-      LM_to_XY (&ref[i].L, &ref[i].M, ref[i].P, ref[i].Q, moscoords);
-      LM_to_XY (&ref[i].X, &ref[i].Y, ref[i].L, ref[i].M, &image[im].coords);
-      break;
+	RD_to_LM (&ref[i].P, &ref[i].Q, ref[i].R, ref[i].D, moscoords);
+	LM_to_XY (&ref[i].L, &ref[i].M, ref[i].P, ref[i].Q, moscoords);
+	LM_to_XY (&ref[i].X, &ref[i].Y, ref[i].L, ref[i].M, &image[im].coords);
+	break;
       default:
         fprintf (stderr, "invalid case");
@@ -399,5 +485,6 @@
   return;
 
-  int i, j, k, m, N, Ndel, Nave, Nmax, TOOFEW, Nsecfilt;
+  int Ndel, Nave;
+  off_t i, j, k, m, N, Nmax, TOOFEW, Nsecfilt;
   double Ns, theta, x, y;
   double *R, *D, *dR, *dD;
@@ -490,5 +577,6 @@
 void FlagOutliers2D (Catalog *catalog) {
 
-  int i, j, k, m, N, Ndel, Nave, Nmax, TOOFEW, Nsecfilt;
+  int Ndel, Nave;
+  off_t i, j, k, m, N, Nmax, TOOFEW, Nsecfilt;
   double *index;
   double Ns, theta, x, y;
@@ -569,5 +657,5 @@
     // recalculate image center, sigma based on closest 50% of points
     for(k = 0;  k < N; k++) {
-      int ind = (int) index[k];
+      off_t ind = (off_t) index[k];
       R[k] = catalog[0].measure[ind].dR;
       D[k] = catalog[0].measure[ind].dD;
Index: trunk/Ohana/src/relastro/src/MosaicOps.c
===================================================================
--- trunk/Ohana/src/relastro/src/MosaicOps.c	(revision 27392)
+++ trunk/Ohana/src/relastro/src/MosaicOps.c	(revision 27435)
@@ -2,26 +2,78 @@
 
 // array of mosaic definition structures
-static int    Nmosaic;
+static off_t    Nmosaic;
 static Mosaic *mosaic;
 
 // list of all images associated with a mosaic
-static int   *Nmosaic_own_images; // number of images for this mosaic
-static int   *Amosaic_own_images; // size of allocated array
-static int   **mosaic_own_images; // array of arrays: mosaic -> images
+static off_t   *Nmosaic_own_images; // number of images for this mosaic
+static off_t   *Amosaic_own_images; // size of allocated array
+static off_t   **mosaic_own_images; // array of arrays: mosaic -> images
 
 // list of mosaic associated with each image  
-static int    Nmosaic_for_images; // number of images (for internal checks)
-static int    *mosaic_for_images; // array of: image -> mosaic
-
-Mosaic *getmosaics (int *N) {
+static off_t    Nmosaic_for_images; // number of images (for off_ternal checks)
+static off_t    *mosaic_for_images; // array of: image -> mosaic
+
+Mosaic *getmosaics (off_t *N) {
   *N = Nmosaic;
   return (mosaic);
 }
 
+off_t getMosaicByTimes (unsigned int start, unsigned int stop, unsigned int *startMos, unsigned int *stopMos, off_t *indexMos) {
+
+  // use bisection to find the overlapping mosaic
+
+  off_t Nlo, Nhi, N;
+
+  // find the last mosaic before start
+  Nlo = 0; Nhi = Nmosaic;
+  while (Nhi - Nlo > 10) {
+    N = 0.5*(Nlo + Nhi);
+    if (startMos[N] < start) {
+      Nlo = MAX(N, 0);
+    } else {
+      Nhi = MIN(N + 1, Nmosaic);
+    }
+  }
+
+  // check for the matched mosaic starting from Nlo 
+  // we may have to go much beyond Nlo since stop is not sorted
+  // can we use a sorted version of stop to check when we are beyond the valid range??
+  for (N = Nlo; N < Nmosaic; N++) { 
+    if (stop  < stopMos[N]) continue;
+    if (start > startMos[N])  continue;
+    if (stop  < startMos[N]) return (-1);
+    return (indexMos[N]);
+  }
+
+  return (-1);
+}
+
+// sort two times vectors and an index by first time vector
+void sort_mosaic_times (unsigned int *S, unsigned int *E, off_t *I, off_t N) {
+
+# define SWAPFUNC(A,B){ unsigned int tmp_t; off_t tmp_i; \
+  tmp_t = S[A]; S[A] = S[B]; S[B] = tmp_t; \
+  tmp_t = E[A]; E[A] = E[B]; E[B] = tmp_t; \
+  tmp_i = I[A]; I[A] = I[B]; I[B] = tmp_i; \
+}
+# define COMPARE(A,B)(S[A] < S[B])
+
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+
+}
+
+// first, let's continue to use the time to make the match, but use bracketing to make it faster:
+
 // find mosaic frames (unique time periods & photcode name matches mosaic) 
-void initMosaics (Image *image, int Nimage) {
-
-  int i, j, found, NMOSAIC;
+void initMosaics (Image *image, off_t Nimage) {
+
+  off_t i, Nmos, NMOSAIC;
   unsigned int start, stop;
+
+  unsigned int *startMos, *stopMos;
+  off_t *indexMos;
 
   Nmosaic = 0;
@@ -29,7 +81,10 @@
   ALLOCATE (mosaic, Mosaic, NMOSAIC);
 
-  ALLOCATE (Nmosaic_own_images, int, NMOSAIC);
-  ALLOCATE (Amosaic_own_images, int, NMOSAIC);
-  ALLOCATE (mosaic_own_images, int *, NMOSAIC);
+  ALLOCATE (Nmosaic_own_images, off_t, NMOSAIC);
+  ALLOCATE (Amosaic_own_images, off_t, NMOSAIC);
+  ALLOCATE (mosaic_own_images, off_t *, NMOSAIC);
+  ALLOCATE (startMos, unsigned int, NMOSAIC);
+  ALLOCATE (stopMos, unsigned int, NMOSAIC);
+  ALLOCATE (indexMos, off_t, NMOSAIC);
 
   /* find the mosaic images (coords.ctype = DIS); generate list of unique mosaics */
@@ -54,5 +109,9 @@
     Nmosaic_own_images[Nmosaic] = 0;
     Amosaic_own_images[Nmosaic] = 10;
-    ALLOCATE (mosaic_own_images[Nmosaic], int, Amosaic_own_images[Nmosaic]);
+    ALLOCATE (mosaic_own_images[Nmosaic], off_t, Amosaic_own_images[Nmosaic]);
+
+    startMos[Nmosaic] = start;
+    stopMos[Nmosaic] = stop;
+    indexMos[Nmosaic] = Nmosaic;
 
     Nmosaic ++;
@@ -60,13 +119,19 @@
       NMOSAIC += 10;
       REALLOCATE (mosaic, Mosaic, NMOSAIC);
-      REALLOCATE (mosaic_own_images, int *, NMOSAIC);
-      REALLOCATE (Nmosaic_own_images, int, NMOSAIC);
-      REALLOCATE (Amosaic_own_images, int, NMOSAIC);
-    }
-  }
-
+      REALLOCATE (mosaic_own_images, off_t *, NMOSAIC);
+      REALLOCATE (Nmosaic_own_images, off_t, NMOSAIC);
+      REALLOCATE (Amosaic_own_images, off_t, NMOSAIC);
+      REALLOCATE (startMos, unsigned int, NMOSAIC);
+      REALLOCATE (stopMos, unsigned int, NMOSAIC);
+      REALLOCATE (indexMos, off_t, NMOSAIC);
+    }
+  }
+
+  // sort the index, start, and stop by the start times:
+  sort_mosaic_times (startMos, stopMos, indexMos, Nmosaic);
+  
   // array to store image->mosaic index
   Nmosaic_for_images = Nimage;
-  ALLOCATE (mosaic_for_images, int, Nmosaic_for_images);
+  ALLOCATE (mosaic_for_images, off_t, Nmosaic_for_images);
 
   /* now assign the WRP images to these mosaics */
@@ -80,26 +145,18 @@
     stop  = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1);
 
-    /* find existing mosaic with this time range */
-    found = FALSE;
-    for (j = 0; !found && (j < Nmosaic); j++) { 
-      if (stop  < mosaic[j].start) continue;
-      if (start > mosaic[j].stop)  continue;
-      found = TRUE;
-      break;
-    }
-    /* if no matching mosaic exists, skip this image */
-    if (!found) continue;
+    Nmos = getMosaicByTimes (start, stop, startMos, stopMos, indexMos);
+    if (Nmos == -1) continue;
 
     // mosaic corresponding to this image
-    mosaic_for_images[i] = j;
+    mosaic_for_images[i] = Nmos;
 
     // add image to mosaic_own_image list 
-    mosaic_own_images[j][Nmosaic_own_images[j]] = i;
-    Nmosaic_own_images[j] ++;
-    if (Nmosaic_own_images[j] == Amosaic_own_images[j]) {
-      Amosaic_own_images[j] += 10;
-      REALLOCATE (mosaic_own_images[j], int, Amosaic_own_images[j]);
-    }
-    assert (Nmosaic_own_images[j] < Amosaic_own_images[j]);
+    mosaic_own_images[Nmos][Nmosaic_own_images[Nmos]] = i;
+    Nmosaic_own_images[Nmos] ++;
+    if (Nmosaic_own_images[Nmos] == Amosaic_own_images[Nmos]) {
+      Amosaic_own_images[Nmos] += 10;
+      REALLOCATE (mosaic_own_images[Nmos], off_t, Amosaic_own_images[Nmos]);
+    }
+    assert (Nmosaic_own_images[Nmos] < Amosaic_own_images[Nmos]);
   }
 
@@ -109,7 +166,7 @@
 // return StarData values for detections in the specified image, converting coordinates from the
 // chip positions: X,Y -> L,M -> P,Q -> R,D
-StarData *getMosaicRaw (Catalog *catalog, int Ncatalog, int mos, int *Nstars) {
-
-  int i, j, im, Nraw, Nnew;
+StarData *getMosaicRaw (Catalog *catalog, int Ncatalog, off_t mos, off_t *Nstars) {
+
+  off_t i, j, im, Nraw, Nnew;
   StarData *raw, *new;
 
@@ -142,7 +199,7 @@
 // return StarData values for averages positions in the specified image, converting coordinates from
 // the sky positions: R,D -> P,Q -> L,M -> X,Y
-StarData *getMosaicRef (Catalog *catalog, int Ncatalog, int mos, int *Nstars) {
-
-  int i, j, im, Nref, Nnew;
+StarData *getMosaicRef (Catalog *catalog, int Ncatalog, off_t mos, off_t *Nstars) {
+
+  off_t i, j, im, Nref, Nnew;
   StarData *ref, *new;
   
@@ -172,7 +229,7 @@
 }
 
-Mosaic *getMosaicForImage (int im) {
-
-  int mos;
+Mosaic *getMosaicForImage (off_t im) {
+
+  off_t mos;
 
   if (im < 0) abort();
Index: trunk/Ohana/src/relastro/src/UpdateChips.c
===================================================================
--- trunk/Ohana/src/relastro/src/UpdateChips.c	(revision 27392)
+++ trunk/Ohana/src/relastro/src/UpdateChips.c	(revision 27435)
@@ -4,5 +4,5 @@
 
   /* we can measure new image parameters for each non-mosaic chip independently */
-  int i, Nimage, Nraw, Nref;
+  off_t i, Nimage, Nraw, Nref;
   Image *image;
   StarData *raw, *ref;
@@ -25,5 +25,5 @@
 
     // FitChip does iterative, clipped fitting
-    fprintf (stderr, "image %d : Nstars: %d\n", i, Nraw);
+    fprintf (stderr, "image %lld : Nstars: %lld\n", (long long) i, (long long) Nraw);
     FitChip (raw, ref, Nraw, &image[i].coords);
 
Index: trunk/Ohana/src/relastro/src/UpdateMeasures.c
===================================================================
--- trunk/Ohana/src/relastro/src/UpdateMeasures.c	(revision 27392)
+++ trunk/Ohana/src/relastro/src/UpdateMeasures.c	(revision 27435)
@@ -3,5 +3,5 @@
 int UpdateMeasures (Catalog *catalog, int Ncatalog) {
 
-  int i, Nimage;
+  off_t i, Nimage;
   Image *image;
 
Index: trunk/Ohana/src/relastro/src/UpdateMosaic.c
===================================================================
--- trunk/Ohana/src/relastro/src/UpdateMosaic.c	(revision 27392)
+++ trunk/Ohana/src/relastro/src/UpdateMosaic.c	(revision 27435)
@@ -4,5 +4,5 @@
 
   /* we can measure new image parameters for each mosaic independently */
-  int i, Nmosaic, Nstars;
+  off_t i, Nmosaic, Nstars;
   Mosaic *mosaic;
   StarData *raw, *ref;
Index: trunk/Ohana/src/relastro/src/UpdateObjects.c
===================================================================
--- trunk/Ohana/src/relastro/src/UpdateObjects.c	(revision 27392)
+++ trunk/Ohana/src/relastro/src/UpdateObjects.c	(revision 27435)
@@ -1,5 +1,5 @@
 # include "relastro.h"
 
-static int Nmax;
+static off_t   Nmax;
 static double *X, *dX;
 static double *Y, *dY;
@@ -13,5 +13,5 @@
 void initObjectData (Catalog *catalog, int Ncatalog) {
 
-  int i, j;
+  off_t i, j;
   
   Nmax = 0;
@@ -40,5 +40,5 @@
 int UpdateObjects (Catalog *catalog, int Ncatalog) {
 
-  int i, j, k, m, N, Nsecfilt, found, kp;
+  int i, j, k, m, N, Nsecfilt;
   StatType statsR, statsD;
   Coords coords;
@@ -47,7 +47,4 @@
   int mode, Nave, Npm, Npar, Nskip;
   double Tmin, Tmax;
-  float mag;
-  int mask;
-  PhotCode *code;
 
   initObjectData (catalog, Ncatalog);
@@ -74,5 +71,5 @@
   for (i = 0; i < Ncatalog; i++) {
 
-    if (VERBOSE) fprintf (stderr, "astrometrize catalog %d : %d ave, %d meas\n", i, catalog[i].Naverage, catalog[i].Nmeasure);
+    if (VERBOSE) fprintf (stderr, "astrometrize catalog %d : %lld ave, %lld meas\n", i, (long long) catalog[i].Naverage, (long long) catalog[i].Nmeasure);
 
     Nskip = 0;
Index: trunk/Ohana/src/relastro/src/UpdateSimple.c
===================================================================
--- trunk/Ohana/src/relastro/src/UpdateSimple.c	(revision 27392)
+++ trunk/Ohana/src/relastro/src/UpdateSimple.c	(revision 27435)
@@ -4,5 +4,5 @@
 
   /* we can measure new image parameters for each non-mosaic chip independently */
-  int i, Nimage, Nstars;
+  off_t i, Nimage, Nstars;
   Image *image;
   StarData *raw, *ref;
Index: trunk/Ohana/src/relastro/src/bcatalog.c
===================================================================
--- trunk/Ohana/src/relastro/src/bcatalog.c	(revision 27392)
+++ trunk/Ohana/src/relastro/src/bcatalog.c	(revision 27435)
@@ -3,9 +3,7 @@
 int bcatalog (Catalog *subcatalog, Catalog *catalog) {
 
-  int i, j, k, offset, found;
-  int NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm, Nsecfilt;
-  float mag;
-  int mask;
-  PhotCode *code;
+  off_t i, j, offset;
+  off_t NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm;
+  int Nsecfilt;
 
   // XXX in the future, use catalog[0].Nsecfilt only?  allow catalogs to have variable Nsecfilt?
@@ -106,6 +104,5 @@
 
   if (VERBOSE) {
-    fprintf (stderr, "%d: using %d stars (%d measures) for catalog\n", i,
-             subcatalog[0].Naverage, subcatalog[0].Nmeasure);
+    fprintf (stderr, "%lld: using %lld stars (%lld measures) for catalog\n", (long long) i, (long long) subcatalog[0].Naverage, (long long) subcatalog[0].Nmeasure);
    }
   return (TRUE);
Index: trunk/Ohana/src/relastro/src/load_images.c
===================================================================
--- trunk/Ohana/src/relastro/src/load_images.c	(revision 27392)
+++ trunk/Ohana/src/relastro/src/load_images.c	(revision 27435)
@@ -1,12 +1,21 @@
 # include "relastro.h"
+
+# define MARKTIME(MSG,...) { \
+  float dtime; \
+  gettimeofday (&stop, (void *) NULL); \
+  dtime = DTIME (stop, start); \
+  fprintf (stderr, MSG, __VA_ARGS__); }
 
 SkyList *load_images (FITS_DB *db, SkyRegion *region) {
 
   Image     *image, *subset;
-  int        Nimage, Nsubset;
-  int       *LineNumber;
+  off_t      Nimage, Nsubset;
+  off_t     *LineNumber;
+  struct timeval start, stop;
 
   SkyTable *sky = NULL;
   SkyList *skylist = NULL;
+
+  gettimeofday (&start, (void *) NULL);
 
   // load the current sky table (layout of all SkyRegions) 
@@ -16,15 +25,21 @@
   // determine the populated SkyRegions overlapping the requested area
   skylist = SkyListByPatch (sky, -1, region);
+  MARKTIME("  setup sky: %f sec\n", dtime);
 
   // convert database table to internal structure
   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
+  MARKTIME("  convert image table: %f sec\n", dtime);
 
   // select the images which overlap the selected sky regions
   subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset);
+  MARKTIME("  select images: %f sec\n", dtime);
 
   gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, LineNumber, Nsubset);
 
   initImages (subset, Nsubset);
+  MARKTIME("  init images: %f sec\n", dtime);
+
   initMosaics (subset, Nsubset);
+  MARKTIME("  init mosaics: %f sec\n", dtime);
   
   /* unlock, if we can (else, unlocked below) */
Index: trunk/Ohana/src/relastro/src/relastro.c
===================================================================
--- trunk/Ohana/src/relastro/src/relastro.c	(revision 27392)
+++ trunk/Ohana/src/relastro/src/relastro.c	(revision 27435)
@@ -1,3 +1,9 @@
 # include "relastro.h"
+
+# define MARKTIME(MSG,...) { \
+  float dtime; \
+  gettimeofday (&stop, (void *) NULL); \
+  dtime = DTIME (stop, start); \
+  fprintf (stderr, MSG, __VA_ARGS__); }
 
 int main (int argc, char **argv) {
@@ -6,6 +12,9 @@
   Catalog *catalog;
   FITS_DB db;
+  struct timeval start, stop;
 
   SkyList *skylist = NULL;
+
+  gettimeofday (&start, (void *) NULL);
 
   /* get configuration info, args */
@@ -26,14 +35,20 @@
   if (db.dbstate == LCK_EMPTY) Shutdown ("ERROR: No images in catalog %s (1)", db.filename);
   if (!dvo_image_load (&db, VERBOSE, FALSE)) Shutdown ("can't read image catalog %s", db.filename);
+  MARKTIME("load image data: %f sec\n", dtime);
 
   /* load regions and images based on specified sky patch (default depth) */
   skylist = load_images (&db, &UserPatch);
+  MARKTIME("load images: %f sec\n", dtime);
 
   /* load catalog data from region files : subselect high-quality measurements */
   catalog = load_catalogs (skylist, &Ncatalog, TRUE);
+  MARKTIME("load catalog data: %f sec\n", dtime);
 
   /* match measurements with images */
   initImageBins (catalog, Ncatalog);
+  MARKTIME("make image bins: %f sec\n", dtime);
+
   findImages (catalog, Ncatalog);
+  MARKTIME("set up image indexes: %f sec\n", dtime);
 
   if (PLOTSTUFF) {
Index: trunk/Ohana/src/relastro/src/select_images.c
===================================================================
--- trunk/Ohana/src/relastro/src/select_images.c	(revision 27392)
+++ trunk/Ohana/src/relastro/src/select_images.c	(revision 27435)
@@ -13,14 +13,20 @@
 } SkyRegionCoords;
 
-Image *select_images (SkyList *skylist, Image *timage, int Ntimage, int **LineNumber, int *Nimage) {
+void dsortindex (double *X, off_t *Y, int N);
+off_t getRegionStartByRA (double R, double *Rref, off_t Nregions);
+
+Image *select_images (SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage) {
   
   Image *image;
-  int i, j, k, m, found, nimage, NIMAGE;
-  int InRange;
+  off_t i, j, k, m, nStart, iSky, nimage, NIMAGE;
+  int InRange, found;
   double Ri[5], Di[5], Xi[5], Yi[5], dx, dy;
-  int *line_number;
+  off_t *line_number;
   Coords tcoords;
   SkyRegionCoords *skycoords;
   
+  double *RmaxSky;
+  off_t *index;
+
   if (skylist[0].Nregions < 1) {
     *Nimage = 0;
@@ -38,4 +44,7 @@
 
   ALLOCATE (skycoords, SkyRegionCoords, skylist[0].Nregions);
+
+  ALLOCATE (RmaxSky, double, skylist[0].Nregions);
+  ALLOCATE (index, off_t, skylist[0].Nregions);
 
   /* compare with each region file */
@@ -56,4 +65,7 @@
     skycoords[i].Yc[4] = skycoords[i].Yc[0];    
 
+    RmaxSky[i] = skylist[0].regions[i][0].Rmax;
+    index[i] = i;
+
     dx = 0.02*(skycoords[i].Xc[2] - skycoords[i].Xc[0]);
     dy = 0.02*(skycoords[i].Yc[2] - skycoords[i].Yc[0]);
@@ -65,4 +77,6 @@
   }
 
+  dsortindex (RmaxSky, index, skylist[0].Nregions);
+
   if (VERBOSE) fprintf (stderr, "finding images\n");
   BuildChipMatch (timage, Ntimage);
@@ -71,5 +85,5 @@
   NIMAGE = 100;
   ALLOCATE (image, Image, NIMAGE);
-  ALLOCATE (line_number, int, NIMAGE);
+  ALLOCATE (line_number, off_t, NIMAGE);
   
   // go through the complete list of images, selecting ones which overlap any region
@@ -100,5 +114,8 @@
     }
     
-    if (!FindMosaicForImage (timage, Ntimage, i)) continue;
+    if (!FindMosaicForImage (timage, Ntimage, i)) {
+      fprintf (stderr, "cannot find mosaic for %lld\n", (long long) i);
+      continue;
+    }
 
     /* define image corners */
@@ -111,10 +128,22 @@
 
     /* transform to ra,dec */
+    double RminImage = 360.0;
+    // double RmaxImage =   0.0;
     for (j = 0; j < 5; j++) {
       XY_to_RD (&Ri[j], &Di[j], Xi[j], Yi[j], &timage[i].coords);
-    }
+      RminImage = MIN(RminImage, Ri[j]);
+      // RmaxImage = MIN(RmaxImage, Ri[j]);
+    }
+
+    // RA(nStart) is guaranteed to be < RminImage:
+    nStart = getRegionStartByRA (RminImage, RmaxSky, skylist[0].Nregions);
 
     /* compare with each region file */
-    for (m = 0; (m < skylist[0].Nregions) && !found; m++) { 
+    for (iSky = nStart; (iSky < skylist[0].Nregions) && !found; iSky++) { 
+
+      m = index[iSky];
+      // if (RmaxImage < skylist[0].regions[m][0].Rmin) {
+      // break;
+      // }
 
       /* we make positional comparisons in the projection of catalog */
@@ -122,5 +151,5 @@
       tcoords.crval2 = skycoords[m].Dc;
 
-      /* transform to ra,dec */
+      /* transform corner coords to X,Y in this catalog system */
       InRange = TRUE;
       for (j = 0; (j < 5) && InRange; j++) {
@@ -161,13 +190,13 @@
 	NIMAGE += 100;
 	REALLOCATE (image, Image, NIMAGE);
-	REALLOCATE (line_number, int, NIMAGE);
+	REALLOCATE (line_number, off_t, NIMAGE);
       }
     }
   }
       
-  if (VERBOSE) fprintf (stderr, "found %d images\n", nimage);
+  if (VERBOSE) fprintf (stderr, "found %lld images\n", (long long) nimage);
 
   REALLOCATE (image, Image, MAX (nimage, 1));
-  REALLOCATE (line_number, int, MAX (nimage, 1));
+  REALLOCATE (line_number, off_t, MAX (nimage, 1));
   free (skycoords);
 
@@ -253,2 +282,35 @@
 }
 
+void dsortindex (double *X, off_t *Y, int N) {
+
+# define SWAPFUNC(A,B){ double tmpf; off_t tmpi; \
+  tmpf = X[A]; X[A] = X[B]; X[B] = tmpf; \
+  tmpi = Y[A]; Y[A] = Y[B]; Y[B] = tmpi; \
+}
+# define COMPARE(A,B)(X[A] < X[B])
+
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+
+}
+
+off_t getRegionStartByRA (double R, double *Rref, off_t Nregions) {
+
+  // use bisection to find the overlapping mosaic
+
+  off_t Nlo, Nhi, N;
+
+  // find the last mosaic before start
+  Nlo = 0; Nhi = Nregions;
+  while (Nhi - Nlo > 10) {
+    N = 0.5*(Nlo + Nhi);
+    if (Rref[N] < R) {
+      Nlo = MAX(N, 0);
+    } else {
+      Nhi = MIN(N, Nregions);
+    }
+  }
+  return (Nlo);
+}
Index: trunk/Ohana/src/relphot/include/relphot.h
===================================================================
--- trunk/Ohana/src/relphot/include/relphot.h	(revision 27392)
+++ trunk/Ohana/src/relphot/include/relphot.h	(revision 27435)
@@ -7,12 +7,4 @@
 # define GRID_V2
 # define NO_IMAGE -100
-
-# if (0)
-typedef struct {
-  double xmin, xmax, ymin, ymax;
-  int style, ptype, ltype, etype, color;
-  double lweight, size;
-} Graphdata;
-# endif
 
 typedef struct {
@@ -110,9 +102,9 @@
 
 # ifdef GRID_V1
-int setGridMeasure (int meas, int cat, double X, double Y);
+int setGridMeasure (off_t meas, int cat, double X, double Y);
 # endif
 
 # ifdef GRID_V2
-int setGridMeasure (int meas, int cat, double X, double Y, int ccdnum);
+int setGridMeasure (off_t meas, int cat, double X, double Y, int ccdnum);
 # endif
 
@@ -122,5 +114,5 @@
 char         *GetPhotnamebyCode   PROTO((PhotCodeData *photcodes, int code));
 void          InterpolateGrid     PROTO((float *buffer, int Nx, int Ny, Coords *ccd, Coords *gcoords));
-int          *SelectRefMosaic     PROTO((Mosaic **refmosaic, int *Nimage));
+off_t        *SelectRefMosaic     PROTO((Mosaic **refmosaic, off_t *Nimage));
 int           args                PROTO((int argc, char **argv));
 int           bcatalog            PROTO((Catalog *subcatalog, Catalog *catalog));
@@ -137,5 +129,5 @@
 
 void set_db (FITS_DB *in);
-int Shutdown (char *format, ...);
+int Shutdown (char *format, ...) OHANA_FORMAT(printf, 1, 2) ;
 void TrapSignal (int sig);
 void SetProtect (int mode);
@@ -147,20 +139,20 @@
 void          free_catalogs       PROTO((Catalog *catalog, int Ncatalog));
 int           gcatalog            PROTO((Catalog *catalog, int FINAL));
-Coords       *getCoords           PROTO((int meas, int cat));
-int           getImageEntry       PROTO((int meas, int cat));
-float         getMcal             PROTO((int meas, int cat));
-float         getMgrid            PROTO((int meas, int cat));
-float         getMmos             PROTO((int meas, int cat));
-float         getMrel             PROTO((Catalog *catalog, int meas, int cat));
-Image        *getimage            PROTO((int N));
-Image        *getimages           PROTO((int *N));
+Coords       *getCoords           PROTO((off_t meas, int cat));
+off_t         getImageEntry       PROTO((off_t meas, int cat));
+float         getMcal             PROTO((off_t meas, int cat));
+float         getMgrid            PROTO((off_t meas, int cat));
+float         getMmos             PROTO((off_t meas, int cat));
+float         getMrel             PROTO((Catalog *catalog, off_t meas, int cat));
+Image        *getimage            PROTO((off_t N));
+Image        *getimages           PROTO((off_t *N));
 void          global_stats        PROTO((Catalog *catalog, int Ncatalog));
 void          initGrid            PROTO((int dX, int dY));
 void          initGridBins        PROTO((Catalog *catalog, int Ncatalog));
 void          initImageBins       PROTO((Catalog *catalog, int Ncatalog));
-void          initImages          PROTO((Image *input, int N));
+void          initImages          PROTO((Image *input, off_t N));
 void          initMosaicBins      PROTO((Catalog *catalog, int Ncatalog));
-void          initMosaicGrid      PROTO((Image *image, int Nimage));
-void          initMosaics         PROTO((Image *image, int Nimage));
+void          initMosaicGrid      PROTO((Image *image, off_t Nimage));
+void          initMosaics         PROTO((Image *image, off_t Nimage));
 void          initMrel            PROTO((Catalog *catalog, int Ncatalog));
 void          initialize          PROTO((int argc, char **argv));
@@ -169,10 +161,10 @@
 Catalog       *load_catalogs      PROTO((SkyList *skylist, int *Ncatalog));
 SkyList      *load_images         PROTO((FITS_DB *db, char *regionName, SkyRegion *region, int RegionSelect));
-Image         *select_images      PROTO((SkyList *skylist, Image *timage, int Ntimage, int **LineNumber, int *Nimage));
+Image         *select_images      PROTO((SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage));
 
 int           main                PROTO((int argc, char **argv));
-void          mark_images         PROTO((Image *image, int Nimage, Image *timage, int Ntimage));
-void          matchImage          PROTO((Catalog *catalog, int meas, int cat));
-void          matchMosaics        PROTO((Catalog *catalog, int meas, int cat));
+void          mark_images         PROTO((Image *image, off_t Nimage, Image *timage, off_t Ntimage));
+void          matchImage          PROTO((Catalog *catalog, off_t meas, int cat));
+void          matchMosaics        PROTO((Catalog *catalog, off_t meas, int cat));
 double        opening_angle       PROTO((double x1, double y1, double x2, double y2, double x3, double y3));
 void          plot_chisq          PROTO((Catalog *catalog, int Ncatalog));
@@ -180,5 +172,5 @@
 void          plot_grid           PROTO((Catalog *catalog));
 void          plot_images         PROTO((void));
-void          plot_list           PROTO((Graphdata *graphdata, double *xlist, double *ylist, int N, char *label, char *format, ...));
+void          plot_list           PROTO((Graphdata *graphdata, double *xlist, double *ylist, int N, char *label, char *format, ...) OHANA_FORMAT(printf, 6, 7) );
 void          plot_mosaic_fields  PROTO((Catalog *catalog));
 void          plot_mosaics        PROTO((void));
@@ -199,5 +191,5 @@
 int           setMave             PROTO((Catalog *catalog, int Ncatalog));
 void          set_ZP              PROTO((double ZERO));
-int           setrefcode          PROTO((Image *image, int Nimage)); 
+int           setrefcode          PROTO((Image *image, off_t Nimage)); 
 void          skip_measurements   PROTO((Catalog *catalog, int pass));
 void          sortA               PROTO((double *X, int N));
Index: trunk/Ohana/src/relphot/src/GridOps.c
===================================================================
--- trunk/Ohana/src/relphot/src/GridOps.c	(revision 27392)
+++ trunk/Ohana/src/relphot/src/GridOps.c	(revision 27435)
@@ -7,20 +7,20 @@
 };
 
-static int     Ngrid;
+static int     Ngrid;  // number of grid elements (gridX * gridY)
 static float   *gridM; // magnitude offset for this grid cell 
 static float   *gridS; // stdev of the magnitude offset for this grid cell 
 static int     *gridN; // number of stars used to measure the magnitude offset for this grid cell 
 static int     *gridV; // data mode for this cell: fitted, frozen, reference
-static int      gridX;
-static int      gridY;
-
-static int    **bin;
-static int    **Xmeas;
-static int    **Ymeas;
+static int      gridX; // number of grid elements in X direction
+static int      gridY; // number of grid elements in Y direction
+
+static int    **bin;   // link from catalog, measure to grid element
+static int    **Xmeas; // grid x-coordinate for a measurement
+static int    **Ymeas; // grid y-coordinate for a measurement
 
 static int    **clist; // link from measurement on a cell to catalog containing measurement
-static int    **mlist; // link from measurement on a cell to measurement in a catalog
-static int     *Nlist; // list of measurements for each grid cell
-static int     *NLIST;
+static off_t  **mlist; // link from measurement on a cell to measurement in a catalog
+static off_t   *Nlist; // number of measurements for each grid cell
+static off_t   *NLIST; // allocated number of measurements for each grid cell
 
 static struct {
@@ -159,5 +159,5 @@
   ALLOCATE (Ymeas, int *, Ncatalog);
   for (i = 0; i < Ncatalog; i++) {
-    ALLOCATE (bin[i], int, MAX (catalog[i].Nmeasure, 1));
+    ALLOCATE (bin[i],   int, MAX (catalog[i].Nmeasure, 1));
     ALLOCATE (Xmeas[i], int, MAX (catalog[i].Nmeasure, 1));
     ALLOCATE (Ymeas[i], int, MAX (catalog[i].Nmeasure, 1));
@@ -166,14 +166,14 @@
 
   /* define grid -> cat,meas pointers */
-  ALLOCATE (Nlist, int, Ngrid);
-  ALLOCATE (NLIST, int, Ngrid);
-  ALLOCATE (clist, int *, Ngrid);
-  ALLOCATE (mlist, int *, Ngrid);
+  ALLOCATE (Nlist, off_t,   Ngrid);
+  ALLOCATE (NLIST, off_t,   Ngrid);
+  ALLOCATE (clist, int *,   Ngrid);
+  ALLOCATE (mlist, off_t *, Ngrid);
 
   for (i = 0; i < Ngrid; i++) {
     Nlist[i] = 0;
     NLIST[i] = 100;
-    ALLOCATE (clist[i], int, NLIST[i]);
-    ALLOCATE (mlist[i], int, NLIST[i]);
+    ALLOCATE (clist[i], int,   NLIST[i]);
+    ALLOCATE (mlist[i], off_t, NLIST[i]);
   }
 }
@@ -206,5 +206,5 @@
 }
 
-int setGridMeasure (int meas, int cat, double X, double Y, int ccdnum) {
+int setGridMeasure (off_t meas, int cat, double X, double Y, int ccdnum) {
 
   int ix, iy, Cx, Cy, i;
@@ -241,6 +241,6 @@
   if (Nlist[i] == NLIST[i]) {
     NLIST[i] += 100;
-    REALLOCATE (clist[i], int, NLIST[i]);
-    REALLOCATE (mlist[i], int, NLIST[i]);
+    REALLOCATE (clist[i], int,   NLIST[i]);
+    REALLOCATE (mlist[i], off_t, NLIST[i]);
   }	
   return (TRUE);
@@ -264,5 +264,5 @@
 }
 
-float getMgrid (int meas, int cat) {
+float getMgrid (off_t meas, int cat) {
 
   int i;
@@ -287,5 +287,5 @@
 
   int **gotstar, **gridmeas;
-  int i, j, k, N, Ngood, Nbad, Nmos, Ncal, Nrel, Nsys;
+  int i, j, k, Ngood, Nbad, Nmos, Ncal, Nrel, Nsys;
   double **A, **B, *Mjx, *Wjx;
   float Msys, Mcal, Mmos, Merr, Wsys;
@@ -498,5 +498,5 @@
     gridM[i] = B[i][0];
     gridS[i] = sqrt(A[i][i]);
-    gridN[i] = N;
+    gridN[i] = Ngood;
   }
 
@@ -673,6 +673,7 @@
 void dump_grid () { 
 
-  int i, j, Nimage, Nbytes, Nformat;
-  int *imlist;
+  off_t i, Nimage;
+  int j, Nbytes, Nformat;
+  off_t *imlist;
   FILE *f;
   Header header, theader;
@@ -702,7 +703,7 @@
   gfits_create_header (&header);
   gfits_create_matrix (&header, &matrix);
-  gfits_modify (&header, "NEXTEND", "%d", 1, Nimage + 3);
+  gfits_modify (&header, "NEXTEND", "%lld", 1, (long long) Nimage + 3);
   gfits_modify (&header, "FILTER", "%s", 1, photcode[0].name);
-  gfits_modify (&header, "COMMENT", "%S", 1, "Mosaic Photometry Grid Analysis");
+  gfits_modify_alt (&header, "COMMENT", "%S", 1, "Mosaic Photometry Grid Analysis");
 
   // we need to add lines to the PHU to identify the camera and format; these are used by the ipp config system
Index: trunk/Ohana/src/relphot/src/ImageOps.c
===================================================================
--- trunk/Ohana/src/relphot/src/ImageOps.c	(revision 27392)
+++ trunk/Ohana/src/relphot/src/ImageOps.c	(revision 27435)
@@ -3,17 +3,17 @@
 static unsigned int *start;
 static unsigned int *stop;
-static int         **bin;
-
-static int         **clist;
-static int         **mlist;
-static int          *Nlist;
-static int          *NLIST;
+static off_t       **bin;
+
+static off_t       **clist;
+static off_t       **mlist;
+static off_t        *Nlist;
+static off_t        *NLIST;
 
 static Image        *image;
-static int          Nimage;
-
-void initImages (Image *input, int N) {
-
-  int i;
+static off_t        Nimage;
+
+void initImages (Image *input, off_t N) {
+
+  off_t i;
 
   image = input;
@@ -31,22 +31,22 @@
 void initImageBins (Catalog *catalog, int Ncatalog) {
 
-  int i, j;
-
-  ALLOCATE (bin, int *, Ncatalog);
+  off_t i, j;
+
+  ALLOCATE (bin, off_t *, Ncatalog);
   for (i = 0; i < Ncatalog; i++) {
-    ALLOCATE (bin[i], int, MAX (catalog[i].Nmeasure, 1));
+    ALLOCATE (bin[i], off_t, MAX (catalog[i].Nmeasure, 1));
     for (j = 0; j < catalog[i].Nmeasure; j++) bin[i][j] = -1;
   }
 
-  ALLOCATE (Nlist, int, Nimage);
-  ALLOCATE (NLIST, int, Nimage);
-  ALLOCATE (clist, int *, Nimage);
-  ALLOCATE (mlist, int *, Nimage);
+  ALLOCATE (Nlist, off_t, Nimage);
+  ALLOCATE (NLIST, off_t, Nimage);
+  ALLOCATE (clist, off_t *, Nimage);
+  ALLOCATE (mlist, off_t *, Nimage);
 
   for (i = 0; i < Nimage; i++) {
     Nlist[i] = 0;
     NLIST[i] = 100;
-    ALLOCATE (clist[i], int, NLIST[i]);
-    ALLOCATE (mlist[i], int, NLIST[i]);
+    ALLOCATE (clist[i], off_t, NLIST[i]);
+    ALLOCATE (mlist[i], off_t, NLIST[i]);
   }
 }
@@ -54,5 +54,5 @@
 void freeImageBins (int Ncatalog) {
 
-  int i;
+  off_t i;
 
   for (i = 0; i < Ncatalog; i++) {
@@ -70,5 +70,5 @@
 /* **** use this to mimic the Mosaic version ***/
 # if (0)
-void initImageGrid (Image *image, int Nimage) {
+void initImageGrid (Image *image, off_t Nimage) {
 
   /* find max dR, dD range for all mosaics */
@@ -76,5 +76,5 @@
   /* send results to initGridBins */
 
-  int i, j, m, NX, NY;
+  off_t i, j, m, NX, NY;
   int dXmax, dYmax;
   double dS, dX, dY;
@@ -151,5 +151,6 @@
 void findImages (Catalog *catalog, int Ncatalog) {
 
-  int i, j, ecode;
+  off_t j;
+  int i, ecode;
 
   for (i = 0; i < Ncatalog; i++) {
@@ -164,7 +165,8 @@
 /* XXX convert this to use the values of measure->Xccd,Yccd */
 /* XXX need to apply the conversion for ELIXIR and LONEOS formats */
-void matchImage (Catalog *catalog, int meas, int cat) {
-
-  int i, ccdnum;
+void matchImage (Catalog *catalog, off_t meas, int cat) {
+
+  off_t i;
+  int ccdnum;
   double X, Y;
   char *pname, *filter, *p, base[256];
@@ -220,6 +222,6 @@
     if (Nlist[i] == NLIST[i]) {
       NLIST[i] += 100;
-      REALLOCATE (clist[i], int, NLIST[i]);
-      REALLOCATE (mlist[i], int, NLIST[i]);
+      REALLOCATE (clist[i], off_t, NLIST[i]);
+      REALLOCATE (mlist[i], off_t, NLIST[i]);
     }	
     return;
@@ -228,7 +230,7 @@
 }
 
-int getImageEntry (int meas, int cat) {
-
-  int i;
+off_t getImageEntry (off_t meas, int cat) {
+
+  off_t i;
 
   i = bin[cat][meas];
@@ -236,7 +238,7 @@
 }
 
-float getMcal (int meas, int cat) {
-
-  int i;
+float getMcal (off_t meas, int cat) {
+
+  off_t i;
   float value;
 
@@ -249,7 +251,7 @@
 }
 
-Coords *getCoords (int meas, int cat) {
-
-  int i;
+Coords *getCoords (off_t meas, int cat) {
+
+  off_t i;
 
   i = bin[cat][meas];
@@ -261,5 +263,6 @@
 void setMcal (Catalog *catalog, int PoorImages) {
 
-  int i, j, m, c, n, N, Nmax, mark, bad, Nfew, Nbad, Nmos, Ngrid, Nrel, Nsys;
+  off_t i, j, m, c, n, N, Nmax, mark, bad;
+  int Nfew, Nbad, Nmos, Ngrid, Nrel, Nsys;
   float Msys, Mrel, Mmos, Mgrid;
   double *list, *dlist;
@@ -359,5 +362,6 @@
 void clean_images () {
 
-  int i, N, mark, Nmark;
+  int mark, Nmark;
+  off_t i, N;
   double *mlist, *slist, *dlist;
   double MaxOffset, MaxScatter, MedOffset;
@@ -409,5 +413,5 @@
 void plot_images () {
 
-  int i, bin;
+  off_t i, bin;
   double *xlist, *Mlist, *dlist;
   Graphdata graphdata;
@@ -457,5 +461,5 @@
 StatType statsImageN (Catalog *catalog) {
 
-  int i, j, m, c, n, N;
+  off_t i, j, m, c, n, N;
   double *list, *dlist;
   float Mcal, Mmos, Mgrid;
@@ -499,5 +503,5 @@
 StatType statsImageX (Catalog *catalog) {
 
-  int i, n;
+  off_t i, n;
   double *list, *dlist;
   StatType stats;
@@ -527,5 +531,5 @@
 StatType statsImageM (Catalog *catalog) {
 
-  int i, n;
+  off_t i, n;
   double *list, *dlist;
   StatType stats;
@@ -555,5 +559,5 @@
 StatType statsImagedM (Catalog *catalog) {
 
-  int i, n;
+  off_t i, n;
   double *list, *dlist;
   StatType stats;
@@ -581,5 +585,5 @@
 }
 
-Image *getimages (int *N) {
+Image *getimages (off_t *N) {
 
   *N = Nimage;
@@ -587,5 +591,5 @@
 }
 
-Image *getimage (int N) {
+Image *getimage (off_t N) {
   return (&image[N]);
 }
Index: trunk/Ohana/src/relphot/src/MosaicOps.c
===================================================================
--- trunk/Ohana/src/relphot/src/MosaicOps.c	(revision 27392)
+++ trunk/Ohana/src/relphot/src/MosaicOps.c	(revision 27435)
@@ -1,22 +1,20 @@
 # include "relphot.h"
 
-Image *getimages (int *N);
-
-static int    Nmosaic;
+static off_t  Nmosaic;
 static Mosaic *mosaic;
 
-static int    *Nimlist;
-static int   **imlist; /* mosaic -> image[] */
-static int   **bin;    /* catalog, measure -> mosaic */
-
-static int   **clist;  /* mosaic -> catalog[] */
-static int   **mlist;  /* mosiac -> measure[] */
-static int    *Nlist;
-static int    *NLIST;
+static off_t  *Nimlist;
+static off_t   **imlist; /* mosaic -> image[] */
+static off_t   **bin;    /* catalog, measure -> mosaic */
+
+static int     **clist;  /* mosaic -> catalog[] */
+static off_t   **mlist;  /* mosiac -> measure[] */
+static off_t    *Nlist;
+static off_t    *NLIST;
 
 /* find mosaic frames (unique time periods & photcode name matches mosaic) */
-void initMosaics (Image *image, int Nimage) {
-
-  int i, j, status, found, NMOSAIC, *NIMLIST;
+void initMosaics (Image *image, off_t Nimage) {
+
+  off_t i, j, status, found, NMOSAIC, *NIMLIST;
   unsigned int start, stop;
   char *pname;
@@ -28,7 +26,7 @@
   ALLOCATE (mosaic, Mosaic, NMOSAIC);
 
-  ALLOCATE (imlist, int *, NMOSAIC);
-  ALLOCATE (Nimlist, int, NMOSAIC);
-  ALLOCATE (NIMLIST, int, NMOSAIC);
+  ALLOCATE (imlist,  off_t *, NMOSAIC);
+  ALLOCATE (Nimlist, off_t,   NMOSAIC);
+  ALLOCATE (NIMLIST, off_t,   NMOSAIC);
 
   /* generate list of unique mosaics */
@@ -56,5 +54,5 @@
       if (Nimlist[j] == NIMLIST[j]) {
 	NIMLIST[j] += 10;
-	REALLOCATE (imlist[j], int, NIMLIST[j]);
+	REALLOCATE (imlist[j], off_t, NIMLIST[j]);
       }
 
@@ -74,5 +72,5 @@
     NIMLIST[Nmosaic] = 10;
     Nimlist[Nmosaic] = 1;
-    ALLOCATE (imlist[Nmosaic], int, NIMLIST[Nmosaic]);
+    ALLOCATE (imlist[Nmosaic], off_t, NIMLIST[Nmosaic]);
     imlist[Nmosaic][0] = i;
 
@@ -80,8 +78,8 @@
     if (Nmosaic == NMOSAIC) {
       NMOSAIC += 10;
-      REALLOCATE (mosaic, Mosaic, NMOSAIC);
-      REALLOCATE (imlist, int *, NMOSAIC);
-      REALLOCATE (Nimlist, int, NMOSAIC);
-      REALLOCATE (NIMLIST, int, NMOSAIC);
+      REALLOCATE (mosaic,  Mosaic,  NMOSAIC);
+      REALLOCATE (imlist,  off_t *, NMOSAIC);
+      REALLOCATE (Nimlist, off_t,   NMOSAIC);
+      REALLOCATE (NIMLIST, off_t,   NMOSAIC);
     }
   }
@@ -91,5 +89,5 @@
 }
 
-void initMosaicGrid (Image *image, int Nimage) {
+void initMosaicGrid (Image *image, off_t Nimage) {
 
   /* find max dR, dD range for all mosaics */
@@ -97,5 +95,5 @@
   /* send results to initGridBins */
 
-  int i, j, m, NX, NY;
+  off_t i, j, m, NX, NY;
   int dXmax, dYmax;
   double dS, dX, dY;
@@ -170,5 +168,5 @@
 void setMcalFinal () {
 
-  int i, j, im, Nimage;
+  off_t i, j, im, Nimage;
   Image *image;
 
@@ -191,26 +189,26 @@
 void initMosaicBins (Catalog *catalog, int Ncatalog) {
 
-  int i, j;
+  off_t i, j;
 
   /* measure -> mosaic */
   if (!MOSAIC_ZEROPT) return;
 
-  ALLOCATE (bin, int *, Ncatalog);
+  ALLOCATE (bin, off_t *, Ncatalog);
   for (i = 0; i < Ncatalog; i++) {
-    ALLOCATE (bin[i], int, MAX (catalog[i].Nmeasure, 1));
+    ALLOCATE (bin[i], off_t, MAX (catalog[i].Nmeasure, 1));
     for (j = 0; j < catalog[i].Nmeasure; j++) bin[i][j] = -1;
   }
 
   /* mosaic -> measure */
-  ALLOCATE (Nlist, int, Nmosaic);
-  ALLOCATE (NLIST, int, Nmosaic);
-  ALLOCATE (clist, int *, Nmosaic);
-  ALLOCATE (mlist, int *, Nmosaic);
+  ALLOCATE (Nlist, off_t,   Nmosaic);
+  ALLOCATE (NLIST, off_t,   Nmosaic);
+  ALLOCATE (clist, int *,   Nmosaic);
+  ALLOCATE (mlist, off_t *, Nmosaic);
 
   for (i = 0; i < Nmosaic; i++) {
     Nlist[i] = 0;
     NLIST[i] = 100;
-    ALLOCATE (clist[i], int, NLIST[i]);
-    ALLOCATE (mlist[i], int, NLIST[i]);
+    ALLOCATE (clist[i], int,   NLIST[i]);
+    ALLOCATE (mlist[i], off_t, NLIST[i]);
   }
 }
@@ -218,5 +216,5 @@
 void freeMosaicBins (int Ncatalog) {
 
-  int i;
+  off_t i;
 
   /* measure -> mosaic */
@@ -241,5 +239,6 @@
 int findMosaics (Catalog *catalog, int Ncatalog) {
   
-  int i, j, ecode;
+  int i, ecode;
+  off_t j;
 
   if (!MOSAIC_ZEROPT) return (FALSE);
@@ -259,5 +258,5 @@
 }
 
-void matchMosaics (Catalog *catalog, int meas, int cat) {
+void matchMosaics (Catalog *catalog, off_t meas, int cat) {
 
   int i;
@@ -287,6 +286,6 @@
     if (Nlist[i] == NLIST[i]) {
       NLIST[i] += 100;
-      REALLOCATE (clist[i], int, NLIST[i]);
-      REALLOCATE (mlist[i], int, NLIST[i]);
+      REALLOCATE (clist[i], int,   NLIST[i]);
+      REALLOCATE (mlist[i], off_t, NLIST[i]);
     }	
     return;
@@ -296,7 +295,7 @@
 }
 
-float getMmos (int meas, int cat) {
-
-  int i;
+float getMmos (off_t meas, int cat) {
+
+  off_t i;
   float value;
 
@@ -313,5 +312,6 @@
 int setMmos (Catalog *catalog, int PoorImages) {
 
-  int i, j, m, c, n, N, Nmax, mark, bad, Nfew, Nbad, Ncal, Nrel, Ngrid, Nsys;
+  off_t i, j, m, c, N, Nmax;
+  int n, mark, bad, Nfew, Nbad, Ncal, Nrel, Ngrid, Nsys;
   float Msys, Mrel, Mcal, Mgrid;
   double *list, *dlist, *Mlist, *dMlist;
@@ -392,5 +392,5 @@
       mark = (N < IMAGE_TOOFEW) || (N < IMAGE_GOOD_FRACTION*Nlist[i]);
       if (mark) {
-	fprintf (stderr, "marked image %s (%d), (%d < %d) || (%d < %f*%d)\n", image[imlist[i][0]].name, i, N, IMAGE_TOOFEW, N, IMAGE_GOOD_FRACTION, Nlist[i]);
+	fprintf (stderr, "marked image %s (%lld), (%lld < %d) || (%lld < %f*%lld)\n", image[imlist[i][0]].name, (long long) i, (long long) N, IMAGE_TOOFEW, (long long) N, IMAGE_GOOD_FRACTION, (long long) Nlist[i]);
 	mosaic[i].flags |= ID_IMAGE_FEW;
 	Nfew ++;
@@ -400,5 +400,5 @@
     }
     liststats (list, dlist, N, &stats);
-    if (PoorImages) fprintf (stderr, "Mmos: %f %f %d %d\n", stats.mean, stats.sigma, stats.Nmeas, N);
+    if (PoorImages) fprintf (stderr, "Mmos: %f %f %d %lld\n", stats.mean, stats.sigma, stats.Nmeas, (long long) N);
     mosaic[i].Mcal  = stats.mean;
     mosaic[i].dMcal = stats.sigma;
@@ -422,5 +422,6 @@
 StatType statsMosaicM (Catalog *catalog) {
 
-  int i, n;
+  off_t i;
+  int n;
   double *list, *dlist;
   StatType stats;
@@ -448,5 +449,5 @@
 StatType statsMosaicdM (Catalog *catalog) {
 
-  int i, n;
+  off_t i, n;
   double *list, *dlist;
   StatType stats;
@@ -476,5 +477,5 @@
 StatType statsMosaicN (Catalog *catalog) {
 
-  int i, j, m, c, n, N;
+  off_t i, j, m, c, n, N;
   double *list, *dlist;
   float Mcal, Mgrid, Mrel;
@@ -510,5 +511,5 @@
     n++;
   }
-  fprintf (stderr, "Nmosaic: %d, n: %d\n", Nmosaic, n);
+  fprintf (stderr, "Nmosaic: %lld, n: %lld\n", (long long) Nmosaic, (long long) n);
 
   liststats (list, dlist, n, &stats);
@@ -520,5 +521,5 @@
 StatType statsMosaicX (Catalog *catalog) {
 
-  int i, n;
+  off_t i, n;
   double *list, *dlist;
   StatType stats;
@@ -549,5 +550,5 @@
 void clean_mosaics () {
 
-  int i, N, mark, Nmark;
+  off_t i, N, mark, Nmark;
   double *mlist, *slist, *dlist;
   double MaxOffset, MedOffset, MaxScatter;
@@ -590,5 +591,5 @@
   }
 
-  fprintf (stderr, "%d mosaics marked poor\n", Nmark);
+  fprintf (stderr, "%lld mosaics marked poor\n", (long long) Nmark);
   initstats (STATMODE);
   free (mlist);
@@ -599,5 +600,5 @@
 void plot_mosaic_fields (Catalog *catalog) {
 
-  int i, j, m, c, N, ave, Nimage;
+  off_t i, j, m, c, N, ave, Nimage;
   double *xlist, *ylist;
   double Xmin, Xmax, Ymin, Ymax;
@@ -634,5 +635,5 @@
     }
   
-    sprintf (string, "Mosaic %d", i);
+    sprintf (string, "Mosaic %lld", (long long) i);
     plot_defaults (&graphdata);
     plot_list (&graphdata, xlist, ylist, N, string, NULL);
@@ -645,5 +646,5 @@
 void plot_mosaics () {
 
-  int i, bin;
+  off_t i, bin;
   double *xlist, *Mlist, *dlist;
   Graphdata graphdata;
@@ -694,7 +695,7 @@
 }
 
-int *SelectRefMosaic (Mosaic **refmosaic, int *Nimage) {
-
-  int i, Imax, Nmax;
+off_t *SelectRefMosaic (Mosaic **refmosaic, off_t *Nimage) {
+
+  off_t i, Imax, Nmax;
 
   Imax = 0;
Index: trunk/Ohana/src/relphot/src/StarOps.c
===================================================================
--- trunk/Ohana/src/relphot/src/StarOps.c	(revision 27392)
+++ trunk/Ohana/src/relphot/src/StarOps.c	(revision 27435)
@@ -7,5 +7,5 @@
 void initMrel (Catalog *catalog, int Ncatalog) {
 
-  int i, j;
+  off_t i, j;
   
   Nmax = 0;
@@ -20,5 +20,5 @@
 }  
 
-float getMrel (Catalog *catalog, int meas, int cat) {
+float getMrel (Catalog *catalog, off_t meas, int cat) {
 
   int ave;
@@ -34,5 +34,6 @@
 int setMrel (Catalog *catalog, int Ncatalog) {
 
-  int i, j, k, m, N, Nfew, Nsys, Nbad, Ncal, Nmos, Ngrid;
+  off_t j, k, m;
+  int i, N, Nfew, Nsys, Nbad, Ncal, Nmos, Ngrid;
   float Msys, Mcal, Mmos, Mgrid;
   StatType stats;
@@ -109,5 +110,6 @@
 int setMrelOutput (Catalog *catalog, int Ncatalog, int mark) {
 
-  int i, j, k, m, N, Nmax;
+  int i, N;
+  off_t j, k, m, Nmax;
   float Msys, Mcal, Mmos, Mgrid;
   double *list, *dlist;
@@ -173,5 +175,6 @@
 int setMave (Catalog *catalog, int Ncatalog) {
 
-  int i, j, k, m, Ns, Nsecfilt, N, Nmax, Nc;
+  off_t j, k, m, Nmax;
+  int i, Ns, Nsecfilt, N, Nc;
   float Msys;
   double *list, *dlist;
@@ -293,5 +296,6 @@
 int setMcalOutput (Catalog *catalog, int Ncatalog) {
 
-  int i, j, k, m;
+  int i;
+  off_t j, k, m;
   float Mcal, Mmos, Mgrid;
 
@@ -380,6 +384,7 @@
 void clean_measures (Catalog *catalog, int Ncatalog, int final) {
 
-  int i, j, k, m, N, Ndel, Nave, Nmax, image_bad, TOOFEW;
-  int *ilist;
+  off_t j, k, m, Nmax, Ndel, Nave;
+  int i, N, image_bad, TOOFEW;
+  off_t *ilist;
   double *tlist, *list, *dlist, Ns;
   float Msys, Mcal, Mmos, Mgrid;
@@ -396,5 +401,5 @@
   ALLOCATE (list, double, MAX (1, Nmax));
   ALLOCATE (dlist, double, MAX (1, Nmax));
-  ALLOCATE (ilist, int, Nmax);
+  ALLOCATE (ilist, off_t, Nmax);
   ALLOCATE (tlist, double, Nmax);
   
@@ -480,5 +485,5 @@
   }
   initstats (STATMODE);
-  if (VERBOSE) fprintf (stderr, "%d measures marked poor, %d total\n", Ndel, Nave);
+  if (VERBOSE) fprintf (stderr, "%lld measures marked poor, %lld total\n", (long long) Ndel, (long long) Nave);
   free (ilist);
   free (tlist);
@@ -487,5 +492,6 @@
 StatType statsStarN (Catalog *catalog, int Ncatalog) {
 
-  int i, j, k, m, n, N, Ntot;
+  off_t j, k, m, Ntot;
+  int i, n, N;
   double *list, *dlist;
   float Mcal, Mmos, Mgrid;
@@ -533,5 +539,6 @@
 StatType statsStarX (Catalog *catalog, int Ncatalog) {
 
-  int i, j, n, Ntot, Xm;
+  off_t j, Ntot;
+  int i, n, Xm;
   double *list, *dlist;
   StatType stats;
@@ -568,5 +575,6 @@
 StatType statsStarS (Catalog *catalog, int Ncatalog) {
 
-  int i, j, n, Ntot;
+  int i, n;
+  off_t j, Ntot;
   double *list, *dlist;
   float dM;
@@ -603,5 +611,6 @@
 void plot_stars (Catalog *catalog, int Ncatalog) {
 
-  int i, j, bin;
+  int i, bin;
+  off_t j;
   float dMrel;
   double *xlist, *Mlist;
@@ -634,5 +643,6 @@
 void plot_chisq (Catalog *catalog, int Ncatalog) {
 
-  int i, j, N, Ntotal, value;
+  off_t j, Ntotal;
+  int i, N, value;
   double *xlist, *ylist;
   Graphdata graphdata;
@@ -665,5 +675,6 @@
 void plot_star_coords (Catalog *catalog, int Ncatalog) {
 
-  int i, j, N;
+  int i;
+  off_t j, N;
   double *xlist, *ylist;
   double Xmin, Ymin, Xmax, Ymax;
Index: trunk/Ohana/src/relphot/src/bcatalog.c
===================================================================
--- trunk/Ohana/src/relphot/src/bcatalog.c	(revision 27392)
+++ trunk/Ohana/src/relphot/src/bcatalog.c	(revision 27435)
@@ -3,6 +3,7 @@
 int bcatalog (Catalog *subcatalog, Catalog *catalog) {
   
-  int i, j, offset, ecode;
-  int NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm;
+  off_t i, j, offset;
+  int ecode;
+  off_t NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm;
   float mag;
 
@@ -113,6 +114,6 @@
 
   if (VERBOSE) {
-    fprintf (stderr, "%d: using %d stars (%d measures) for catalog\n", i, 
-	     subcatalog[0].Naverage, subcatalog[0].Nmeasure);
+    fprintf (stderr, "%lld: using %lld stars (%lld measures) for catalog\n", (long long) i, 
+	     (long long) subcatalog[0].Naverage, (long long) subcatalog[0].Nmeasure);
   }
   return (TRUE);
Index: trunk/Ohana/src/relphot/src/load_images.c
===================================================================
--- trunk/Ohana/src/relphot/src/load_images.c	(revision 27392)
+++ trunk/Ohana/src/relphot/src/load_images.c	(revision 27435)
@@ -4,6 +4,6 @@
 
   Image     *image, *subset;
-  int        Nimage, Nsubset, Nchar;
-  int       *LineNumber;
+  off_t      Nimage, Nsubset, Nchar;
+  off_t     *LineNumber;
 
   SkyTable *sky = NULL;
@@ -40,5 +40,5 @@
 
   Image     *image;
-  int        Nimage, Nx, i;
+  off_t     Nimage, Nx, i;
   VTable    *vtable;
 
@@ -47,5 +47,5 @@
   vtable = &db[0].vtable;
 
-  gfits_scan (vtable[0].header, "NAXIS1", "%d", 1, &Nx);
+  gfits_scan (vtable[0].header, "NAXIS1", "%lld", 1, (long long *) &Nx);
   for (i = 0; i < Nimage; i++) {
     memcpy (vtable[0].buffer[i], &image[i], Nx);
Index: trunk/Ohana/src/relphot/src/plot_scatter.c
===================================================================
--- trunk/Ohana/src/relphot/src/plot_scatter.c	(revision 27392)
+++ trunk/Ohana/src/relphot/src/plot_scatter.c	(revision 27435)
@@ -3,5 +3,5 @@
 void plot_scatter (Catalog *catalog, int Ncatalog) {
 
-  int i, j, k, m, N, Ntot;
+  off_t i, j, k, m, N, Ntot;
   float Mrel, Mcal, Mmos, Mgrid;
   double *xlist, *ylist, *ilist;
Index: trunk/Ohana/src/relphot/src/relphot_objects.c
===================================================================
--- trunk/Ohana/src/relphot/src/relphot_objects.c	(revision 27392)
+++ trunk/Ohana/src/relphot/src/relphot_objects.c	(revision 27435)
@@ -3,5 +3,5 @@
 int relphot_objects () {
 
-  int i, j, k, m;
+  off_t i, j, k, m;
   int Nsecfilt;
 
Index: trunk/Ohana/src/relphot/src/select_images.c
===================================================================
--- trunk/Ohana/src/relphot/src/select_images.c	(revision 27392)
+++ trunk/Ohana/src/relphot/src/select_images.c	(revision 27435)
@@ -13,11 +13,11 @@
 } SkyRegionCoords;
 
-Image *select_images (SkyList *skylist, Image *timage, int Ntimage, int **LineNumber, int *Nimage) {
+Image *select_images (SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage) {
   
   Image *image;
-  int i, j, k, m, found, nimage, NIMAGE;
-  int InRange, ecode;
+  off_t i, j, k, m;
+  off_t *line_number, nimage, NIMAGE;
+  int InRange, ecode, found;
   double Ri[5], Di[5], Xi[5], Yi[5], dx, dy;
-  int *line_number;
   Coords tcoords;
   SkyRegionCoords *skycoords;
@@ -71,5 +71,5 @@
   NIMAGE = 100;
   ALLOCATE (image, Image, NIMAGE);
-  ALLOCATE (line_number, int, NIMAGE);
+  ALLOCATE (line_number, off_t, NIMAGE);
   
   // go through the complete list of images, selecting ones which overlap any region
@@ -146,13 +146,13 @@
 	NIMAGE += 100;
 	REALLOCATE (image, Image, NIMAGE);
-	REALLOCATE (line_number, int, NIMAGE);
+	REALLOCATE (line_number, off_t, NIMAGE);
       }
     }
   }
       
-  if (VERBOSE) fprintf (stderr, "found %d images\n", nimage);
+  if (VERBOSE) fprintf (stderr, "found %lld images\n", (long long) nimage);
 
   REALLOCATE (image, Image, MAX (nimage, 1));
-  REALLOCATE (line_number, int, MAX (nimage, 1));
+  REALLOCATE (line_number, off_t, MAX (nimage, 1));
   free (skycoords);
 
Index: trunk/Ohana/src/relphot/src/setExclusions.c
===================================================================
--- trunk/Ohana/src/relphot/src/setExclusions.c	(revision 27392)
+++ trunk/Ohana/src/relphot/src/setExclusions.c	(revision 27435)
@@ -3,5 +3,6 @@
 int setExclusions (Catalog *catalog, int Ncatalog) {
 
-  int i, j, k, m, Narea, Nnocal, Ngood, ecode;
+  off_t i, j, k, m, Narea, Nnocal, Ngood;
+  int ecode;
   Coords *coords;
   double r, d, x, y;
@@ -49,7 +50,7 @@
     }
   }
-  if (VERBOSE) fprintf (stderr, "%d measurements marked by area\n", Narea);
-  if (VERBOSE) fprintf (stderr, "%d measurements marked nocal\n", Nnocal);
-  if (VERBOSE) fprintf (stderr, "%d measurements kept for analysis\n", Ngood);
+  if (VERBOSE) fprintf (stderr, "%lld measurements marked by area\n",    (long long) Narea);
+  if (VERBOSE) fprintf (stderr, "%lld measurements marked nocal\n",      (long long) Nnocal);
+  if (VERBOSE) fprintf (stderr, "%lld measurements kept for analysis\n", (long long) Ngood);
   return (TRUE);
 }
Index: trunk/Ohana/src/relphot/src/setMrelFinal.c
===================================================================
--- trunk/Ohana/src/relphot/src/setMrelFinal.c	(revision 27392)
+++ trunk/Ohana/src/relphot/src/setMrelFinal.c	(revision 27435)
@@ -3,5 +3,6 @@
 void setMrelFinal (Catalog *catalog) {
 
-  int i, j, m, ecode;
+  off_t i, j, m;
+  int ecode;
 
   /* if we reset the catalog, reset all the current measurements */
@@ -39,5 +40,5 @@
 
   /* set catalog[0].found[i] = FALSE */
-  ALLOCATE (catalog[0].found, int, MAX (1, catalog[0].Naverage));
+  ALLOCATE (catalog[0].found, off_t, MAX (1, catalog[0].Naverage));
   for (i = 0; i < catalog[0].Naverage; i++) {
     catalog[0].found[i] = FALSE;
@@ -66,6 +67,7 @@
 void skip_measurements (Catalog *catalog, int pass) {
 
-  int i, k, m, ecode, d1, d2;
-  int Ntot, Ntry, Nkeep, Nskip;
+  off_t i, k, m;
+  int ecode;
+  off_t Ntot, Ntry, Nkeep, Nskip;
   float mag;
 
@@ -136,6 +138,6 @@
     }
   }
-  if (VERBOSE) fprintf (stderr, "pass %d, Ntot: %d, Ntry: %d, Nskip: %d, Nkeep: %d\n",
-			pass, Ntot, Ntry, Nskip, Nkeep);
+  if (VERBOSE) fprintf (stderr, "pass %d, Ntot: %lld, Ntry: %lld, Nskip: %lld, Nkeep: %lld\n",
+			pass, (long long) Ntot, (long long) Ntry, (long long) Nskip, (long long) Nkeep);
 }
 
Index: trunk/Ohana/src/relphot/src/sort.c
===================================================================
--- trunk/Ohana/src/relphot/src/sort.c	(revision 27392)
+++ 	(revision )
@@ -1,182 +1,0 @@
-# include "relphot.h"
-
-void sortA (double *X, int N) {
-
-  int l,j,ir,i;
-  double tX;
-  
-  if (N < 2) return;
-
-  l = N >> 1;
-  ir = N - 1;
-  for (;;) {
-    if (l > 0) {
-      l--;
-      tX = X[l];
-    }
-    else {
-      tX = X[ir];
-      X[ir] = X[0];
-      if (--ir == 0) {
-	X[0] = tX;
-	return;
-      }
-    }
-    i = l;
-    j = (l << 1) + 1;
-    while (j <= ir) {
-      if (j < ir && X[j] < X[j+1]) j++;
-      if (tX < X[j]) {
-	X[i] = X[j];
-	j += (i=j) + 1;
-      }
-      else j = ir + 1;
-    }
-    X[i] = tX;
-  }
-}
-
-void sortB (double *X, double *Y, int N) {
-
-  int l,j,ir,i;
-  double tX, tY;
-  
-  if (N < 2) return;
-
-  l = N >> 1;
-  ir = N - 1;
-  for (;;) {
-    if (l > 0) {
-      l--;
-      tX = X[l];
-      tY = Y[l];
-    }
-    else {
-      tX = X[ir];
-      X[ir] = X[0];
-      tY = Y[ir];
-      Y[ir] = Y[0];
-      if (--ir == 0) {
-	X[0] = tX;
-	Y[0] = tY;
-	return;
-      }
-    }
-    i = l;
-    j = (l << 1) + 1;
-    while (j <= ir) {
-      if (j < ir && X[j] < X[j+1]) j++;
-      if (tX < X[j]) {
-	X[i] = X[j];
-	Y[i] = Y[j];
-	j += (i=j) + 1;
-      }
-      else j = ir + 1;
-    }
-    X[i] = tX;
-    Y[i] = tY;
-  }
-}
-
-void sortC (double *X, double *Y, double *F1, double *F2, int N) {
-
-  int l,j,ir,i;
-  double tX, tY;
-  double t1, t2;
-  
-  if (N < 2) return;
-
-  l = N >> 1;
-  ir = N - 1;
-  for (;;) {
-    if (l > 0) {
-      l--;
-      tX = X[l];
-      tY = Y[l];
-      t1 = F1[l];
-      t2 = F2[l];
-    }
-    else {
-      tX = X[ir];
-      X[ir] = X[0];
-      tY = Y[ir];
-      Y[ir] = Y[0];
-      t1 = F1[ir];
-      F1[ir] = F1[0];
-      t2 = F2[ir];
-      F2[ir] = F2[0];
-      if (--ir == 0) {
-	X[0] = tX;
-	Y[0] = tY;
-	F1[0] = t1;
-	F2[0] = t2;
-	return;
-      }
-    }
-    i = l;
-    j = (l << 1) + 1;
-    while (j <= ir) {
-      if (j < ir && X[j] < X[j+1]) j++;
-      if (tX < X[j]) {
-	X[i] = X[j];
-	Y[i] = Y[j];
-	F1[i] = F1[j];
-	F2[i] = F2[j];
-	j += (i=j) + 1;
-      }
-      else j = ir + 1;
-    }
-    X[i] = tX;
-    Y[i] = tY;
-    F1[i] = t1;
-    F2[i] = t2;
-  }
-}
-
-void sortD (double *X, double *Y, double *Z, int N) {
-
-  int l,j,ir,i;
-  double tX, tY, tZ;
-  
-  if (N < 2) return;
-
-  l = N >> 1;
-  ir = N - 1;
-  for (;;) {
-    if (l > 0) {
-      l--;
-      tX = X[l];
-      tY = Y[l];
-      tZ = Z[l];
-    }
-    else {
-      tX = X[ir];
-      X[ir] = X[0];
-      tY = Y[ir];
-      Y[ir] = Y[0];
-      tZ = Z[ir];
-      Z[ir] = Z[0];
-      if (--ir == 0) {
-	X[0] = tX;
-	Y[0] = tY;
-	Z[0] = tZ;
-	return;
-      }
-    }
-    i = l;
-    j = (l << 1) + 1;
-    while (j <= ir) {
-      if (j < ir && X[j] < X[j+1]) j++;
-      if (tX < X[j]) {
-	X[i] = X[j];
-	Y[i] = Y[j];
-	Z[i] = Z[j];
-	j += (i=j) + 1;
-      }
-      else j = ir + 1;
-    }
-    X[i] = tX;
-    Y[i] = tY;
-    Z[i] = tZ;
-  }
-}
Index: trunk/Ohana/src/skycalc/src/misc.c
===================================================================
--- trunk/Ohana/src/skycalc/src/misc.c	(revision 27392)
+++ 	(revision )
@@ -1,314 +1,0 @@
-# include <ohana.h>
-# include <skycalc_internal.h>
-
-/***** convert [-]00:00:00 to 0.0000 ****/
-int dms_to_ddd (double *Value, char *string) {
-  
-  int valid, neg, status;
-  double tmp, value;
-  char *p1, *p2, *px;
-
-  valid = FALSE; 
-  neg = FALSE;
-  stripwhite (string);
-  p1 = string;
-  px = string + strlen(string);
-
-  if (string[0] == '-') { 
-    valid = TRUE; 
-    neg = TRUE;
-    p1 = &string[1];
-  }
-  if (string[0] == '+') { 
-    valid = TRUE; 
-    neg = FALSE;
-    p1 = &string[1];
-  }
-  if (isdigit(string[0])) { 
-    valid = TRUE;
-    p1 = &string[0];
-  }
-  if (!valid) { return (FALSE); }
-
-  status = 1;
-  tmp = strtod (p1, &p2);
-  if (p2 == p1) return (FALSE); /* entry not a number: +fred */
-  value = tmp;
-  if (p2 == px) goto escape;    /* entry only number: +1.0 */ 
-  p1 = p2 + 1;
-
-  tmp = strtod (p1, &p2);
-  if (p2 == p1) goto escape;    /* entry not a number: +1:fred */
-  status = 2;
-  value += tmp / 60.0;
-  if (p2 == px) goto escape;    /* entry only number: +1:1 */
-  p1 = p2 + 1;
-
-  tmp = strtod (p1, &p2);
-  if (p2 == p1) goto escape;    /* entry not a number: +1:1:fred */
-  value += tmp / 3600.0;
-
- escape:
-  if (neg) {
-    value *= -1;
-  }
-  *Value = value;
-
-  return (status);
-}
-
-/**********/
-int str_to_radec (double *ra, double *dec, char *str1, char *str2) {
-
-  double Ra, Dec;
-
-  *ra = *dec = 0;
-  switch (dms_to_ddd (&Ra, str1)) {
-  case 0:
-    fprintf (stderr, "syntax error in RA\n");
-    return (FALSE);
-  case 1:
-    break;
-  case 2:
-    Ra = Ra * 15;
-    break;
-  }
-  switch (dms_to_ddd (&Dec, str2)) {
-  case 0:
-    fprintf (stderr, "syntax error in DEC\n");
-    return (FALSE);
-  case 1:
-  case 2:
-    break;
-  }
-  *ra = Ra;
-  *dec = Dec;
-  return (TRUE);
-}
-
-# define FORMAT_DAYS    1
-# define FORMAT_HOURS   2
-# define FORMAT_MINUTES 3
-# define FORMAT_SECONDS 4
-# define FORMAT_JD      5
-# define FORMAT_DATE    6
-
-/**********/
-int chk_time (char *line) {
-
-  char *p1, *p2;
-  double tmp;
-  int mode;
-
-  p1 = line;
-  tmp = strtod (p1, &p2);
-  if (p2 == p1 + strlen (p1) - 1) {
-    if (*p2 == 'd') {
-      mode = FORMAT_DAYS;
-    }
-    if (*p2 == 'h') {
-      mode = FORMAT_HOURS;
-    }
-    if (*p2 == 'm') {
-      mode = FORMAT_MINUTES;
-    }
-    if (*p2 == 's') {
-      mode = FORMAT_SECONDS;
-    }
-    if (*p2 == 'j') {
-      mode = FORMAT_JD;
-    }
-  } else { 
-    mode = FORMAT_DATE;
-  }
-  return (mode);
-}
-
-/**********/
-int str_to_time (char *line, time_t *second) {
-  
-  struct timeval now;
-  double jd;
-
-  if (!strcasecmp (line, "NOW")) {
-    gettimeofday (&now, (struct timezone *) NULL);
-    *second = now.tv_sec;
-    return (TRUE);
-  }
-    
-  if (!strcasecmp (line, "TODAY")) {
-    gettimeofday (&now, (struct timezone *) NULL);
-    *second = 86400 * ((int)(now.tv_sec / 86400));
-    return (TRUE);
-  }
-    
-  switch (chk_time (line)) {
-  case 0:
-    return (FALSE);
-  case FORMAT_DAYS:
-    *second = strtod (line, 0) * 86400.0;
-    return (TRUE);
-  case FORMAT_HOURS:
-    *second = strtod (line, 0) * 3600.0;
-    return (TRUE);
-  case FORMAT_MINUTES:
-    *second = strtod (line, 0) * 60.0;
-    return (TRUE);
-  case FORMAT_SECONDS:
-    *second = strtod (line, 0);
-    return (TRUE);
-  case FORMAT_JD:
-    jd = strtod (line, 0);
-    *second = jd_to_sec (jd);
-    return (TRUE);
-  case FORMAT_DATE:
-    *second = date_to_sec (line);
-    return (TRUE);
-  }
-  return (FALSE);
-}
-
-/**********/
-int str_to_dtime (char *line, double *second) {
-  
-  switch (chk_time (line)) {
-  case 0:
-  case FORMAT_JD:
-  case FORMAT_DATE:
-    return (FALSE);
-  case FORMAT_DAYS:
-    *second = strtod (line, 0) * 86400.0;
-    return (TRUE);
-  case FORMAT_HOURS:
-    *second = strtod (line, 0) * 3600.0;
-    return (TRUE);
-  case FORMAT_MINUTES:
-    *second = strtod (line, 0) * 60.0;
-    return (TRUE);
-  case FORMAT_SECONDS:
-    *second = strtod (line, 0);
-    return (TRUE);
-  }
-  return (FALSE);
-}
-
-/**********/
-double sec_to_jd (time_t second) {
-
-  double jd;
-  
-  jd = second/86400.0 + 2440587.5;
-  return (jd);
-}
-
-/**********/
-time_t jd_to_sec (double jd) {
-
-  time_t second;
-
-  second = (jd - 2440587.5)*86400;
-  return (second);
-}
-
-/**********/
-char *sec_to_date (time_t second) {
-  
-  struct tm *gmt;
-  char *line;
-  
-  ALLOCATE (line, char, 64);
-  gmt   = gmtime (&second);
-  sprintf (line, "%4d/%02d/%02d,%02d:%02d:%02d", 1900+gmt[0].tm_year, gmt[0].tm_mon+1, gmt[0].tm_mday, gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 
-  return (line);
-
-}
-
-/***** date in format yyyy/mm/dd,hh:mm:ss *****/
-time_t date_to_sec (char *date) {
-  
-  time_t second;
-  double tmp, jd;
-  struct tm now;
-  char *p1, *p2, *px;
-  
-  p1 = date;
-  px = date + strlen(date);
-  bzero (&now, sizeof(now));
-
-  tmp = strtod (p1, &p2);
-  if (p2 == p1) goto escape;
-  now.tm_year = tmp;
-  if (now.tm_year > 1000) now.tm_year -= 1900;
-  if (now.tm_year <   50) now.tm_year += 100;
-  if (p2 == px) goto escape;  
-  p1 = p2 + 1;
-
-  tmp = strtod (p1, &p2);
-  if (p2 == p1) goto escape;
-  now.tm_mon = tmp - 1; /* mon runs from 0 - 11 */
-  if (p2 == px) goto escape;  
-  p1 = p2 + 1;
-
-  tmp = strtod (p1, &p2);
-  if (p2 == p1) goto escape;
-  now.tm_mday = tmp;
-  if (p2 == px) goto escape;  
-  p1 = p2 + 1;
-
-  tmp = strtod (p1, &p2);
-  if (p2 == p1) goto escape;
-  p1 = p2 + 1;
-  now.tm_hour = tmp;
-  if (p2 == px) goto escape;  
-
-  tmp = strtod (p1, &p2);
-  if (p2 == p1) goto escape;
-  now.tm_min = tmp;
-  if (p2 == px) goto escape;  
-  p1 = p2 + 1;
-
-  tmp = strtod (p1, &p2);
-  if (p2 == p1) goto escape;
-  now.tm_sec = tmp;
-  if (p2 == px) goto escape;  
-  p1 = p2 + 1;
-
- escape:
-  jd = now.tm_mday - 32075 + (int)(1461*(1900 + now.tm_year + 4800 + (int)(((now.tm_mon+1)-14)/12))/4)
-    + (int)(367*((now.tm_mon+1) - 2 - (int)(((now.tm_mon+1) - 14)/12)*12)/12)
-    - (int)(3*(int)((1900 + now.tm_year + 4900 + (int)(((now.tm_mon+1) - 14)/12))/100)/4) - 0.5;
-  
-  second = (jd - 2440587.5)*86400 + 3600.0*now.tm_hour + now.tm_min*60.0 + now.tm_sec;
-
-  return (second);
-}
-
-
-/* times may be in forms as:
-   20040200450s (N seconds since 1970.0)
-   2440900.232j (julian date)
-   99/02/23,03:22:18 (date string)
-   (separators may be anything except space, +, -)
-   99:02:15:12:23:30
-   99:02:15:12h23m30s
-   */
-
-
-/* fseek with timeout - 0.5 sec */
-int Fseek (FILE *f, long offset, int whence) {
-
-  int status, k;
-
-  status = fseek (f, offset, whence);
-  if (status == -1) {
-    int k;
-    /* fprintf (stderr, "problem seeking position: %d\n", errno); */
-    for (k = 0; (k < 10) && ((status = fseek (f, 0, SEEK_SET)) == -1); k++) usleep (50000);
-    if (status == -1) {
-      /* fprintf (stderr, "ERROR: serious problem seeking position: %d\n", errno); */
-      /* clear lock at this point? */
-      return (0);
-    }
-  }
-  return (1);
-}
Index: trunk/Ohana/src/tools/src/ckfits.c
===================================================================
--- trunk/Ohana/src/tools/src/ckfits.c	(revision 27392)
+++ trunk/Ohana/src/tools/src/ckfits.c	(revision 27435)
@@ -4,5 +4,6 @@
 int main (int argc, char **argv) {
 
-  int i, Nbytes, nbytes, Ndata, Ntotal, nskip, status;
+  off_t i, Nbytes, nbytes, Ndata, Ntotal, nskip;
+  int status;
   Header header;
   FILE *f;
@@ -26,5 +27,5 @@
 
   nbytes = Ntotal - Ndata;
-  nskip = Ndata + header.size;
+  nskip = Ndata + header.datasize;
 
   f = fopen (argv[1], "r");
@@ -35,5 +36,5 @@
 
   ALLOCATE (buffer, char, MAX (nbytes, 1));
-  fseek (f, nskip, SEEK_SET);
+  fseeko (f, nskip, SEEK_SET);
   Nbytes = fread (buffer, 1, nbytes, f);
   fclose (f);
Index: trunk/Ohana/src/tools/src/fhead.c
===================================================================
--- trunk/Ohana/src/tools/src/fhead.c	(revision 27392)
+++ trunk/Ohana/src/tools/src/fhead.c	(revision 27435)
@@ -5,5 +5,6 @@
 
   int N, Extend, Nextend, status;
-  int i, j, nbytes;
+  int i, j;
+  off_t nbytes;
   Header head;
   char *p;
@@ -29,5 +30,5 @@
     if (!status) continue;
 
-    for (j = 79; j < head.size; j+= 80) {
+    for (j = 79; j < head.datasize; j+= 80) {
       head.buffer[j] = 10;
     }
Index: trunk/Ohana/src/tools/src/fields.c
===================================================================
--- trunk/Ohana/src/tools/src/fields.c	(revision 27392)
+++ trunk/Ohana/src/tools/src/fields.c	(revision 27435)
@@ -22,6 +22,6 @@
   Header header;
   char filename[1000], *CCDKeyword, *Extname, extname[80];
-  int N, Nbytes, Extnum, Nextend, status, GotFile, GotField, GotExtension;
-
+  int N, Extnum, Nextend, status, GotFile, GotField, GotExtension;
+  off_t Nbytes;
   regex_t preg;
 
@@ -97,5 +97,5 @@
     
 	Nbytes = gfits_data_size (&header);
-	fseek (f, Nbytes, SEEK_CUR);
+	fseeko (f, Nbytes, SEEK_CUR);
 	Nextend ++;
 
Index: trunk/Ohana/src/tools/src/fits_insert.c
===================================================================
--- trunk/Ohana/src/tools/src/fits_insert.c	(revision 27392)
+++ trunk/Ohana/src/tools/src/fits_insert.c	(revision 27435)
@@ -7,6 +7,7 @@
 int main (int argc, char **argv) {
 
-  int i, N, status, EXTNUM, Nbytes, skip, Delete, DeleteStart, DeleteStop;
-  int Nreserved, start_size;
+  off_t i, skip, Nbytes, start_size;
+  int N, status, EXTNUM, Delete, DeleteStart, DeleteStop;
+  int Nreserved;
   char *p, keyword[16], line[256];
   FILE *f;
@@ -62,6 +63,6 @@
       exit (1);
   }
-  start_size = header.size;
-  skip = Nbytes - header.size;
+  start_size = header.datasize;
+  skip = Nbytes - header.datasize;
 
   /* open header data file */
@@ -116,5 +117,5 @@
     /* check that the line does not already exist */
     p = (char *) NULL;
-    for (i = 0; (i < header.size) && (p == (char *) NULL) ; i+= FT_LINE_LENGTH) {
+    for (i = 0; (i < header.datasize) && (p == (char *) NULL) ; i+= FT_LINE_LENGTH) {
       if (!strncmp (&header.buffer[i], line, 80)) {
 	p = &header.buffer[i];
@@ -126,5 +127,5 @@
     p = (char *) NULL;
     Nreserved = strlen (reserved);
-    for (i = 0; (i < header.size) && (p == (char *) NULL) ; i+= FT_LINE_LENGTH) {
+    for (i = 0; (i < header.datasize) && (p == (char *) NULL) ; i+= FT_LINE_LENGTH) {
       if (!strncmp (&header.buffer[i], "END     ", 8)) break;
       if (!strncmp (&header.buffer[i], reserved, Nreserved)) {
@@ -142,5 +143,5 @@
 	exit (1);
       }
-      if (p - header.buffer + 80 == header.size) {
+      if (p - header.buffer + 80 == header.datasize) {
 	fprintf (stderr, "no free space in block, can't insert keyword\n");
 	exit (1);
@@ -161,5 +162,5 @@
   */
 
-  if (header.size != start_size) {
+  if (header.datasize != start_size) {
     fprintf (stderr, "header changed size: should not happen!\n");
     exit (1);
@@ -172,7 +173,7 @@
   }
 
-  fseek (f, skip, SEEK_SET);
-  status = fwrite (header.buffer, 1, header.size, f);
-  if (status != header.size) {
+  fseeko (f, skip, SEEK_SET);
+  status = fwrite (header.buffer, 1, header.datasize, f);
+  if (status != header.datasize) {
     fprintf (stderr, "failed to write data to image header\n");
     exit (1);
Index: trunk/Ohana/src/tools/src/ftable.c
===================================================================
--- trunk/Ohana/src/tools/src/ftable.c	(revision 27392)
+++ trunk/Ohana/src/tools/src/ftable.c	(revision 27435)
@@ -8,11 +8,10 @@
 void list_extnames (char *file);
 void print_layout (Header *header);
-int   ByteSwap (char *ptr, int size, int nitems, char *type);
 int Binary;
 
 int main (int argc, char **argv) {
 
-  int i, N, Nx, Ny, Nbytes, Nread;
-  int Nextend, Column, Row, ListExtname, Layout;
+  off_t i, Nx, Ny, Nbytes, Nread, Row;
+  int N, Nextend, Column, ListExtname, Layout;
   char *Extname, *Colname, *line, ttype[80];
   FTable table;
@@ -94,8 +93,8 @@
     exit (1);
   }
-  table.size = Nbytes;
-
-  gfits_scan (table.header, "NAXIS1",  "%d", 1, &Nx);
-  gfits_scan (table.header, "NAXIS2",  "%d", 1, &Ny);
+  table.datasize = Nbytes;
+
+  gfits_scan (table.header, "NAXIS1",  "%lld", 1, (long long *) &Nx);
+  gfits_scan (table.header, "NAXIS2",  "%lld", 1, (long long *) &Ny);
 
   /* print a column */
@@ -122,8 +121,9 @@
 char *print_table_row (char *row, Header *header) {
   
-  int i, j, Nx, Nfields, Nbytes, Nvals, Oout, Oin;
+  off_t Nx;
+  int i, j, Nfields, Nbytes, Nvals, Oout, Oin;
   char field[16], type[16], format[16], *line;
 
-  gfits_scan (header, "NAXIS1",  "%d", 1, &Nx);
+  gfits_scan (header, "NAXIS1",  "%lld", 1, (long long *) &Nx);
   gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
 
@@ -160,5 +160,6 @@
 
   FILE *f;
-  int i, Naxis, Nelem, Ncomp, extend, Nbytes, status;
+  off_t Nbytes, Nelem;
+  int i, Naxis, Ncomp, extend, status;
   char extname[82], exttype[82], axisname[32];
   Header header;
@@ -169,13 +170,4 @@
     exit (1);
   }
-
-  /* 
-     if (!gfits_fread_header (f, &header)) {
-     fprintf (stderr, "can't read header from %s\n", file);
-     exit (1);
-     }
-     Nbytes = gfits_data_size (&header);
-     fseek (f, Nbytes, SEEK_CUR);
-  */
 
   fprintf (stdout, "%-30s %-15s NAXIS NAXIS(i)...\n", "extname", "datatype"); 
@@ -217,9 +209,9 @@
     for (i = 0; i < Naxis; i++) {
       sprintf (axisname, "NAXIS%d", i+1);
-      status = gfits_scan (&header, axisname,  "%d", 1, &Nelem);
+      status = gfits_scan (&header, axisname,  "%lld", 1, (long long *) &Nelem);
       if (!status) {
 	fprintf (stderr, "missing %s\n", axisname);
       }
-      fprintf (stdout, " %7d", Nelem);
+      fprintf (stdout, " %7lld", (long long) Nelem);
     }
     fprintf (stdout, "\n");
@@ -228,5 +220,5 @@
     if (Ncomp == 0) {
       extend = FALSE;
-      gfits_scan (&header, "EXTEND", "%t", 1, &extend);
+      gfits_scan_alt (&header, "EXTEND", "%t", 1, &extend);
       if (!extend) {
 	fprintf (stderr, "no extensions listed in file\n");
@@ -235,5 +227,5 @@
 
     Nbytes = gfits_data_size (&header);
-    fseek (f, Nbytes, SEEK_CUR);
+    fseeko (f, Nbytes, SEEK_CUR);
 
     Ncomp ++;
@@ -245,5 +237,6 @@
 FILE *load_extension (char *file, int Nextend, char *Extname, Header *header) {
 
-  int i, extend, Nbytes;
+  off_t Nbytes;
+  int i, extend;
   char extname[82];
   FILE *f;
@@ -264,5 +257,5 @@
   /* check for existence of extensions */
   extend = FALSE;
-  gfits_scan (header, "EXTEND", "%t", 1, &extend);
+  gfits_scan_alt (header, "EXTEND", "%t", 1, &extend);
   if (!extend) {
     fprintf (stderr, "no extensions listed in file\n");
@@ -271,5 +264,5 @@
   /* skip first data array */
   Nbytes = gfits_data_size (header);
-  fseek (f, Nbytes, SEEK_CUR);
+  fseeko (f, Nbytes, SEEK_CUR);
 
   /* search for extension of interest */
@@ -281,5 +274,5 @@
 
     Nbytes = gfits_data_size (header);
-    fseek (f, Nbytes, SEEK_CUR);
+    fseeko (f, Nbytes, SEEK_CUR);
     gfits_free_header (header);
   }
@@ -292,5 +285,6 @@
 void print_column (FTable *table, int Column, char *Colname) {
   
-  int i, j, Nfields, Nstart, Nv, Nb, Nx, Ny;
+  off_t Nx, Ny;
+  int i, j, Nfields, Nstart, Nv, Nb;
   Header *header;
   char format[16], field[16], type[16], *line, *data;
@@ -300,6 +294,6 @@
 
   gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
-  gfits_scan (header, "NAXIS1",  "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1",  "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2",  "%lld", 1, (long long *) &Ny);
 
   if (Colname != (char *) NULL) {
@@ -364,5 +358,5 @@
 	  if (!strcmp (type, "int64_t")) {
 	    memcpy (line, &data[i*Nv*Nb + Nb*j], Nb);
-	    fprintf (stdout, "%d ", *(int64_t*)line);
+	    fprintf (stdout, "%lld ", (long long) *(int64_t*)line);
 	  }
 	  if (!strcmp (type, "float")) {
@@ -394,5 +388,5 @@
     sprintf (field, "TTYPE%d", i);
     gfits_scan (header, field, "%s", 1, type);
-    gfits_scan (header, field, "%C", 1, comment);
+    gfits_scan_alt (header, field, "%C", 1, comment);
     sprintf (field, "TFORM%d", i);
     gfits_scan (header, field, "%s", 1, format);
Index: trunk/Ohana/src/tools/src/mefhead.c
===================================================================
--- trunk/Ohana/src/tools/src/mefhead.c	(revision 27392)
+++ trunk/Ohana/src/tools/src/mefhead.c	(revision 27435)
@@ -5,5 +5,6 @@
 
   struct stat filestat;
-  int NEXTEND, Nextend, Nmatrix, status;
+  int NEXTEND, Nextend, status;
+  off_t Nmatrix;
   Header header;
   FILE *f, *g;
@@ -43,5 +44,5 @@
   /* skip matrix */
   Nmatrix = gfits_data_size (&header);
-  fseek (g, Nmatrix, SEEK_CUR);
+  fseeko (g, Nmatrix, SEEK_CUR);
 
   /* write PHU */
@@ -65,5 +66,5 @@
     /* skip matrix */
     Nmatrix = gfits_data_size (&header);
-    fseek (g, Nmatrix, SEEK_CUR);
+    fseeko (g, Nmatrix, SEEK_CUR);
     
     /* write header */
Index: trunk/Ohana/src/tools/src/mktemp.c
===================================================================
--- trunk/Ohana/src/tools/src/mktemp.c	(revision 27392)
+++ trunk/Ohana/src/tools/src/mktemp.c	(revision 27435)
@@ -5,4 +5,6 @@
 # define FALSE 0
 # define TRUE 1
+
+void usage(void);
 
 int main (int argc, char **argv) {
@@ -95,5 +97,5 @@
 
   if (make_directory) {
-    if (mkdtemp (template) == -1) {
+    if (mkdtemp (template) == NULL) {
       if (!fail_silently) fprintf (stderr, "failed to make temp file from %s\n", template);
       exit (1);
@@ -111,5 +113,5 @@
 }
  
-usage() {
+void usage(void) {
   fprintf (stderr, "Usage: mktemp [-V] | [-dqtu] [-p prefix] [template]\n");
   exit (1);
Index: trunk/Ohana/src/uniphot/include/uniphot.h
===================================================================
--- trunk/Ohana/src/uniphot/include/uniphot.h	(revision 27392)
+++ trunk/Ohana/src/uniphot/include/uniphot.h	(revision 27435)
@@ -93,14 +93,14 @@
 void          wcatalog           PROTO((Catalog *catalog));
 void          wimages            PROTO((Image *image, int Nimage));
-void check_permissions (char *basefile);
-void lock_image_db (FITS_DB *db, char *filename);
-void unlock_image_db (FITS_DB *db);
-void create_image_db (FITS_DB *db);
-void set_db (FITS_DB *in);
-int Shutdown (char *format, ...);
-void TrapSignal (int sig);
-void SetProtect (int mode);
-int SetSignals (void);
-int subset_images (FITS_DB *db);
-void update (FITS_DB *db, Group *sgroup, int Nsgroup);
-void sort_time (unsigned int *value, int N);
+void 	      check_permissions  PROTO((char *basefile));
+void 	      lock_image_db 	 PROTO((FITS_DB *db, char *filename));
+void	      unlock_image_db 	 PROTO((FITS_DB *db));
+void	      create_image_db 	 PROTO((FITS_DB *db));
+void	      set_db 		 PROTO((FITS_DB *in));
+int 	      Shutdown 		 PROTO((char *format, ...) OHANA_FORMAT(printf, 1, 2) );
+void 	      TrapSignal 	 PROTO((int sig));
+void 	      SetProtect 	 PROTO((int mode));
+int 	      SetSignals 	 PROTO((void));
+int 	      subset_images 	 PROTO((FITS_DB *db));
+void 	      update 		 PROTO((FITS_DB *db, Group *sgroup, int Nsgroup));
+void 	      sort_time 	 PROTO((unsigned int *value, int N));
Index: trunk/Ohana/src/uniphot/src/find_image_sgroups.c
===================================================================
--- trunk/Ohana/src/uniphot/src/find_image_sgroups.c	(revision 27392)
+++ trunk/Ohana/src/uniphot/src/find_image_sgroups.c	(revision 27435)
@@ -3,5 +3,6 @@
 Group *find_image_sgroups (FITS_DB *db, ImageLink **Imlink, int *Nsgroup) {
 
-  int i, j, Nimage, Ngroup, Nentry, NENTRY;
+  off_t i, Nimage;
+  int j, Ngroup, Nentry, NENTRY;
   double r, d, x, y, radius;
   Group *group;
Index: trunk/Ohana/src/uniphot/src/find_image_tgroups.c
===================================================================
--- trunk/Ohana/src/uniphot/src/find_image_tgroups.c	(revision 27392)
+++ trunk/Ohana/src/uniphot/src/find_image_tgroups.c	(revision 27435)
@@ -4,5 +4,6 @@
 
   char *start, *stop;
-  int i, j, Nimage, Ngroup, NGROUP, Nentry, NENTRY;
+  int j, Ngroup, NGROUP, Nentry, NENTRY;
+  off_t i, Nimage;
   unsigned int *time, *tmin, *tmax;
   Group *group;
Index: trunk/Ohana/src/uniphot/src/subset_images.c
===================================================================
--- trunk/Ohana/src/uniphot/src/subset_images.c	(revision 27392)
+++ trunk/Ohana/src/uniphot/src/subset_images.c	(revision 27435)
@@ -3,6 +3,6 @@
 int subset_images (FITS_DB *db) {
 
-  int    i, Nimage, equiv;
-  int    Nkeep, *keep;
+  off_t i, Nimage, Nkeep, *keep;
+  int equiv;
   Image *image;
 
@@ -11,5 +11,5 @@
 
   Nkeep = 0;
-  ALLOCATE (keep, int, Nimage);
+  ALLOCATE (keep, off_t, Nimage);
 
   /* mark images to be calibrated */
Index: trunk/Ohana/src/uniphot/src/update.c
===================================================================
--- trunk/Ohana/src/uniphot/src/update.c	(revision 27392)
+++ trunk/Ohana/src/uniphot/src/update.c	(revision 27435)
@@ -4,5 +4,6 @@
 void update (FITS_DB *db, Group *sgroup, int Nsgroup) {
 
-  int i, j, status, Nmin, Nimage;
+  off_t i, Nimage;
+  int j, status, Nmin;
   char line[256];
   glob_t pglob;
