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
