Index: /trunk/Ohana/Makefile
===================================================================
--- /trunk/Ohana/Makefile	(revision 3465)
+++ /trunk/Ohana/Makefile	(revision 3466)
@@ -80,5 +80,5 @@
 	mkdir -p $(LINC)
 	mkdir -p $(LLIB)
-	for i in $(LIBS-$(ARCH)); do make $$i.install; done
+	for i in $(LIBS-$(ARCH)); do make $$i.install || exit; done
 
 bins: 
Index: /trunk/Ohana/src/addrefs/include/addstar.h
===================================================================
--- /trunk/Ohana/src/addrefs/include/addstar.h	(revision 3465)
+++ /trunk/Ohana/src/addrefs/include/addstar.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 # include <signal.h>
 
Index: /trunk/Ohana/src/addspphot/include/addstar.h
===================================================================
--- /trunk/Ohana/src/addspphot/include/addstar.h	(revision 3465)
+++ /trunk/Ohana/src/addspphot/include/addstar.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 # include <signal.h>
 
Index: /trunk/Ohana/src/addstar/include/addstar.h
===================================================================
--- /trunk/Ohana/src/addstar/include/addstar.h	(revision 3465)
+++ /trunk/Ohana/src/addstar/include/addstar.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 # include <signal.h>
 # include <sys/time.h>
@@ -71,4 +71,5 @@
 double Latitude, SiderealTime;
 int    VERBOSE;
+int    FITS_INPUT;
 int    SKIP_MISSED;
 int    XOVERSCAN, YOVERSCAN;
@@ -215,2 +216,6 @@
 GSCRegion *gregion_patch (GSCRegion *patch, int *nregions);
 int ConvertStars (StarData *data, int size, int nitems);
+int dump_rawstars (Stars *stars, int Nstars);
+Stars *rfits (FILE *f, int *nstars);
+Stars *rtext (FILE *f, int *nstars);
+
Index: /trunk/Ohana/src/addstar/src/args.c
===================================================================
--- /trunk/Ohana/src/addstar/src/args.c	(revision 3465)
+++ /trunk/Ohana/src/addstar/src/args.c	(revision 3466)
@@ -90,4 +90,9 @@
     remove_argument (N, &argc, argv);
     fits_free_header (&header);
+  }
+  FITS_INPUT = FALSE;
+  if ((N = get_argument (argc, argv, "-fits"))) {
+    FITS_INPUT = TRUE;
+    remove_argument (N, &argc, argv);
   }
   
Index: /trunk/Ohana/src/addstar/src/gstars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gstars.c	(revision 3465)
+++ /trunk/Ohana/src/addstar/src/gstars.c	(revision 3466)
@@ -4,14 +4,10 @@
 
   FILE *f;
+  int j, N, extend, Nbytes;
+  int itmp, hour, min;
+  char *c, photcode[64], line[80];
+  double tmp, sec, dMs;
+  Stars *stars, *rdstars;
   Header header;
-  int j, N, Ninstar, extend;
-  int nbytes, Nbytes;
-  Stars *stars, *rdstars;
-  char *buffer, *c, *c2, photcode[64];
-  double tmp;
-  int done, doneread, Nskip, Nextra, itmp;
-  int hour, min;
-  double sec, dMs;
-  char line[80];
 
   if (!fits_read_header (file, &header)) {
@@ -131,6 +127,5 @@
 
   /* find expected number of stars */
-  fits_scan (&header, "NSTARS", "%d", 1, &image[0].nstar);
-  if (image[0].nstar == 0) {
+  if (!fits_scan (&header, "NSTARS", "%d", 1, &image[0].nstar)) {
     fprintf (stderr, "ERROR: can't get NSTARS from header\n");
     exit (1);
@@ -166,7 +161,5 @@
   fseek (f, header.size, SEEK_SET); 
 
-  extend = FALSE;
-  fits_scan (&header, "EXTEND",  "%t", 1, &extend);
-  if (extend) {
+  if (FITS_INPUT) {
     Nbytes = fits_matrix_size (&header); 
     fseek (f, Nbytes, SEEK_CUR); 
Index: /trunk/Ohana/src/addstar/src/rfits.c
===================================================================
--- /trunk/Ohana/src/addstar/src/rfits.c	(revision 3465)
+++ /trunk/Ohana/src/addstar/src/rfits.c	(revision 3466)
@@ -3,9 +3,15 @@
 Stars *rfits (FILE *f, int *nstars) {
 
-  int i, N, Nx, Ny, Nstars;
+  int i, Nx, Ny, Nstars;
   Header theader;
   FTable table;
   Stars *stars;
   StarData *stardata;
+
+  /* if no stars, no table */
+  if (*nstars == 0) {
+    *nstars = 0;
+    return (NULL);
+  }
 
   /* init & load in table data */
@@ -40,4 +46,5 @@
 escape:
   fprintf (stderr, "error reading file\n");
-  exit (1);
+  *nstars = 0;
+  return (NULL);
 }
Index: /trunk/Ohana/src/addstar/src/rtext.c
===================================================================
--- /trunk/Ohana/src/addstar/src/rtext.c	(revision 3465)
+++ /trunk/Ohana/src/addstar/src/rtext.c	(revision 3466)
@@ -20,5 +20,5 @@
   ALLOCATE (stars, Stars, *nstars);
 
-  while (1) {
+  while (N < *nstars) {
     /* load next data block */
     Nbytes = BYTES_STAR * BLOCK - Nextra;
@@ -62,5 +62,5 @@
     Ninstar = nbytes / BYTES_STAR;
     Nextra = nbytes % BYTES_STAR;
-    for (j = 0; j < Ninstar; j++, N++) {
+    for (j = 0; (j < Ninstar) && (N < *nstars); j++, N++) {
       dparse (&stars[N].X,  1, &buffer[j*BYTES_STAR]);
       dparse (&stars[N].Y,  2, &buffer[j*BYTES_STAR]);
@@ -81,3 +81,5 @@
     }
   }
+  *nstars = N;
+  return (stars);
 }
Index: /trunk/Ohana/src/addusno/include/addstar.h
===================================================================
--- /trunk/Ohana/src/addusno/include/addstar.h	(revision 3465)
+++ /trunk/Ohana/src/addusno/include/addstar.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 /* global variables set in parameter file */
Index: /trunk/Ohana/src/addusno/include/addusno.h
===================================================================
--- /trunk/Ohana/src/addusno/include/addusno.h	(revision 3465)
+++ /trunk/Ohana/src/addusno/include/addusno.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 /* global variables set in parameter file */
Index: /trunk/Ohana/src/delstar/include/addstar.h
===================================================================
--- /trunk/Ohana/src/delstar/include/addstar.h	(revision 3465)
+++ /trunk/Ohana/src/delstar/include/addstar.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 /* global variables set in parameter file */
Index: /trunk/Ohana/src/delstar/include/delstar.h
===================================================================
--- /trunk/Ohana/src/delstar/include/delstar.h	(revision 3465)
+++ /trunk/Ohana/src/delstar/include/delstar.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 # include <signal.h>
 
Index: /trunk/Ohana/src/fixcat/include/markstar.h
===================================================================
--- /trunk/Ohana/src/fixcat/include/markstar.h	(revision 3465)
+++ /trunk/Ohana/src/fixcat/include/markstar.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 int    VERBOSE;
Index: /trunk/Ohana/src/gastro/include/gastro.h
===================================================================
--- /trunk/Ohana/src/gastro/include/gastro.h	(revision 3465)
+++ /trunk/Ohana/src/gastro/include/gastro.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 double DEFAULT_RADIUS;
Index: /trunk/Ohana/src/gastro2/include/gastro2.h
===================================================================
--- /trunk/Ohana/src/gastro2/include/gastro2.h	(revision 3465)
+++ /trunk/Ohana/src/gastro2/include/gastro2.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 typedef struct {
Index: /trunk/Ohana/src/gastro2/src/gstars2.c
===================================================================
--- /trunk/Ohana/src/gastro2/src/gstars2.c	(revision 3465)
+++ /trunk/Ohana/src/gastro2/src/gstars2.c	(revision 3466)
@@ -5,11 +5,8 @@
 void gstars (char *filename, CmpCatalog *Target) {
 
-  int i, N, Nstars, nstars, Ninstar;
-  int nbytes, Nbytes;
-  char line[80], *buffer;
-  double dmag, type, det;
+  int Nstars;
+  char line[80];
+  double det;
   int NX, NY, FoundAstrom, extend;
-
-  FILE *f;
   StarData *stars;
 
Index: /trunk/Ohana/src/getstar/include/getstar.h
===================================================================
--- /trunk/Ohana/src/getstar/include/getstar.h	(revision 3465)
+++ /trunk/Ohana/src/getstar/include/getstar.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 # include <signal.h>
 
Index: /trunk/Ohana/src/imclean/include/imclean.h
===================================================================
--- /trunk/Ohana/src/imclean/include/imclean.h	(revision 3465)
+++ /trunk/Ohana/src/imclean/include/imclean.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 enum {DOPHOT, CHAD, SEXTRACT};
@@ -77,2 +77,4 @@
 void help ();
 void args (int argc, char **argv);
+int ConvertStars (Stars *data, int size, int nitems);
+void wfits (char *filename, Stars *stars, int Nstars, Header *header);
Index: /trunk/Ohana/src/imclean/src/wfits.c
===================================================================
--- /trunk/Ohana/src/imclean/src/wfits.c	(revision 3465)
+++ /trunk/Ohana/src/imclean/src/wfits.c	(revision 3466)
@@ -1,8 +1,6 @@
 # include "imclean.h"
-int ConvertStars (Stars *data, int size, int nitems);
 
 void wfits (char *filename, Stars *stars, int Nstars, Header *header) {
 
-  int i;
   Matrix matrix;
   Header theader;
Index: /trunk/Ohana/src/imregister/include/detrend.h
===================================================================
--- /trunk/Ohana/src/imregister/include/detrend.h	(revision 3465)
+++ /trunk/Ohana/src/imregister/include/detrend.h	(revision 3466)
@@ -77,4 +77,5 @@
 int SaveEntry (char *input, DetReg *newdata, char *ID);
 
+void init_db ();
 int load_db ();
 int save_db ();
Index: /trunk/Ohana/src/imregister/include/imreg.h
===================================================================
--- /trunk/Ohana/src/imregister/include/imreg.h	(revision 3465)
+++ /trunk/Ohana/src/imregister/include/imreg.h	(revision 3466)
@@ -75,4 +75,5 @@
 RegImage *get_images (int *N);
 int set_images (RegImage *new, int Nnew);
+void init_db ();
 int load_db ();
 int save_db ();
Index: /trunk/Ohana/src/imregister/include/imregister.h
===================================================================
--- /trunk/Ohana/src/imregister/include/imregister.h	(revision 3465)
+++ /trunk/Ohana/src/imregister/include/imregister.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 # include <errno.h>
 # include <time.h>
Index: /trunk/Ohana/src/imregister/include/photreg.h
===================================================================
--- /trunk/Ohana/src/imregister/include/photreg.h	(revision 3465)
+++ /trunk/Ohana/src/imregister/include/photreg.h	(revision 3466)
@@ -30,4 +30,5 @@
 int set_images (PhotPars *new, int Nnew);
 int load_db ();
+void init_db ();
 int save_db ();
 int update_db (int *match, int Nmatch);
Index: /trunk/Ohana/src/imregister/photreg/db.c
===================================================================
--- /trunk/Ohana/src/imregister/photreg/db.c	(revision 3465)
+++ /trunk/Ohana/src/imregister/photreg/db.c	(revision 3466)
@@ -1,4 +1,7 @@
 # include "imregister.h"
 # include "photreg.h"
+
+/**** I am moving the auto-convert functions out of this program 
+      until I can define an appropriate paradigm ****/
 
 /* variables which describe the db */
@@ -40,4 +43,12 @@
     return (TRUE);
   }
+  if (!strcmp (db, "trans")) {
+    dBFile = TransDB;    
+    BinaryName = "TRANS_POINTS_3.0";
+    set_Binary_name (BinaryName);
+    set_ASCII_name ("SUMMARY_ZPTS");
+    return (TRUE);
+  }
+  /*
   if (!strcmp (db, "phot_old")) {
     dBFile = PhotDB;    
@@ -47,11 +58,4 @@
     return (TRUE);
   }
-  if (!strcmp (db, "trans")) {
-    dBFile = TransDB;    
-    BinaryName = "TRANS_POINTS_3.0";
-    set_Binary_name (BinaryName);
-    set_ASCII_name ("SUMMARY_ZPTS");
-    return (TRUE);
-  }
   if (!strcmp (db, "trans_old")) {
     dBFile = TransDB;    
@@ -61,4 +65,5 @@
     return (TRUE);
   }
+  */
   return (FALSE);
 }
@@ -99,6 +104,11 @@
 
   if (output.convert) {
+    fprintf (stderr, "conversion not allowed for now\n");
+    status = FALSE;
+    exit (1);
+    /* 
     status = load_old_db ();
     return (status);
+    */
   }
   set_db (output.db);
@@ -138,4 +148,5 @@
 }
 
+# if (0)
 int load_old_db () {
 
@@ -198,4 +209,5 @@
   return (1);
 }
+# endif
 
 /* save complete db file */
Index: /trunk/Ohana/src/libohana/Makefile
===================================================================
--- /trunk/Ohana/src/libohana/Makefile	(revision 3465)
+++ /trunk/Ohana/src/libohana/Makefile	(revision 3466)
@@ -21,5 +21,11 @@
 ohana: $(LIB)/libohana.$(ARCH).a 
 
-HOBJ = $(DESTINC)/ohana.h $(DESTINC)/loneos.h $(DESTINC)/Xohana.h 
+HOBJ = \
+$(DESTINC)/Xohana.h  \
+$(DESTINC)/ohana.h \
+$(DESTINC)/loneos.h \
+$(DESTINC)/elixir.h \
+$(DESTINC)/panstarrs.h \
+$(DESTINC)/dvo.h
 
 LOBJ = \
@@ -42,5 +48,5 @@
 	$(RANLIB) $(LIB)/libohana.$(ARCH).a
 
-$(LOBJ): $(DESTINC)/ohana.h $(DESTINC)/loneos.h
+$(LOBJ): $(DESTINC)/ohana.h $(DESTINC)/loneos.h $(DESTINC)/elixir.h $(DESTINC)/panstarrs.h
 
 $(DESTINC)/%: $(INC)/%
Index: /trunk/Ohana/src/libohana/doc/dvo-structures.txt
===================================================================
--- /trunk/Ohana/src/libohana/doc/dvo-structures.txt	(revision 3465)
+++ /trunk/Ohana/src/libohana/doc/dvo-structures.txt	(revision 3466)
@@ -28,2 +28,10 @@
 programs.
 
+Translations
+
+/* average data as stored in the LONEOS database -- must be translated on load */
+
+Loneos:Measure -> Elixir:Measure
+/* OLD LONEOS VERSION.  NOT BYTE COMPATIBLE WITH NEW VERSION 
+   (can be loaded with translation, losing the exptime,
+   and limited the number of Naverage to 0xffffff - in load_catalog) */
Index: /trunk/Ohana/src/libohana/doc/load_catalog.c
===================================================================
--- /trunk/Ohana/src/libohana/doc/load_catalog.c	(revision 3465)
+++ /trunk/Ohana/src/libohana/doc/load_catalog.c	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 /* the function in this file uses the old definition of Catalog,
Index: /trunk/Ohana/src/libohana/doc/save_catalog.c
===================================================================
--- /trunk/Ohana/src/libohana/doc/save_catalog.c	(revision 3465)
+++ /trunk/Ohana/src/libohana/doc/save_catalog.c	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 /* the function in this file uses the old definition of Catalog,
Index: /trunk/Ohana/src/libohana/include/loneos.h
===================================================================
--- /trunk/Ohana/src/libohana/include/loneos.h	(revision 3465)
+++ /trunk/Ohana/src/libohana/include/loneos.h	(revision 3466)
@@ -18,26 +18,6 @@
 enum {M_UNDEF = -1, M_NONE, M_MEF, M_SPLIT, M_SINGLE, M_CUBE, M_SLICE, M_MODES, N_MODE};
 
-# if (0) 
-  # define MODE_NONE   0  /* not defined */
-  # define MODE_MEF    1  /* chip of mef image */
-  # define MODE_SPLIT  2  /* chip of split image */
-  # define MODE_SINGLE 3  /* single chip, not mosaic */
-  # define MODE_CUBE   4  /* cube entry */
-  # define MODE_SLICE  5  /* slice of a cube */
-  # define MODE_MODES  6  /* not used? */
-
-  # define TYPE_NONE   0
-  # define TYPE_OBJECT 1
-  # define TYPE_DARK   2
-  # define TYPE_BIAS   3
-  # define TYPE_FLAT   4
-/** these are no longer used by imregister-3.0 
-    status:imrough uses the imregister-3.0 values
-    status:imsearch should migrate to the imregister.h version 
-    or be removed!
-**/
-# endif
-
-
+/* convert these to enums? */
+/* RegImage.flag values */
 # define IMREG_DIST  0x01 /* image distributed, only imregister-3.0 */
 
@@ -101,10 +81,4 @@
       than one star in the catalog, but not in the same catalog file.
 */
-
-/* structure for data on a catalog region */
-typedef struct {
-  char filename[256];
-  double DEC[2], RA[2];
-} GSCRegion;
 
 /* structure for Image Registration Database */
@@ -137,30 +111,4 @@
 } RegImage;  /* 360 bytes / image */
 
-/* structure for Image Registration Database */
-typedef struct {
-  float sky;
-  float bias;
-  float fwhm;
-  float exptime;
-  float airmass;
-  e_time obstime;
-  short int ccdnum;
-  char junk1, junk2;
-  char filter[32];
-} RufImage;  /* 60 bytes */
-
-/* Old Detrend Database structure */
-typedef struct {
-  e_time tstart;
-  e_time tstop;
-  e_time treg;
-  float sigma, clipsigma;
-  int type;
-  int filter;
-  int ccd;
-  char filename[254];
-  char flag1, flag2;
-} DetRegOld;    /* 288 bytes */
-
 /* Detrend Database structure */
 typedef struct {
@@ -193,19 +141,4 @@
   short int c2;               /* photcode for color term */
   short int photcode;         /* appropriate photcode */
-  char label[66];
-} OldPhotPars;    /* 100 bytes */
-
-/* Instant Zeropoint structure */
-typedef struct {
-  float ZP;                   /* measured zero point */
-  float ZPo;                  /* expected zero point */
-  float dZP;                  /* error on zero point */
-  float K;                    /* airmass term used */
-  float X;                    /* color term used */
-  e_time tstart;   /* start time of observation */
-  e_time tstop;    /* end time of observation */
-  short int c1;               /* photcode for color term */
-  short int c2;               /* photcode for color term */
-  short int photcode;         /* appropriate photcode */
   char label[64];
   short int refcode;          /* reference photometry system */
@@ -213,19 +146,4 @@
   int Nmeas;                  /* number of data points */
 } PhotPars;    /* 108 bytes */
-
-/* average data as stored in the LONEOS database */
-typedef struct {
-  float R;                    /* RA  in decimal degrees */
-  float D;                    /* DEC in decimal degrees */
-  short int M;                /* thousandths of mag (-32.000 to 32.000 valid range) */
-  unsigned short int Nm, Nn;  /* number of measurements, missing */
-  short int Xp;               /* scatter in 1/100 arcsec (-327.67 to +327.67 valid range) */
-  short int Xm;               /* chisq for primary mag [1000*value] */
-  unsigned short int code;    /* an ID code (ie, star, ghost, satelite, etc) */
-  signed int offset;          /* offset to first measurement */
-  signed int missing;         /* offset to first missing obs */
-  short int dM;               /* formal error on pri mag   [1000*log(value)] */
-  short int Xg;               /* 'best' chisq value */
-} Average; /* 32 bytes / Average */
 
 /* average data as stored in the LONEOS database -- must be translated on load */
@@ -240,10 +158,7 @@
   signed int offset;          /* offset to first measurement */
   signed int missing;         /* offset to first missing obs */
-} OldAverage; /* 28 bytes / Average */
+} Average; /* 28 bytes / Average */
 
 /* data for individual measurement for each star */
-/* OLD LONEOS VERSION.  NOT BYTE COMPATIBLE WITH NEW VERSION 
-   (can be loaded with translation, losing the exptime,
-   and limited the number of Naverage to 0xffffff - in load_catalog) */
 typedef struct {
   short int dR, dD;           /* 1/100 of arcsec (-327.67 to +327.67 valid range) */
@@ -255,39 +170,5 @@
   unsigned int   t;           /* time in seconds (0 - 143 years valid range) */
   unsigned int average;       /* reference to corresponding average entry, upper byte of Measure.average stores flags */
-} OldMeasure; /* 20 bytes / Measure */
-
-/* data for individual measurement for each star */
-typedef struct {
-  short int dR, dD;           /* 1/100 of arcsec (-327.67 to +327.67 valid range) */
-  short int M;                /* thousandths of mag (-32.767 to 32.767 valid range) */
-  short int Mcal;             /* image cal mag, thousandths of mag (-32.767 to 32.767 valid range) */
-  short int Mgal;             /* 'galaxy' mag, thousandths of mag (-32.767 to 32.767 valid range) */
-  short int airmass;          /* (airmass - 1), thousandths of mag (-32.767 to 32.767 valid range) */
-  short int FWx;              /* object fwhm major axis - 1/100 of arcsec */
-  unsigned char dM;           /* thousandths of mag (0.000 to 0.255 valid range) */
-  unsigned char fwy, theta;   /* object fwhm minor/major axes ratio, angle wrt ccd X dir (0xff/360 deg precision) */
-  char dophot;                /* dophot type (1-9) */
-  unsigned short int source;  /* code to identify photometry source */
-  unsigned int   t;           /* time in seconds (0 - 143 years valid range) */
-  unsigned int averef;        /* reference to corresponding average entry, upper byte of Measure.average stores flags */
-  short int dt;               /* exposure time in units of 2500*log(exptime) (millimags!) */
-  unsigned short int flags;   /* 16 bit-flags for various uses */ 
-} Measure; /* 32 bytes / Measure */
-
-# if (0)
-/* data for individual measurement for each star */
-typedef struct {
-  short int dR, dD;           /* 1/100 of arcsec (-327.67 to +327.67 valid range) */
-  short int M;                /* thousandths of mag (-32.767 to 32.767 valid range) */
-  short int Mcal;             /* image cal mag, thousandths of mag (-32.767 to 32.767 valid range) */
-  unsigned char dM;           /* thousandths of mag (0.000 to 0.255 valid range) */
-  char dophot;                /* dophot type (1-9) */
-  unsigned short int source;  /* code to identify photometry source */
-  unsigned int   t;           /* time in seconds (0 - 143 years valid range) */
-  unsigned int averef;        /* reference to corresponding average entry, upper byte of Measure.average stores flags */
-  short int dt;               /* exposure time in units of 2500*log(exptime) (millimags!) */
-  unsigned short int flags;   /* 16 bit-flags for various uses */ 
-} Measure; /* 24 bytes / Measure */
-# endif
+} Measure; /* 20 bytes / Measure */
 
 /* data on missing stars */
@@ -302,31 +183,4 @@
   short int dM;               /* scatter on alt mag */
 } SecFilt; /* 6 byte / SecFilt */
-
-/* data on missing stars */
-typedef struct {
-  short int M;                /* other mags - thousandths of mag (-32.767 to 32.767 valid range) */
-  short int Xm;               /* chisq on alt mag */
-} OldSecFilt; /* 4 byte / SecFilt */
-
-/* a catalog contains this data */
-typedef struct {
-  /* data in the file: */
-  Average *average;
-  Measure *measure; 
-  Missing *missing; 
-  SecFilt *secfilt;
-  Header  header;
-  int Naverage, Nmeasure, Nmissing, Nsecfilt;
-  /* description of the catalog file: */
-  char *filename;
-  int lockmode;
-  FILE *f;
-  /* pointers for data manipulation */
-  int *found;
-  int *image;
-  int *mosaic;
-  float *X;
-  float *Y;
-} Catalog;
 
 /* the standard astrometric coordinates structure */
@@ -341,24 +195,4 @@
   char     Npolyterms;
 } Coords;  /* 120 bytes / Coords */
-
-typedef struct {
-  unsigned short int code;   /* code number (stored in Measure.source) */
-  char name[32];             /* name for filter combination */
-  char type;                 /* primary, secondary, dependent, reference */
-  short int C, dC, dX;       /* primary phot calibration terms (millimags) */
-  float K;                   /* secondary phot calibration terms (millimags) */
-  int  c1, c2;               /* color is average.M[c1] - average.M[c2] */
-  int  equiv;                /* this dependent filter is equivalent to equiv primary/secondary */
-  int  Nc;                   /* number of color terms */
-  float X[4];                /* color terms X[0]*mc + X[1]*mc^2 + X[2]*mc^3, etc */
-} PhotCode;
-
-typedef struct {
-  int Ncode;
-  int Nsecfilt;
-  int hashcode[0x10000];
-  int hashNsec[0x10000];
-  PhotCode *code;
-} PhotCodeData;
 
 /* image structure for binary data storage of image data */
@@ -395,4 +229,51 @@
 /* Image needs to be aligned with 8-byte boundaries on Suns */
 
+/* a catalog contains this data */
+typedef struct {
+  /* data in the file: */
+  Average *average;
+  Measure *measure; 
+  Missing *missing; 
+  SecFilt *secfilt;
+  Header  header;
+  int Naverage, Nmeasure, Nmissing, Nsecfilt;
+  /* description of the catalog file: */
+  char *filename;
+  int lockmode;
+  FILE *f;
+  /* pointers for data manipulation */
+  int *found;
+  int *image;
+  int *mosaic;
+  float *X;
+  float *Y;
+} Catalog;
+
+/* structure for data on a catalog region */
+typedef struct {
+  char filename[256];
+  double DEC[2], RA[2];
+} GSCRegion;
+
+typedef struct {
+  unsigned short int code;   /* code number (stored in Measure.source) */
+  char name[32];             /* name for filter combination */
+  char type;                 /* primary, secondary, dependent, reference */
+  short int C, dC, dX;       /* primary phot calibration terms (millimags) */
+  float K;                   /* secondary phot calibration terms (millimags) */
+  int  c1, c2;               /* color is average.M[c1] - average.M[c2] */
+  int  equiv;                /* this dependent filter is equivalent to equiv primary/secondary */
+  int  Nc;                   /* number of color terms */
+  float X[4];                /* color terms X[0]*mc + X[1]*mc^2 + X[2]*mc^3, etc */
+} PhotCode;
+
+typedef struct {
+  int Ncode;
+  int Nsecfilt;
+  int hashcode[0x10000];
+  int hashNsec[0x10000];
+  PhotCode *code;
+} PhotCodeData;
+
 /**** prototypes ****/
 
Index: /trunk/Ohana/src/libohana/src/Fread.c
===================================================================
--- /trunk/Ohana/src/libohana/src/Fread.c	(revision 3465)
+++ /trunk/Ohana/src/libohana/src/Fread.c	(revision 3466)
@@ -1,4 +1,6 @@
 # include <stdio.h>
 # include <string.h>
+# include <ohana.h>
+# include <dvo.h>
 int   ByteSwap (char *ptr, int size, int nitems, char *type);
 int   ConvertStruct (char *buffer, int size, int Nbytes, char *type);
@@ -15,21 +17,31 @@
   tmp = byte[X+2]; byte[X+2] = byte[X+5]; byte[X+5] = tmp; \
   tmp = byte[X+3]; byte[X+3] = byte[X+4]; byte[X+4] = tmp;
-# define IMAGE_SIZE 240
-# define OLDAVERAGE_SIZE 28
-# define AVERAGE_SIZE 32
-# define OLDMEASURE_SIZE 20
-# define MEASURE_SIZE 32
-# define MISSING_SIZE 4
-# define OLDSECFILT_SIZE 4
-# define SECFILT_SIZE 6
+
 # define REGIMAGE_SIZE 360
-# define SPECTRUM_SIZE 216
-# define RUFIMAGE_SIZE 60
-# define OLDDETREG_SIZE 288
 # define DETREG_SIZE 416
 # define PHOTPARS_SIZE 108
+# define MISSING_SIZE 4
+# define SECFILT_SIZE 6
+# define SPECTRUM_SIZE 216  /* where is this?? */
+# define IMAGE_SIZE 240
+
+# if (PANSTARRS)
+# define AVERAGE_SIZE 40
+# define MEASURE_SIZE 32
+# endif
+
+# if (ELIXIR)
+# define AVERAGE_SIZE 32
+# define MEASURE_SIZE 32
+# endif
+
+# if (LONEOS)
+# define AVERAGE_SIZE 28
+# define MEASURE_SIZE 20
+# endif
+
 # define OLDPHOTPARS_SIZE 100
-# define TRUE 1
-# define FALSE 0
+# define OLDSECFILT_SIZE 4
+# define OLDDETREG_SIZE 288
 
 # ifdef linux
@@ -46,5 +58,5 @@
 # endif
 
-int Fread (char *ptr, int size, int nitems, FILE *f, char *type) {
+int Fread (void *ptr, int size, int nitems, FILE *f, char *type) {
 
   int valid, status;
@@ -58,5 +70,5 @@
 }
 
-int Fwrite (char *ptr, int size, int nitems, FILE *f, char *type) {
+int Fwrite (void *ptr, int size, int nitems, FILE *f, char *type) {
 
   int valid, status;
@@ -81,11 +93,8 @@
 # ifdef BYTE_SWAP
 
-  int i, j, valid;
+  int i, j;
   unsigned char *byte, *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, tmp;
 
-  valid = FALSE;
-  if (!strcmp (type, "char")) {
-    valid = TRUE;
-  }
+  if (!strcmp (type, "char")) return (TRUE);
 
   if (!strcmp (type, "short")) {
@@ -97,5 +106,5 @@
       *byte1 = tmp;
     }
-    valid = TRUE;
+    return (TRUE);
   }
 
@@ -113,5 +122,5 @@
       *byte2 = tmp;
     }
-    valid = TRUE;
+    return (TRUE);
   }
 
@@ -139,55 +148,11 @@
       *byte4 = tmp;
     }
-    valid = TRUE;
-  }
-
-  if (!strcmp (type, "average")) {
-    if (size != AVERAGE_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (Average) %d vs %d\n", size, AVERAGE_SIZE);
-      return (0);
-    }
-    byte = (char *)ptr;
-    for (i = 0; i < nitems; i++, byte += AVERAGE_SIZE) {
-      SWAP_WORD (0);   /* R */
-      SWAP_WORD (4);   /* D */
-      SWAP_BYTE (8);   /* M */
-      SWAP_BYTE (10);  /* Nm */
-      SWAP_BYTE (12);  /* Nn */
-      SWAP_BYTE (14);  /* Xp */
-      SWAP_BYTE (16);  /* Xm */
-      SWAP_BYTE (18);  /* code */
-      SWAP_WORD (20);  /* offset */
-      SWAP_WORD (24);  /* missing */
-      SWAP_BYTE (28);  /* dM */
-      SWAP_BYTE (30);  /* Xg */
-    }
-    valid = TRUE;
-  } 
-
-  if (!strcmp (type, "oldaverage")) {
-    if (size != OLDAVERAGE_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (OldAverage) %d vs %d\n", size, OLDAVERAGE_SIZE);
-      return (0);
-    }
-    byte = (char *)ptr;
-    for (i = 0; i < nitems; i++, byte += OLDAVERAGE_SIZE) {
-      SWAP_WORD (0);   /* R */
-      SWAP_WORD (4);   /* D */
-      SWAP_BYTE (8);   /* M */
-      SWAP_BYTE (10); /* Nm */
-      SWAP_BYTE (12); /* Nn */
-      SWAP_BYTE (14); /* Xp */
-      SWAP_BYTE (16); /* Xm */
-      SWAP_BYTE (18); /* code */
-      SWAP_WORD (20); /* offset */
-      SWAP_WORD (24); /* missing */
-    }
-    valid = TRUE;
-  } 
+    return (TRUE);
+  }
 
   if (!strcmp (type, "regimage")) {
     if (size != REGIMAGE_SIZE) {
       fprintf (stderr, "mismatch in type sizes (RegImage) %d vs %d\n", size, REGIMAGE_SIZE);
-      return (0);
+      return (FALSE);
     }
     byte = (char *)ptr;
@@ -213,63 +178,5 @@
       SWAP_WORD (356); /* regtime */  
     }
-    valid = TRUE;
-  }
-
-  if (!strcmp (type, "spectrum")) {
-    if (size != SPECTRUM_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (Spectrum) %d vs %d\n", size, SPECTRUM_SIZE);
-      return (0);
-    }
-    byte = (char *)ptr;
-    for (i = 0; i < nitems; i++, byte += SPECTRUM_SIZE) {
-      SWAP_WORD (0);  /* ra */ 
-      SWAP_WORD (4);  /* dec */ 
-      SWAP_WORD (8);  /* exptime */ 
-      SWAP_WORD (12); /* airmass */ 
-      SWAP_WORD (16); /* Ws */ 
-      SWAP_WORD (20); /* We */ 
-      SWAP_WORD (24); /* dW */ 
-      SWAP_WORD (28); /* Nspec */ 
-      SWAP_WORD (32); /* obstime */ 
-      SWAP_WORD (36); /* regtime */ 
-    }
-    valid = TRUE;
-  }
-
-  if (!strcmp (type, "rufimage")) {
-    if (size != RUFIMAGE_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (RufImage) %d vs %d\n", size, RUFIMAGE_SIZE);
-      return (0);
-    }
-    byte = (char *)ptr;
-    for (i = 0; i < nitems; i++, byte += RUFIMAGE_SIZE) {
-      SWAP_WORD (0);   /* sky */
-      SWAP_WORD (4);   /* bias */
-      SWAP_WORD (8);  /* fwhm */
-      SWAP_WORD (12); /* exptime */
-      SWAP_WORD (16); /* airmass */
-      SWAP_WORD (20); /* obstime */
-      SWAP_BYTE (24); /* ccdnum */
-    }
-    valid = TRUE;
-  }
-
-  if (!strcmp (type, "olddetreg")) {
-    if (size != OLDDETREG_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (DetReg) %d vs %d\n", size, OLDDETREG_SIZE);
-      return (0);
-    }
-    byte = (char *)ptr;
-    for (i = 0; i < nitems; i++, byte += OLDDETREG_SIZE) {
-      SWAP_WORD (0);   /* tstart */
-      SWAP_WORD (4);   /* tstop */
-      SWAP_WORD (8);   /* treg */
-      SWAP_WORD (12);  /* sigma */
-      SWAP_WORD (16);  /* clipsigma */
-      SWAP_WORD (20);  /* type */
-      SWAP_WORD (24);  /* filter */
-      SWAP_WORD (28);  /* ccd */
-    }
-    valid = TRUE;
+    return (TRUE);
   }
 
@@ -277,5 +184,5 @@
     if (size != DETREG_SIZE) {
       fprintf (stderr, "mismatch in type sizes (DetReg) %d vs %d\n", size, DETREG_SIZE);
-      return (0);
+      return (FALSE);
     }
     byte = (char *)ptr;
@@ -291,26 +198,5 @@
       SWAP_WORD (32);  /* Norder */
     }
-    valid = TRUE;
-  }
-
-  if (!strcmp (type, "oldphotpars")) {
-    if (size != OLDPHOTPARS_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (OldPhotPars) %d vs %d\n", size, OLDPHOTPARS_SIZE);
-      return (0);
-    }
-    byte = (char *)ptr;
-    for (i = 0; i < nitems; i++, byte += OLDPHOTPARS_SIZE) {
-      SWAP_WORD (0);    /* ZP */
-      SWAP_WORD (4);    /* ZPo */
-      SWAP_WORD (8);    /* dZP */
-      SWAP_WORD (12);   /* K */
-      SWAP_WORD (16);   /* A */
-      SWAP_WORD (20);   /* tstart */
-      SWAP_WORD (24);   /* tstop */
-      SWAP_BYTE (28);   /* c1 */
-      SWAP_BYTE (30);   /* c2 */
-      SWAP_BYTE (32);   /* photcode */
-    }
-    valid = TRUE;
+    return (TRUE);
   }
 
@@ -318,5 +204,5 @@
     if (size != PHOTPARS_SIZE) {
       fprintf (stderr, "mismatch in type sizes (PhotPars) %d vs %d\n", size, PHOTPARS_SIZE);
-      return (0);
+      return (FALSE);
     }
     byte = (char *)ptr;
@@ -335,74 +221,5 @@
       SWAP_WORD (104);   /* Nmeas */
     }
-    valid = TRUE;
-  }
-
-  if (!strcmp (type, "oldmeasure")) {
-    if (size != OLDMEASURE_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (OldMeasure) %d vs %d\n", size, OLDMEASURE_SIZE);
-      return (0);
-    }
-    byte = (char *)ptr;
-    for (i = 0; i < nitems; i++, byte += OLDMEASURE_SIZE) {
-      SWAP_BYTE (0);   /* dR */
-      SWAP_BYTE (2);   /* dD */
-      SWAP_BYTE (4);   /* M  */
-      SWAP_BYTE (6);   /* Mcal */
-      SWAP_BYTE (10);  /* source */
-      SWAP_WORD (12);  /* t */
-      SWAP_WORD (16);  /* average */
-    }
-    valid = TRUE;
-  }
-
-  if (!strcmp (type, "measure")) {
-    if (size != MEASURE_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (Measure) %d vs %d\n", size, MEASURE_SIZE);
-      return (0);
-    }
-    byte = (char *)ptr;
-    for (i = 0; i < nitems; i++, byte += MEASURE_SIZE) {
-      SWAP_BYTE (0);   /* dR */
-      SWAP_BYTE (2);   /* dD */
-      SWAP_BYTE (4);   /* M  */
-      SWAP_BYTE (6);   /* Mcal */
-      SWAP_BYTE (8);   /* Mgal */
-      SWAP_BYTE (10);  /* Map  */
-      SWAP_BYTE (12);  /* FWx */
-      /* 14, 15, 16, 17 - char */
-      SWAP_BYTE (18);  /* source */
-      SWAP_WORD (20);  /* t */
-      SWAP_WORD (24);  /* averef */
-      SWAP_BYTE (28);  /* dt */
-      SWAP_BYTE (30);  /* flags */
-    }
-    valid = TRUE;
-  }
-
-  if (!strcmp (type, "secfilt")) {
-    if (size != SECFILT_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (SecFilt) %d vs %d\n", size, SECFILT_SIZE);
-      return (0);
-    }
-    byte = (char *) ptr;
-    for (i = 0; i < nitems; i++, byte += SECFILT_SIZE) {
-      SWAP_BYTE (0);   /* M */
-      SWAP_BYTE (2);   /* Xm */
-      SWAP_BYTE (4);   /* dM */
-    }
-    valid = TRUE;
-  }
-
-  if (!strcmp (type, "oldsecfilt")) {
-    if (size != OLDSECFILT_SIZE) {
-      fprintf (stderr, "mismatch in type sizes (OldSecFilt) %d vs %d\n", size, OLDSECFILT_SIZE);
-      return (0);
-    }
-    byte = (char *) ptr;
-    for (i = 0; i < nitems; i++, byte += OLDSECFILT_SIZE) {
-      SWAP_BYTE (0);   /* M */
-      SWAP_BYTE (2);   /* Xm */
-    }
-    valid = TRUE;
+    return (TRUE);
   }
 
@@ -410,5 +227,5 @@
     if (size != MISSING_SIZE) {
       fprintf (stderr, "mismatch in type sizes (Missing) %d vs %d\n", size, MISSING_SIZE);
-      return (0);
+      return (FALSE);
     }
     byte0 = (char *)ptr;
@@ -424,5 +241,40 @@
       *byte2 = tmp;
     }
-    valid = TRUE;
+    return (TRUE);
+  }
+
+  if (!strcmp (type, "secfilt")) {
+    if (size != SECFILT_SIZE) {
+      fprintf (stderr, "mismatch in type sizes (SecFilt) %d vs %d\n", size, SECFILT_SIZE);
+      return (FALSE);
+    }
+    byte = (char *) ptr;
+    for (i = 0; i < nitems; i++, byte += SECFILT_SIZE) {
+      SWAP_BYTE (0);   /* M */
+      SWAP_BYTE (2);   /* Xm */
+      SWAP_BYTE (4);   /* dM */
+    }
+    return (TRUE);
+  }
+
+  if (!strcmp (type, "spectrum")) {
+    if (size != SPECTRUM_SIZE) {
+      fprintf (stderr, "mismatch in type sizes (Spectrum) %d vs %d\n", size, SPECTRUM_SIZE);
+      return (FALSE);
+    }
+    byte = (char *)ptr;
+    for (i = 0; i < nitems; i++, byte += SPECTRUM_SIZE) {
+      SWAP_WORD (0);  /* ra */ 
+      SWAP_WORD (4);  /* dec */ 
+      SWAP_WORD (8);  /* exptime */ 
+      SWAP_WORD (12); /* airmass */ 
+      SWAP_WORD (16); /* Ws */ 
+      SWAP_WORD (20); /* We */ 
+      SWAP_WORD (24); /* dW */ 
+      SWAP_WORD (28); /* Nspec */ 
+      SWAP_WORD (32); /* obstime */ 
+      SWAP_WORD (36); /* regtime */ 
+    }
+    return (TRUE);
   }
 
@@ -430,5 +282,5 @@
     if (size != IMAGE_SIZE) {
       fprintf (stderr, "mismatch in type sizes (Image) %d vs %d\n", size, IMAGE_SIZE);
-      return (0);
+      return (FALSE);
     }
     byte = (char *)ptr;
@@ -450,11 +302,199 @@
       }
     }
-    valid = TRUE;
-  }
-
-  if (!valid) 
-    fprintf (stderr, "unknown type %s\n", type);
-
-  return (valid);
+    return (TRUE);
+  }
+
+# if (PANSTARRS)
+  if (!strcmp (type, "average")) {
+    if (size != AVERAGE_SIZE) {
+      fprintf (stderr, "mismatch in type sizes (Average) %d vs %d\n", size, AVERAGE_SIZE);
+      return (FALSE);
+    }
+    byte = (char *)ptr;
+    for (i = 0; i < nitems; i++, byte += AVERAGE_SIZE) {
+      SWAP_DBLE (0);   /* R */
+      SWAP_DBLE (8);   /* D */
+      SWAP_BYTE (16);  /* M */
+      SWAP_BYTE (18);  /* Nm */
+      SWAP_BYTE (20);  /* Nn */
+      SWAP_BYTE (22);  /* Xp */
+      SWAP_BYTE (24);  /* Xm */
+      SWAP_BYTE (26);  /* code */
+      SWAP_WORD (28);  /* offset */
+      SWAP_WORD (32);  /* missing */
+      SWAP_BYTE (36);  /* dM */
+      SWAP_BYTE (38);  /* Xg */
+    }
+    return (TRUE);
+  } 
+  if (!strcmp (type, "measure")) {
+    if (size != MEASURE_SIZE) {
+      fprintf (stderr, "mismatch in type sizes (Measure) %d vs %d\n", size, MEASURE_SIZE);
+      return (FALSE);
+    }
+    byte = (char *)ptr;
+    for (i = 0; i < nitems; i++, byte += MEASURE_SIZE) {
+      SWAP_BYTE (0);   /* dR */
+      SWAP_BYTE (2);   /* dD */
+      SWAP_BYTE (4);   /* M  */
+      SWAP_BYTE (6);   /* Mcal */
+      SWAP_BYTE (8);   /* Mgal */
+      SWAP_BYTE (10);  /* Map  */
+      SWAP_BYTE (12);  /* FWx */
+      /* 14, 15, 16, 17 - char */
+      SWAP_BYTE (18);  /* source */
+      SWAP_WORD (20);  /* t */
+      SWAP_WORD (24);  /* averef */
+      SWAP_BYTE (28);  /* dt */
+      SWAP_BYTE (30);  /* flags */
+    }
+    return (TRUE);
+  }
+
+# endif /** ELIXIR **/
+
+
+# if (ELIXIR)
+  if (!strcmp (type, "average")) {
+    if (size != AVERAGE_SIZE) {
+      fprintf (stderr, "mismatch in type sizes (Average) %d vs %d\n", size, AVERAGE_SIZE);
+      return (FALSE);
+    }
+    byte = (char *)ptr;
+    for (i = 0; i < nitems; i++, byte += AVERAGE_SIZE) {
+      SWAP_WORD (0);   /* R */
+      SWAP_WORD (4);   /* D */
+      SWAP_BYTE (8);   /* M */
+      SWAP_BYTE (10);  /* Nm */
+      SWAP_BYTE (12);  /* Nn */
+      SWAP_BYTE (14);  /* Xp */
+      SWAP_BYTE (16);  /* Xm */
+      SWAP_BYTE (18);  /* code */
+      SWAP_WORD (20);  /* offset */
+      SWAP_WORD (24);  /* missing */
+      SWAP_BYTE (28);  /* dM */
+      SWAP_BYTE (30);  /* Xg */
+    }
+    return (TRUE);
+  } 
+  if (!strcmp (type, "measure")) {
+    if (size != MEASURE_SIZE) {
+      fprintf (stderr, "mismatch in type sizes (Measure) %d vs %d\n", size, MEASURE_SIZE);
+      return (FALSE);
+    }
+    byte = (char *)ptr;
+    for (i = 0; i < nitems; i++, byte += MEASURE_SIZE) {
+      SWAP_BYTE (0);   /* dR */
+      SWAP_BYTE (2);   /* dD */
+      SWAP_BYTE (4);   /* M  */
+      SWAP_BYTE (6);   /* Mcal */
+      SWAP_BYTE (8);   /* Mgal */
+      SWAP_BYTE (10);  /* Map  */
+      SWAP_BYTE (12);  /* FWx */
+      /* 14, 15, 16, 17 - char */
+      SWAP_BYTE (18);  /* source */
+      SWAP_WORD (20);  /* t */
+      SWAP_WORD (24);  /* averef */
+      SWAP_BYTE (28);  /* dt */
+      SWAP_BYTE (30);  /* flags */
+    }
+    return (TRUE);
+  }
+
+# endif /** ELIXIR **/
+
+
+# if (LONEOS)
+  if (!strcmp (type, "average")) {
+    if (size != OLDAVERAGE_SIZE) {
+      fprintf (stderr, "mismatch in type sizes (OldAverage) %d vs %d\n", size, OLDAVERAGE_SIZE);
+      return (FALSE);
+    }
+    byte = (char *)ptr;
+    for (i = 0; i < nitems; i++, byte += OLDAVERAGE_SIZE) {
+      SWAP_WORD (0);   /* R */
+      SWAP_WORD (4);   /* D */
+      SWAP_BYTE (8);   /* M */
+      SWAP_BYTE (10); /* Nm */
+      SWAP_BYTE (12); /* Nn */
+      SWAP_BYTE (14); /* Xp */
+      SWAP_BYTE (16); /* Xm */
+      SWAP_BYTE (18); /* code */
+      SWAP_WORD (20); /* offset */
+      SWAP_WORD (24); /* missing */
+    }
+    return (TRUE);
+  } 
+  if (!strcmp (type, "measure")) {
+    if (size != OLDMEASURE_SIZE) {
+      fprintf (stderr, "mismatch in type sizes (OldMeasure) %d vs %d\n", size, OLDMEASURE_SIZE);
+      return (FALSE);
+    }
+    byte = (char *)ptr;
+    for (i = 0; i < nitems; i++, byte += OLDMEASURE_SIZE) {
+      SWAP_BYTE (0);   /* dR */
+      SWAP_BYTE (2);   /* dD */
+      SWAP_BYTE (4);   /* M  */
+      SWAP_BYTE (6);   /* Mcal */
+      SWAP_BYTE (10);  /* source */
+      SWAP_WORD (12);  /* t */
+      SWAP_WORD (16);  /* average */
+    }
+    return (TRUE);
+  }
+# endif /** LONEOS **/
+
+# if (0) /*** others ***/
+  if (!strcmp (type, "oldsecfilt")) {
+    if (size != OLDSECFILT_SIZE) {
+      fprintf (stderr, "mismatch in type sizes (OldSecFilt) %d vs %d\n", size, OLDSECFILT_SIZE);
+      return (FALSE);
+    }
+    byte = (char *) ptr;
+    for (i = 0; i < nitems; i++, byte += OLDSECFILT_SIZE) {
+      SWAP_BYTE (0);   /* M */
+      SWAP_BYTE (2);   /* Xm */
+    }
+    return (TRUE);
+  }
+  if (!strcmp (type, "rufimage")) {
+    if (size != RUFIMAGE_SIZE) {
+      fprintf (stderr, "mismatch in type sizes (RufImage) %d vs %d\n", size, RUFIMAGE_SIZE);
+      return (FALSE);
+    }
+    byte = (char *)ptr;
+    for (i = 0; i < nitems; i++, byte += RUFIMAGE_SIZE) {
+      SWAP_WORD (0);   /* sky */
+      SWAP_WORD (4);   /* bias */
+      SWAP_WORD (8);  /* fwhm */
+      SWAP_WORD (12); /* exptime */
+      SWAP_WORD (16); /* airmass */
+      SWAP_WORD (20); /* obstime */
+      SWAP_BYTE (24); /* ccdnum */
+    }
+    return (TRUE);
+  }
+  if (!strcmp (type, "olddetreg")) {
+    if (size != OLDDETREG_SIZE) {
+      fprintf (stderr, "mismatch in type sizes (DetReg) %d vs %d\n", size, OLDDETREG_SIZE);
+      return (FALSE);
+    }
+    byte = (char *)ptr;
+    for (i = 0; i < nitems; i++, byte += OLDDETREG_SIZE) {
+      SWAP_WORD (0);   /* tstart */
+      SWAP_WORD (4);   /* tstop */
+      SWAP_WORD (8);   /* treg */
+      SWAP_WORD (12);  /* sigma */
+      SWAP_WORD (16);  /* clipsigma */
+      SWAP_WORD (20);  /* type */
+      SWAP_WORD (24);  /* filter */
+      SWAP_WORD (28);  /* ccd */
+    }
+    return (TRUE);
+  }
+# endif /** others **/
+
+  fprintf (stderr, "unknown type %s\n", type);
+  return (FALSE);
 
 # else
Index: /trunk/Ohana/src/libohana/src/LoadPhotcodes.c
===================================================================
--- /trunk/Ohana/src/libohana/src/LoadPhotcodes.c	(revision 3465)
+++ /trunk/Ohana/src/libohana/src/LoadPhotcodes.c	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 # define NCTERMS 4
Index: /trunk/Ohana/src/libohana/src/coordops.c
===================================================================
--- /trunk/Ohana/src/libohana/src/coordops.c	(revision 3465)
+++ /trunk/Ohana/src/libohana/src/coordops.c	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 static Coords *mosaic = NULL;
Index: /trunk/Ohana/src/libohana/src/imreg_datatypes.c
===================================================================
--- /trunk/Ohana/src/libohana/src/imreg_datatypes.c	(revision 3465)
+++ /trunk/Ohana/src/libohana/src/imreg_datatypes.c	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 char typename[N_TYPE][32] = {"none", "object", "dark", "bias", "flat", "mask", "fringe", "scatter", "modes", "frpts", "any"};
Index: /trunk/Ohana/src/libohana/src/mosaic_astrom.c
===================================================================
--- /trunk/Ohana/src/libohana/src/mosaic_astrom.c	(revision 3465)
+++ /trunk/Ohana/src/libohana/src/mosaic_astrom.c	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 /* chip-match table: j = ChipMatch[i], images[j] is DIS for images[i] WRP */
Index: /trunk/Ohana/src/libohana/src/phot_catalog.c
===================================================================
--- /trunk/Ohana/src/libohana/src/phot_catalog.c	(revision 3465)
+++ /trunk/Ohana/src/libohana/src/phot_catalog.c	(revision 3466)
@@ -1,8 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
-
-SecFilt *FixOldSecFilt (OldSecFilt *in, int Nvalues);
-Average *FixOldAverage (OldAverage *in, int Nvalues);
-Measure *FixOldMeasure (OldMeasure *in, int Nvalues);
+# include <dvo.h>
 
 /* possible exit status for lock_catalog: 
@@ -37,11 +33,4 @@
 }
 
-/* this is (a bit) dangerous: the load function will automatically
-   convert from the old (Loneos) format to the new (CFHT) format.
-   But, if you load an old-format catalog, then save the new-format
-   version, the new file will be corrupted unless you load all four
-   data components.  Actually, 'save_catalog' assumes you've loaded
-   all four anyway, so it is not such a problem... */
-
 int load_catalog (Catalog *catalog, char mode, int VERBOSE) {
   
@@ -50,7 +39,4 @@
   int NewMeasure, NewAverage, NewSecFilt;
   FILE *f;
-  OldMeasure *tmpmeasure;
-  OldAverage *tmpaverage;
-  OldSecFilt *tmpsecfilt;
   struct stat filestatus;
 
@@ -66,4 +52,9 @@
   /* this is done by the load anyway... */
   fseek (f, catalog[0].header.size, SEEK_SET); 
+
+  /* require the file to contain the NEW versions (ELIXIR) */
+  if (!fits_scan (&catalog[0].header, "NEWMEAS",  "%t", 1, &NewMeasure)) return (FALSE);
+  if (!fits_scan (&catalog[0].header, "NEWAVES",  "%t", 1, &NewAverage)) return (FALSE);
+  if (!fits_scan (&catalog[0].header, "NEWSECF",  "%t", 1, &NewSecFilt)) return (FALSE);
 
   /* get the components from the header */
@@ -73,17 +64,14 @@
   if (!fits_scan (&catalog[0].header, "NMISS",    "%d", 1, &catalog[0].Nmissing)) return (FALSE);
   if (!fits_scan (&catalog[0].header, "NSECFILT", "%d", 1, &catalog[0].Nsecfilt)) catalog[0].Nsecfilt = 0;
-  if (!fits_scan (&catalog[0].header, "NEWMEAS",  "%t", 1, &NewMeasure)) NewMeasure = FALSE;
-  if (!fits_scan (&catalog[0].header, "NEWAVES",  "%t", 1, &NewAverage)) NewAverage = FALSE;
-  if (!fits_scan (&catalog[0].header, "NEWSECF",  "%t", 1, &NewSecFilt)) NewSecFilt = FALSE;
 
   /* predicted file size - for double checking data validity */
   size = catalog[0].header.size;
-  ssize = NewAverage ? sizeof (Average) : sizeof (OldAverage);
+  ssize = sizeof (Average);
   size += ssize * catalog[0].Naverage;
-  ssize = NewMeasure ? sizeof (Measure) : sizeof (OldMeasure);
+  ssize = sizeof (Measure);
   size += ssize * catalog[0].Nmeasure;
   ssize = sizeof (Missing);
   size += ssize * catalog[0].Nmissing;
-  ssize = NewSecFilt ? sizeof (SecFilt) : sizeof (OldSecFilt);
+  ssize = sizeof (SecFilt);
   size += ssize * catalog[0].Nsecfilt * catalog[0].Naverage;
 
@@ -96,11 +84,11 @@
     if (VERBOSE) {
       fprintf (stderr, "star catalog has inconsistent size\n");
-      ssize = NewAverage ? sizeof (Average) : sizeof (OldAverage);
+      ssize = sizeof (Average);
       fprintf (stderr, "average: %d = %d bytes\n", catalog[0].Naverage, catalog[0].Naverage*ssize);
-      ssize = NewMeasure ? sizeof (Measure) : sizeof (OldMeasure);
+      ssize = sizeof (Measure);
       fprintf (stderr, "measure: %d = %d bytes\n", catalog[0].Nmeasure, catalog[0].Nmeasure*ssize);
       ssize = sizeof (Missing);
       fprintf (stderr, "missing: %d = %d bytes\n", catalog[0].Nmissing, catalog[0].Nmissing*ssize);
-      ssize = NewSecFilt ? sizeof (SecFilt) : sizeof (OldSecFilt);
+      ssize = sizeof (SecFilt);
       fprintf (stderr, "secfilt: %d = %d bytes\n", catalog[0].Nsecfilt, catalog[0].Nsecfilt*catalog[0].Naverage*ssize);
       fprintf (stderr, "expect: %d, found: %d\n", size, (int)filestatus.st_size);
@@ -118,15 +106,7 @@
 
   if (mode & LOAD_AVES) {
-    /* read average values */
-    if (NewAverage) {
-      ALLOCATE (catalog[0].average, Average, MAX (catalog[0].Naverage, 1));
-      Nitems = catalog[0].Naverage;
-      nitems = Fread (catalog[0].average, sizeof(Average), Nitems, f, "average");
-    } else {
-      ALLOCATE (tmpaverage, OldAverage, MAX (catalog[0].Naverage, 1));
-      Nitems = catalog[0].Naverage;
-      nitems = Fread (tmpaverage, sizeof(OldAverage), Nitems, f, "oldaverage");
-      catalog[0].average = FixOldAverage (tmpaverage, Nitems);
-    }
+    ALLOCATE (catalog[0].average, Average, MAX (catalog[0].Naverage, 1));
+    Nitems = catalog[0].Naverage;
+    nitems = Fread (catalog[0].average, sizeof(Average), Nitems, f, "average");
     if (nitems != Nitems) {
       if (VERBOSE) fprintf (stderr, "failed to read averages from catalog file %s (%d vs %d)\n", catalog[0].filename, nitems, Nitems);
@@ -139,15 +119,7 @@
   
   if (mode & LOAD_MEAS) {
-    /* read measurements */
-    if (NewMeasure) {
-      ALLOCATE (catalog[0].measure, Measure, MAX (catalog[0].Nmeasure, 1));
-      Nitems = catalog[0].Nmeasure;
-      nitems = Fread (catalog[0].measure, sizeof(Measure), Nitems, f, "measure");
-    } else {
-      ALLOCATE (tmpmeasure, OldMeasure, MAX (catalog[0].Nmeasure, 1));
-      Nitems = catalog[0].Nmeasure;
-      nitems = Fread (tmpmeasure, sizeof(OldMeasure), Nitems, f, "oldmeasure");
-      catalog[0].measure = FixOldMeasure (tmpmeasure, Nitems);
-    }
+    ALLOCATE (catalog[0].measure, Measure, MAX (catalog[0].Nmeasure, 1));
+    Nitems = catalog[0].Nmeasure;
+    nitems = Fread (catalog[0].measure, sizeof(Measure), Nitems, f, "measure");
     if (nitems != Nitems) {
       if (VERBOSE) fprintf (stderr, "failed to read measures from catalog file %s (%d vs %d)\n", catalog[0].filename, nitems, Nitems);
@@ -174,15 +146,7 @@
   
   if (mode & LOAD_SECF) {
-    /* read missing */
-    if (NewSecFilt) {
-      Nitems = catalog[0].Naverage * catalog[0].Nsecfilt;
-      ALLOCATE (catalog[0].secfilt, SecFilt, MAX (Nitems, 1));
-      nitems = Fread (catalog[0].secfilt, sizeof(SecFilt), Nitems, f, "secfilt");
-    } else {
-      Nitems = catalog[0].Naverage * catalog[0].Nsecfilt;
-      ALLOCATE (tmpsecfilt, OldSecFilt, MAX (Nitems, 1));
-      nitems = Fread (tmpsecfilt, sizeof(OldSecFilt), Nitems, f, "oldsecfilt");
-      catalog[0].secfilt = FixOldSecFilt (tmpsecfilt, Nitems);
-    } 
+    Nitems = catalog[0].Naverage * catalog[0].Nsecfilt;
+    ALLOCATE (catalog[0].secfilt, SecFilt, MAX (Nitems, 1));
+    nitems = Fread (catalog[0].secfilt, sizeof(SecFilt), Nitems, f, "secfilt");
     if (nitems != Nitems) {
       if (VERBOSE) fprintf (stderr, "failed to read secondary filters from catalog file %s (%d vs %d)\n", catalog[0].filename, nitems, Nitems);
@@ -281,77 +245,2 @@
 }
 
-/**** tools to convert between formats - this happens automatically in load_catalog */
-
-Measure *FixOldMeasure (OldMeasure *in, int Nvalues) {
-
-  int i;
-  Measure *out;
-
-  ALLOCATE (out, Measure, Nvalues);
-
-  for (i = 0; i < Nvalues; i++) {
-    out[i].dR = in[i].dR;
-    out[i].dD = in[i].dD;
-    out[i].M  = in[i].M;
-    out[i].dM = in[i].dM;
-    out[i].Mcal = in[i].Mcal;
-    out[i].dophot = in[i].dophot;
-    out[i].source = in[i].source;
-    out[i].t = in[i].t;
-
-    out[i].dt = 0xffff;
-    out[i].averef = in[i].average & 0x00ffffff;
-    out[i].flags  = (in[i].average & 0xff000000) >> 24;
-  }
-
-  free (in);
-  
-  return (out);
-}
-
-Average *FixOldAverage (OldAverage *in, int Nvalues) {
-
-  int i;
-  Average *out;
-
-  ALLOCATE (out, Average, Nvalues);
-
-  for (i = 0; i < Nvalues; i++) {
-    out[i].R       = in[i].R;      
-    out[i].D       = in[i].D;      
-    out[i].M       = in[i].M;      
-    out[i].Xp      = in[i].Xp;     
-    out[i].Xm      = in[i].Xm;     
-    out[i].Nm      = in[i].Nm;     
-    out[i].Nn      = in[i].Nn;     
-    out[i].code    = in[i].code;   
-    out[i].offset  = in[i].offset; 
-    out[i].missing = in[i].missing;
-
-    out[i].dM = 0xffff;
-  }
-
-  free (in);
-  
-  return (out);
-}
-
-SecFilt *FixOldSecFilt (OldSecFilt *in, int Nvalues) {
-
-  int i;
-  SecFilt *out;
-
-  ALLOCATE (out, SecFilt, Nvalues);
-
-  for (i = 0; i < Nvalues; i++) {
-    out[i].M    = in[i].M;      
-    out[i].Xm   = in[i].Xm;      
-
-    out[i].dM   = 0xffff;
-  }
-
-  free (in);
-  
-  return (out);
-}
-
Index: /trunk/Ohana/src/libohana/src/photfits.c
===================================================================
--- /trunk/Ohana/src/libohana/src/photfits.c	(revision 3465)
+++ /trunk/Ohana/src/libohana/src/photfits.c	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 # define MAX_ORDER 3
 
Index: /trunk/Ohana/src/markrock/include/markrock.h
===================================================================
--- /trunk/Ohana/src/markrock/include/markrock.h	(revision 3465)
+++ /trunk/Ohana/src/markrock/include/markrock.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 typedef struct {
Index: /trunk/Ohana/src/markstar/include/markstar.h
===================================================================
--- /trunk/Ohana/src/markstar/include/markstar.h	(revision 3465)
+++ /trunk/Ohana/src/markstar/include/markstar.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 int    VERBOSE;
Index: /trunk/Ohana/src/misc/src/SAOobjects.c
===================================================================
--- /trunk/Ohana/src/misc/src/SAOobjects.c	(revision 3465)
+++ /trunk/Ohana/src/misc/src/SAOobjects.c	(revision 3466)
@@ -1,4 +1,4 @@
 # include "ohana.h"
-# include "loneos.h"
+# include "dvo.h"
 
 main (int argc, char **argv) {
Index: /trunk/Ohana/src/misc/src/fixcpt.c
===================================================================
--- /trunk/Ohana/src/misc/src/fixcpt.c	(revision 3465)
+++ /trunk/Ohana/src/misc/src/fixcpt.c	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 main (argc, argv)
Index: /trunk/Ohana/src/misc/src/fiximg.c
===================================================================
--- /trunk/Ohana/src/misc/src/fiximg.c	(revision 3465)
+++ /trunk/Ohana/src/misc/src/fiximg.c	(revision 3466)
@@ -1,4 +1,3 @@
 # include <ohana.h>
-# include <loneos.h>
 
 int main (int argc, char **argv) {
Index: /trunk/Ohana/src/misc/src/fixsimple.c
===================================================================
--- /trunk/Ohana/src/misc/src/fixsimple.c	(revision 3465)
+++ /trunk/Ohana/src/misc/src/fixsimple.c	(revision 3466)
@@ -1,4 +1,3 @@
 # include <ohana.h>
-# include <loneos.h>
 
 main (int argc, char **argv) {
Index: /trunk/Ohana/src/misc/src/mosastro.c
===================================================================
--- /trunk/Ohana/src/misc/src/mosastro.c	(revision 3465)
+++ /trunk/Ohana/src/misc/src/mosastro.c	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 # define NCCD 12
 
Index: /trunk/Ohana/src/mosastro/Makefile
===================================================================
--- /trunk/Ohana/src/mosastro/Makefile	(revision 3465)
+++ /trunk/Ohana/src/mosastro/Makefile	(revision 3466)
@@ -61,5 +61,6 @@
 $(SRC)/wfits.$(ARCH).o \
 $(SRC)/rtext.$(ARCH).o \
-$(SRC)/ConvertStars.$(ARCH).o
+$(SRC)/ConvertStars.$(ARCH).o \
+$(SRC)/SaveResiduals.$(ARCH).o
 
 mosastro: $(BIN)/mosastro.$(ARCH)
Index: /trunk/Ohana/src/mosastro/include/mosastro.h
===================================================================
--- /trunk/Ohana/src/mosastro/include/mosastro.h	(revision 3465)
+++ /trunk/Ohana/src/mosastro/include/mosastro.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 typedef struct {
@@ -73,4 +73,20 @@
 } Stars;
 
+typedef struct {
+  double Rraw, Draw; /* Sky Coords    - degrees */
+  float Praw, Qraw;  /* Tangent Plane - pixels  */
+  float Lraw, Mraw;  /* Focal Plane   - pixels  */
+  float Xraw, Yraw;  /* Chip Coords   - pixels  */
+
+  double Rref, Dref; /* Sky Coords    - degrees */
+  float Pref, Qref;  /* Tangent Plane - pixels  */
+  float Lref, Mref;  /* Focal Plane   - pixels  */
+  float Xref, Yref;  /* Chip Coords   - pixels  */
+
+  float Mcat, dMcat;
+  float Minst, dMinst;
+  char mask;
+} MatchData;
+
 int  ChipOrder;
 int  Nchip;
@@ -81,4 +97,8 @@
 double SIGMA;
 double SIGMA_LIM;
+double IMAG_MIN;
+double IMAG_MAX;
+double INST_BRIGHT;
+double ZERO_POINT;
 
 char StoneRegions[256];
@@ -95,4 +115,5 @@
 int VERBOSE;
 int NO_CHIPS;
+int SAVE_RESID;
 
 char GSCFILE[256];
@@ -116,5 +137,5 @@
 StarData *gcatalog (char *filename, int *Nstars);
 StarData *gptolemy (char *filename, int *NSTARS);
-double GetScatter ();
+double GetScatter (int *Nscatter, double *DL, double *DM, int bright);
 int find_dec_bands (CatStats *area);
 int load_ra_blocks (int Ndec, CatStats *area);
@@ -178,2 +199,6 @@
 void wstars (char *filename, Stars *stars, int Nstars, Header *header);
 int ConvertStars (Stars *data, int size, int nitems);
+int rfits (Chip *mychip);
+int rtext (Chip *mychip);
+void wfits (char *filename, Stars *stars, int Nstars, Header *header);
+int ConvertMatch (MatchData *data, int size, int nitems);
Index: /trunk/Ohana/src/mosastro/src/ConfigInit.c
===================================================================
--- /trunk/Ohana/src/mosastro/src/ConfigInit.c	(revision 3465)
+++ /trunk/Ohana/src/mosastro/src/ConfigInit.c	(revision 3466)
@@ -41,5 +41,10 @@
   GetConfig (config, "RADIUS",            "%lf", 0, &RADIUS);
   GetConfig (config, "SIGMA_LIM",         "%lf", 0, &SIGMA_LIM);
+  ScanConfig (config, "ZERO_PT",          "%lf", 0, &ZERO_POINT);
 
+  ScanConfig (config, "INST_MAG_MIN",     "%lf", 0, &IMAG_MIN);
+  ScanConfig (config, "INST_MAG_MAX",     "%lf", 0, &IMAG_MAX);
+  ScanConfig (config, "INST_BRIGHT",      "%lf", 0, &INST_BRIGHT);
+  
   free (config);
   free (file);
Index: /trunk/Ohana/src/mosastro/src/ConvertStars.c
===================================================================
--- /trunk/Ohana/src/mosastro/src/ConvertStars.c	(revision 3465)
+++ /trunk/Ohana/src/mosastro/src/ConvertStars.c	(revision 3466)
@@ -25,4 +25,5 @@
 
 # define STARS_SIZE 44
+# define MATCH_SIZE 104
 
 int ConvertStars (Stars *data, int size, int nitems) {
@@ -57,2 +58,46 @@
 # endif  
 } 
+
+int ConvertMatch (MatchData *data, int size, int nitems) {
+
+  int i;
+  unsigned char *byte, tmp;
+
+# ifdef BYTE_SWAP
+
+  if (size != MATCH_SIZE) {
+    fprintf (stderr, "mismatch in type sizes (MatchData) %d vs %d\n", size, MATCH_SIZE);
+    return (FALSE);
+  }
+
+  byte = (char *) data;
+  for (i = 0; i < nitems; i++, byte += size) {
+    SWAP_DBLE (0);   /* R */
+    SWAP_DBLE (8);   /* D */
+    SWAP_WORD (16);  /* P */
+    SWAP_WORD (20);  /* Q */
+    SWAP_WORD (24);  /* L */
+    SWAP_WORD (28);  /* M */
+    SWAP_WORD (32);  /* X */
+    SWAP_WORD (36);  /* Y */
+
+    SWAP_DBLE (40);  /* R */
+    SWAP_DBLE (40);  /* D */
+    SWAP_WORD (56);  /* P */
+    SWAP_WORD (60);  /* Q */
+    SWAP_WORD (64);  /* L */
+    SWAP_WORD (68);  /* M */
+    SWAP_WORD (72);  /* X */
+    SWAP_WORD (76);  /* Y */
+
+    SWAP_WORD (80);  /* Mcat */
+    SWAP_WORD (84);  /* dMcat */
+    SWAP_WORD (88);  /* Minst */
+    SWAP_WORD (92);  /* dMinst */
+  }
+  return (TRUE);
+
+# else
+  return (TRUE);
+# endif  
+} 
Index: /trunk/Ohana/src/mosastro/src/GetScatter.c
===================================================================
--- /trunk/Ohana/src/mosastro/src/GetScatter.c	(revision 3465)
+++ /trunk/Ohana/src/mosastro/src/GetScatter.c	(revision 3466)
@@ -2,12 +2,12 @@
 
 /* measure scatter on the focal plane */
-double GetScatter (int *Nscatter) {
+double GetScatter (int *Nscatter, double *DL, double *DM, int bright) {
 
   int i, j, Ntotal;
-  double dL, dM, dR2, dR;
+  double dL, dM, dL2, dM2, dl, dm, dR;
   StarData *raw, *ref;
 
-  Ntotal = dR2 = 0.0;
-
+  Ntotal = 0.0;
+  dL = dL2 = dM = dM2 = 0;
   for (i = 0; i < Nchip; i++) {
     raw = chip[i].raw;
@@ -15,12 +15,23 @@
     for (j = 0; j < chip[i].Nmatch; j++) {
       if (raw[j].mask) continue;
-      dL = raw[j].L - ref[j].L;
-      dM = raw[j].M - ref[j].M;
-      dR2 += dL*dL + dM*dM;
+      if (bright && (raw[j].Mag > INST_BRIGHT)) continue;
+      dl = raw[j].L - ref[j].L;
+      dm = raw[j].M - ref[j].M;
+      dL  += dl;
+      dL2 += SQ(dl);
+      dM  += dm;
+      dM2 += SQ(dm);
       Ntotal ++;
     }
   }
-  dR = sqrt (dR2 / Ntotal) * 3600.0 * field.project.cdelt1;
+  dL = sqrt (fabs(dL2 / Ntotal - (dL*dL) / (Ntotal*Ntotal)));
+  dM = sqrt (fabs(dM2 / Ntotal - (dM*dM) / (Ntotal*Ntotal)));
+  dR = hypot(dL, dM) * 3600.0 * field.project.cdelt1;
   *Nscatter = Ntotal;
+  *DL = dL;
+  *DM = dM;
   return (dR);
 }
+
+/* sigma is returned in arcsec, dL, dM are in pixels */
+/* return dL and dM independently as well */
Index: /trunk/Ohana/src/mosastro/src/LoadStars.c
===================================================================
--- /trunk/Ohana/src/mosastro/src/LoadStars.c	(revision 3465)
+++ /trunk/Ohana/src/mosastro/src/LoadStars.c	(revision 3466)
@@ -3,6 +3,5 @@
 int LoadStars (int Nfile, char **file) {
 
-  int i, j, itmp, Nbytes, nbytes, status, extend;
-  FILE *f;
+  int i, itmp, status, extend;
   time_t tsval;
   struct tm *tmval;
Index: /trunk/Ohana/src/mosastro/src/args.c
===================================================================
--- /trunk/Ohana/src/mosastro/src/args.c	(revision 3465)
+++ /trunk/Ohana/src/mosastro/src/args.c	(revision 3466)
@@ -31,4 +31,10 @@
   }
 
+  SAVE_RESID = FALSE;
+  if ((N = get_argument (*argc, argv, "-save-residuals"))) {
+    remove_argument (N, argc, argv);
+    SAVE_RESID = TRUE;
+  }
+
   CHIPS = (char *) NULL;
   if ((N = get_argument (*argc, argv, "-chips"))) {
Index: /trunk/Ohana/src/mosastro/src/clip.c
===================================================================
--- /trunk/Ohana/src/mosastro/src/clip.c	(revision 3465)
+++ /trunk/Ohana/src/mosastro/src/clip.c	(revision 3466)
@@ -4,10 +4,10 @@
 
   int i, j, Nscatter, Nmask, Nkeep;
-  double dL, dM, dV;
+  double DL, DM, dL, dM;
   double sigma;
   StarData *raw, *ref;
 
   Nmask = Nkeep = 0;
-  sigma = GetScatter (&Nscatter) / (3600.0 * field.project.cdelt1);
+  sigma = GetScatter (&Nscatter, &DL, &DM, FALSE);
 
   for (i = 0; i < Nchip; i++) {
@@ -17,6 +17,5 @@
       dL = raw[j].L - ref[j].L;
       dM = raw[j].M - ref[j].M;
-      dV = hypot(dL, dM);
-      if (dV > Nsigma*sigma) {
+      if ((fabs(dL) > Nsigma*DL) || (fabs(dM) > Nsigma*DM)) {
 	raw[j].mask = TRUE;
 	Nmask ++;
@@ -32,2 +31,5 @@
 }
 
+/*
+  sigma = sigma / (3600.0 * field.project.cdelt1);
+*/
Index: /trunk/Ohana/src/mosastro/src/match.c
===================================================================
--- /trunk/Ohana/src/mosastro/src/match.c	(revision 3465)
+++ /trunk/Ohana/src/mosastro/src/match.c	(revision 3466)
@@ -6,5 +6,5 @@
   int i, j, k, K, Ntotal;
   int Nmatch, NMATCH;
-  double dp, dq, radius, Radius;
+  double dp, dq, radius, Radius, exptime;
   double *p, *q, *P, *Q;
   int *U, *u;
@@ -45,4 +45,14 @@
     /* find star matches in the tangent plane coord system */
     for (j = k = 0; (j < chip[i].Nstars) && (k < Nrefcat); ) {
+
+      /** instrumental magnitude limits for raw data **/
+      if (IMAG_MIN && (chip[i].stars[u[j]].Mag - ZERO_POINT < IMAG_MIN)) {
+	j++;
+	continue;
+      }
+      if (IMAG_MAX && (chip[i].stars[u[j]].Mag - ZERO_POINT > IMAG_MAX)) {
+	j++;
+	continue;
+      }
       /* skip anything with dMag too large */
       if (SIGMA_LIM > 0.0) {
@@ -70,6 +80,7 @@
 	radius = hypot (dp, dq);
 	if (radius < Radius) {
+	  chip[i].ref[Nmatch] = refcat[U[k]];
 	  chip[i].raw[Nmatch] = chip[i].stars[u[j]];
-	  chip[i].ref[Nmatch] = refcat[U[k]];
+	  chip[i].raw[Nmatch].Mag -= ZERO_POINT;  /* raw in instrumental mags */
 	  Nmatch ++;
 	  if (Nmatch == NMATCH) {
Index: /trunk/Ohana/src/mosastro/src/mkmosaic.c
===================================================================
--- /trunk/Ohana/src/mosastro/src/mkmosaic.c	(revision 3465)
+++ /trunk/Ohana/src/mosastro/src/mkmosaic.c	(revision 3466)
@@ -4,5 +4,6 @@
 
   int Nastro;
-  double Xmin, Xmax, Ymin, Ymax, tmp, Cerror, Cprecise;
+  double Xmin, Xmax, Ymin, Ymax, tmp;
+  double DL, DM, Cerror, Cprecise;
   Header *header;
   char line[80];
@@ -16,4 +17,5 @@
   header[0].bitpix = -32;
   header[0].unsign = FALSE;
+  header[0].extend = FALSE;
   header[0].bscale = 1.0;
   header[0].bzero  = 0.0;
@@ -25,10 +27,20 @@
 
   /* calculate image-wide astrometry scatter */
-  Cerror   = GetScatter (&Nastro);
+  Cerror   = GetScatter (&Nastro, &DL, &DM, FALSE);
   Cprecise = Cerror / sqrt (Nastro);
   fits_modify (header, "CERROR",   "%lf", 1, Cerror);
+  fits_modify (header, "CERR_L",   "%lf", 1, DL*3600.0 * field.project.cdelt1);
+  fits_modify (header, "CERR_M",   "%lf", 1, DM*3600.0 * field.project.cdelt1);
+
   fits_modify (header, "CPRECISE", "%lf", 1, Cprecise);
-  fits_modify (header, "NSTARS",   "%d", 1, 1);  /*** modify addstar to allow NSTARS = 0 ***/
-  fits_modify (header, "NASTRO",   "%d", 1, Nastro);
+  fits_modify (header, "NSTARS",   "%d",  1, 0);  /*** modify addstar to allow NSTARS = 0 ***/
+  fits_modify (header, "NASTRO",   "%d",  1, Nastro);
+
+  GetScatter (&Nastro, &DL, &DM, TRUE);
+  fits_modify (header, "CERR_LB",  "%lf", 1, DL*3600.0 * field.project.cdelt1);
+  fits_modify (header, "CERR_MB",  "%lf", 1, DM*3600.0 * field.project.cdelt1);
+  fits_modify (header, "NBRIGHT",  "%d",  1, Nastro);
+
+  fprintf (stderr, "bright: %f %f %d\n", DL*3600.0 * field.project.cdelt1, DM*3600.0 * field.project.cdelt1, Nastro);
 
   /* make a better selection for the mosaic photcode? */
Index: /trunk/Ohana/src/mosastro/src/mosastro.c
===================================================================
--- /trunk/Ohana/src/mosastro/src/mosastro.c	(revision 3465)
+++ /trunk/Ohana/src/mosastro/src/mosastro.c	(revision 3466)
@@ -5,5 +5,6 @@
 
   int Nrefcat, Nastro;
-  double Cerror;
+  double Cerror, DL, DM;
+  double Scale;
   glob_t pglob;
   StarData *refcat;
@@ -29,4 +30,5 @@
   init_field ();  /** needs results from field stats **/
   init_chips ();  /** needs results from init_field **/
+  Scale = 3600.0 * field.project.cdelt1;
 
   /* use field model to get TP & FP coords */
@@ -41,42 +43,45 @@
   deproject_raw ();
   project_ref ();
-  Cerror   = GetScatter (&Nastro);
-  fprintf (stderr, "scatter (raw)  : %f for %d stars\n", Cerror, Nastro);
+  Cerror   = GetScatter (&Nastro, &DL, &DM, TRUE);
+  fprintf (stderr, "scatter (raw) : %6.4f for %d stars (%6.4f, %6.4f)\n", Cerror, Nastro, DL*Scale, DM*Scale);
   if ((DUMP != NULL) && !strcmp (DUMP, "rawmatch")) dump_match();
 
   grad = GetGradients ();
   FitGradients (grad);
-  Cerror   = GetScatter (&Nastro);
-  fprintf (stderr, "scatter (grad) : %f for %d stars\n", Cerror, Nastro);
+  Cerror   = GetScatter (&Nastro, &DL, &DM, TRUE);
+  fprintf (stderr, "scatter (grad) : %6.4f for %d stars (%6.4f, %6.4f)\n", Cerror, Nastro, DL*Scale, DM*Scale);
   if ((DUMP != NULL) && !strcmp (DUMP, "fitgrads")) dump_match();
+  Scale = 3600.0 * field.project.cdelt1;
 
   FitChips (ChipOrder);
-  Cerror   = GetScatter (&Nastro);
-  fprintf (stderr, "scatter (chip) : %f for %d stars\n", Cerror, Nastro);
+  Cerror   = GetScatter (&Nastro, &DL, &DM, TRUE);
+  fprintf (stderr, "scatter (chip) : %6.4f for %d stars (%6.4f, %6.4f)\n", Cerror, Nastro, DL*Scale, DM*Scale);
   if ((DUMP != NULL) && !strcmp (DUMP, "fitchips_unclip")) dump_match();
 
-  ClipOnFP (2.0);
-  Cerror   = GetScatter (&Nastro);
-  fprintf (stderr, "scatter (clip) : %f for %d stars\n", Cerror, Nastro);
+  ClipOnFP (2.5);
+  Cerror   = GetScatter (&Nastro, &DL, &DM, TRUE);
+  fprintf (stderr, "scatter (clip) : %6.4f for %d stars (%6.4f, %6.4f)\n", Cerror, Nastro, DL*Scale, DM*Scale);
 
   FitChips (ChipOrder);
-  Cerror   = GetScatter (&Nastro);
-  fprintf (stderr, "scatter (chip) : %f for %d stars\n", Cerror, Nastro);
+  Cerror   = GetScatter (&Nastro, &DL, &DM, TRUE);
+  fprintf (stderr, "scatter (chip) : %6.4f for %d stars (%6.4f, %6.4f)\n", Cerror, Nastro, DL*Scale, DM*Scale);
 
-  ClipOnFP (2.0);
-  Cerror   = GetScatter (&Nastro);
-  fprintf (stderr, "scatter (clip) : %f for %d stars\n", Cerror, Nastro);
+  ClipOnFP (2.5);
+  Cerror   = GetScatter (&Nastro, &DL, &DM, TRUE);
+  fprintf (stderr, "scatter (clip) : %6.4f for %d stars (%6.4f, %6.4f)\n", Cerror, Nastro, DL*Scale, DM*Scale);
 
   FitChips (ChipOrder);
-  Cerror   = GetScatter (&Nastro);
-  fprintf (stderr, "scatter (chip) : %f for %d stars\n", Cerror, Nastro);
+  Cerror   = GetScatter (&Nastro, &DL, &DM, TRUE);
+  fprintf (stderr, "scatter (chip) : %6.4f for %d stars (%6.4f, %6.4f)\n", Cerror, Nastro, DL*Scale, DM*Scale);
 
-  ClipOnFP (2.0);
-  Cerror   = GetScatter (&Nastro);
-  fprintf (stderr, "scatter (clip) : %f for %d stars\n", Cerror, Nastro);
+  ClipOnFP (2.5);
+  Cerror   = GetScatter (&Nastro, &DL, &DM, TRUE);
+  fprintf (stderr, "scatter (clip) : %6.4f for %d stars (%6.4f, %6.4f)\n", Cerror, Nastro, DL*Scale, DM*Scale);
 
   FitChips (ChipOrder);
-  Cerror   = GetScatter (&Nastro);
-  fprintf (stderr, "scatter (chip) : %f for %d stars\n", Cerror, Nastro);
+  Cerror   = GetScatter (&Nastro, &DL, &DM, FALSE);
+  fprintf (stderr, "scatter (brit) : %6.4f for %d stars (%6.4f, %6.4f)\n", Cerror, Nastro, DL*Scale, DM*Scale);
+  Cerror   = GetScatter (&Nastro, &DL, &DM, TRUE);
+  fprintf (stderr, "scatter (chip) : %6.4f for %d stars (%6.4f, %6.4f)\n", Cerror, Nastro, DL*Scale, DM*Scale);
   if ((DUMP != NULL) && !strcmp (DUMP, "fitchips")) dump_match();
 
Index: /trunk/Ohana/src/mosastro/src/output.c
===================================================================
--- /trunk/Ohana/src/mosastro/src/output.c	(revision 3465)
+++ /trunk/Ohana/src/mosastro/src/output.c	(revision 3466)
@@ -36,4 +36,9 @@
 
   header = mkmosaic (1, 1, 0, &field.project);
+  if (SAVE_RESID) {
+    SaveResiduals (f, header);
+    return;
+  }
+
   fwrite (header[0].buffer, 1, header[0].size, f);
   fclose (f);
Index: /trunk/Ohana/src/mosastro/src/rfits.c
===================================================================
--- /trunk/Ohana/src/mosastro/src/rfits.c	(revision 3465)
+++ /trunk/Ohana/src/mosastro/src/rfits.c	(revision 3466)
@@ -7,5 +7,4 @@
   FTable table;
   Stars *stars;
-  StarData *stardata;
 
   /* open file for stars */
Index: /trunk/Ohana/src/mosastro/src/wfits.c
===================================================================
--- /trunk/Ohana/src/mosastro/src/wfits.c	(revision 3465)
+++ /trunk/Ohana/src/mosastro/src/wfits.c	(revision 3466)
@@ -3,5 +3,4 @@
 void wfits (char *filename, Stars *stars, int Nstars, Header *header) {
 
-  int i;
   Matrix matrix;
   Header theader;
@@ -48,2 +47,3 @@
   return;
 }
+
Index: /trunk/Ohana/src/nightd/include/nightd.h
===================================================================
--- /trunk/Ohana/src/nightd/include/nightd.h	(revision 3465)
+++ /trunk/Ohana/src/nightd/include/nightd.h	(revision 3466)
@@ -1,4 +1,3 @@
 # include <ohana.h>
-# include <loneos.h>
 # include <signal.h>
 # include <errno.h>
@@ -40,4 +39,8 @@
 int vsystem (char *line);
 char *ExpandWords (char *line);
+int pcommand (char *line, int timeout);
+int WaitForPeriod ();
+int DoCommand (char *command, char *name);
+int freeargs (char **arglist);
 
 int PERIOD;
Index: /trunk/Ohana/src/nightd/src/ConfigInit.c
===================================================================
--- /trunk/Ohana/src/nightd/src/ConfigInit.c	(revision 3465)
+++ /trunk/Ohana/src/nightd/src/ConfigInit.c	(revision 3466)
@@ -17,11 +17,11 @@
   sprintf (file, "%s/.%src", home, Program);
   LoadConfig (SIGKILL);
-
+  return (TRUE);
 }
 
 void LoadConfig (int sig) {
 
-  int i, Ncmd, found;
-  char *config;
+  int i, Ncmd;
+  char *config, *found;
   char line[256];
   double tmp;
@@ -43,8 +43,8 @@
 
   /* load list of InitCommands */
-  found = TRUE;
+  found = config;
   Ncmd = 10;
   ALLOCATE (InitCommand, char *, Ncmd);
-  for (i = 0; found; i++) {
+  for (i = 0; found != NULL; i++) {
     ALLOCATE (InitCommand[i], char, 256);
     bzero (InitCommand[i], 256);
@@ -57,8 +57,8 @@
   
   /* load list of MainCommands */
-  found = TRUE;
+  found = config;
   Ncmd = 10;
   ALLOCATE (MainCommand, char *, Ncmd);
-  for (i = 0; found; i++) {
+  for (i = 0; found != NULL; i++) {
     ALLOCATE (MainCommand[i], char, 256);
     bzero (MainCommand[i], 256);
@@ -71,8 +71,8 @@
 
   /* load list of DoneCommands */
-  found = TRUE;
+  found = config;
   Ncmd = 10;
   ALLOCATE (DoneCommand, char *, Ncmd);
-  for (i = 0; found; i++) {
+  for (i = 0; found != NULL; i++) {
     ALLOCATE (DoneCommand[i], char, 256);
     bzero (DoneCommand[i], 256);
Index: /trunk/Ohana/src/nightd/src/DoCommand.c
===================================================================
--- /trunk/Ohana/src/nightd/src/DoCommand.c	(revision 3465)
+++ /trunk/Ohana/src/nightd/src/DoCommand.c	(revision 3466)
@@ -9,5 +9,4 @@
 int DoCommand (char *command, char *name) {
   
-  int status;
   char *line;
 
@@ -19,3 +18,4 @@
   }
   free (line);
+  return (TRUE);
 }
Index: /trunk/Ohana/src/nightd/src/SetSignals.c
===================================================================
--- /trunk/Ohana/src/nightd/src/SetSignals.c	(revision 3465)
+++ /trunk/Ohana/src/nightd/src/SetSignals.c	(revision 3466)
@@ -6,5 +6,5 @@
   signal (SIGUSR1, LoadConfig);
   signal (SIGUSR2, ToggleSuspend);
-
+  return (TRUE);
 }
 
Index: /trunk/Ohana/src/nightd/src/StartUp.c
===================================================================
--- /trunk/Ohana/src/nightd/src/StartUp.c	(revision 3465)
+++ /trunk/Ohana/src/nightd/src/StartUp.c	(revision 3466)
@@ -4,9 +4,8 @@
 
   int i;
-  int night, NightTime, status;
-  char user[256], machine[256], filename[256];
+  int night, NightTime;
+  char user[256], machine[256];
   float time;
   pid_t pid;
-  struct stat filestat;
 
   if (!SetPID (&pid, user, machine)) {
Index: /trunk/Ohana/src/nightd/src/misc.c
===================================================================
--- /trunk/Ohana/src/nightd/src/misc.c	(revision 3465)
+++ /trunk/Ohana/src/nightd/src/misc.c	(revision 3466)
@@ -136,11 +136,11 @@
 int WaitForPeriod () {
 
-  int Nsec, tsec;
+  int Nsec;
   struct timeval now;
-  struct tm *local;
   
   gettimeofday (&now, (struct timezone *) NULL);
   Nsec = PERIOD - (now.tv_sec % PERIOD);
   sleep (Nsec);
+  return (TRUE);
 }
 
@@ -151,5 +151,5 @@
   pid_t pid;
   char buffer[0x4000];
-  char *file, **arglist;
+  char **arglist;
 
   /* create pipes for communications */
@@ -235,5 +235,4 @@
 char **getargs (char *input) {
 
-  int i;
   char **args, *line, *p, *e;
   int Nargs, N, Nchar;
@@ -281,5 +280,5 @@
   }
   free (arglist);
-
+  return (TRUE);
 }
 
Index: /trunk/Ohana/src/nightd/src/nightd.c
===================================================================
--- /trunk/Ohana/src/nightd/src/nightd.c	(revision 3465)
+++ /trunk/Ohana/src/nightd/src/nightd.c	(revision 3466)
@@ -1,5 +1,5 @@
 # include "nightd.h"
 
-main (int argc, char **argv) {
+int main (int argc, char **argv) {
 
   Program = filebasename (argv[0]);
Index: /trunk/Ohana/src/photdbc/include/photdbc.h
===================================================================
--- /trunk/Ohana/src/photdbc/include/photdbc.h	(revision 3465)
+++ /trunk/Ohana/src/photdbc/include/photdbc.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 # include <signal.h>
 
Index: /trunk/Ohana/src/relphot/include/relphot.h
===================================================================
--- /trunk/Ohana/src/relphot/include/relphot.h	(revision 3465)
+++ /trunk/Ohana/src/relphot/include/relphot.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 /* # define GRID_V1 */
Index: /trunk/Ohana/src/uniphot/include/uniphot.h
===================================================================
--- /trunk/Ohana/src/uniphot/include/uniphot.h	(revision 3465)
+++ /trunk/Ohana/src/uniphot/include/uniphot.h	(revision 3466)
@@ -1,4 +1,4 @@
 # include <ohana.h>
-# include <loneos.h>
+# include <dvo.h>
 
 typedef struct {
