Index: trunk/Ohana/src/relphot/include/relphot.h
===================================================================
--- trunk/Ohana/src/relphot/include/relphot.h	(revision 26154)
+++ 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 26154)
+++ 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 26154)
+++ 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 26154)
+++ 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 26154)
+++ 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 26154)
+++ 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 26154)
+++ 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 26154)
+++ 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 26154)
+++ 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 26154)
+++ 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 26154)
+++ 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 26154)
+++ 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 26154)
+++ 	(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;
-  }
-}
