Index: /trunk/Ohana/src/addstar/include/addstar.h
===================================================================
--- /trunk/Ohana/src/addstar/include/addstar.h	(revision 5321)
+++ /trunk/Ohana/src/addstar/include/addstar.h	(revision 5322)
@@ -51,4 +51,21 @@
 char   STKeyword[64];
 
+/* these globals modify the behavior of gstars (KEEP) */
+double SNLIMIT;
+int    ACCEPT_ASTROM;  // accept even bad astrometry solutions (NASTRO == 0)
+int    TEXTMODE;       // force input file to be loaded as RAW
+char  *DUMP;           // dump out intermediate results
+int    XOVERSCAN;      // used to modify stored image dimensions 
+int    YOVERSCAN;      // used to modify stored image dimensions 
+int    XMIN;           // used to filter loaded star list 
+int    XMAX;           // used to filter loaded star list 
+int    YMIN;           // used to filter loaded star list 
+int    YMAX;           // used to filter loaded star list 
+double Latitude;       // carried into image structure from config
+
+/* these globals are used separately by both client and server (KEEP) */
+double ZeroPt;  // double check for consistency
+int    VERBOSE;
+
 /* add to options as an int / keep the global? */
 PhotCode *thiscode;
@@ -59,32 +76,18 @@
 /* globals set by command-line options (AddstarClientOptions) */
 /* move into AddstarClientOptions completely */
-# if (1)
-int   MODE;
-int   EXISTING_REGIONS;
-int   ONLY_MATCH;
-int   SKIP_MISSED;
-int   REPLACE;
-int   CLOSEST;
-int   NOSORT;
-int   UPDATE;
-int   ONLY_IMAGES;
-int   CALIBRATE;
+# if (0)
+int    MODE;
+int    EXISTING_REGIONS;
+int    ONLY_MATCH;
+int    SKIP_MISSED;
+int    REPLACE;
+int    CLOSEST;
+int    NOSORT;
+int    UPDATE;
+int    ONLY_IMAGES;
+int    CALIBRATE;
 double DEFAULT_RADIUS;   // XXX add to AddstarClientOptions
 double NSIGMA;           // XXX add to AddstarClientOptions
 # endif
-
-/* these globals modify the behavior of gstars (KEEP) */
-double SNLIMIT;
-int    ACCEPT_ASTROM;  // accept even bad astrometry solutions (NASTRO == 0)
-int    TEXTMODE;
-int    VERBOSE;
-char  *DUMP;
-int    XOVERSCAN;  // used to modify stored image dimensions 
-int    YOVERSCAN;  
-int    XMIN;       // used to filter loaded star list 
-int    XMAX;
-int    YMIN;
-int    YMAX;
-double Latitude;   // carried into image structure from config
 
 /* modify server behavoir (make this an addstar cleanup mode?) */
@@ -99,15 +102,9 @@
 time_t    TIMEREF;    // used by MODE REF
 GSCRegion UserPatch;  // used by MODE CAT
-char *SELECT_2MASS_QUALITY;  // used only by get2mass_as
-
-double ZeroPt;  // double check for consistency (image header / config file): KEEP global
-
-int   FITS_INPUT;     // unused??? 
-int   ADDREFS;        // unused??? 
-int   DUMP_MATCHES;   // un-set??? 
+char     *SELECT_2MASS_QUALITY;  // used only by get2mass_as
 
 /*** addstar prototypes ***/
 void       AddToCalibration       PROTO((Average *average, Measure *measure, Measure *new, int *next, int Nstar));
-void       ConfigInit             PROTO((int *argc, char **argv));
+AddstarClientOptions ConfigInit   PROTO((int *argc, char **argv));
 void       FindCalibration        PROTO((Image *image));
 int        FindDecBand            PROTO((double dec, double *DEC0, double *DEC1));
@@ -125,11 +122,11 @@
 float      airmass                PROTO((float secz_image, double ra, double dec, double st, double latitude));
 void       aregion                PROTO((GSCRegion *region, FILE *f, double ra, double dec));
-int        args                   PROTO((int argc, char **argv));
+AddstarClientOptions args         PROTO((int argc, char **argv, AddstarClientOptions options));
 void       check_permissions      PROTO((char *basefile));
 int        dump_rawstars          PROTO((Stars *stars, int Nstars));
 int        edge_check             PROTO((double *x1, double *y1, double *x2, double *y2));
-void       find_matches           PROTO((GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap));
-void       find_matches_closest   PROTO((GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap));
-void       find_matches_refstars  PROTO((GSCRegion *region, Stars **stars, int Nstars, Catalog *catalog));
+void       find_matches           PROTO((GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap, AddstarClientOptions options));
+void       find_matches_closest   PROTO((GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap, AddstarClientOptions options));
+void       find_matches_refstars  PROTO((GSCRegion *region, Stars **stars, int Nstars, Catalog *catalog, AddstarClientOptions options));
 Stars    **find_subset            PROTO((GSCRegion *region, Stars *stars, int Nstars, int *NSTARS));
 int        gcatalog               PROTO((Catalog *catalog));
@@ -189,8 +186,4 @@
 Missing *sort_missing (Average *average, int Naverage, Missing *missing, int Nmissing, int *next_miss);
 
-int InitServerSocket (char *hostname, SockAddress *Address);
-int WaitServerSocket (int InitSocket, SockAddress *Address, int *validIP, int Nvalid);
-int GetClientSocket (char *hostname);
-
 /** 
   there is an inconsistency to be resolved: fixed structures (like Image)
@@ -202,7 +195,15 @@
 **/
 
-AddstarClientOptions args_client (int argc, char **argv);
-
-int args_server (int argc, char **argv);
+/** function for client / server **/ 
+
+AddstarClientOptions args_client (int argc, char **argv, AddstarClientOptions options);
+
+void args_server (int argc, char **argv);
+
 int CheckPassword (int BindSocket);
 int NewImage (int BindSocket);
+
+int InitServerSocket (char *hostname, SockAddress *Address);
+int WaitServerSocket (int InitSocket, SockAddress *Address, int *validIP, int Nvalid);
+int GetClientSocket (char *hostname);
+
Index: /trunk/Ohana/src/addstar/src/ConfigInit.c
===================================================================
--- /trunk/Ohana/src/addstar/src/ConfigInit.c	(revision 5321)
+++ /trunk/Ohana/src/addstar/src/ConfigInit.c	(revision 5322)
@@ -1,9 +1,10 @@
 # include "addstar.h"
 
-void ConfigInit (int *argc, char **argv) {
+AddstarClientOptions ConfigInit (int *argc, char **argv) {
 
   char *config, *file;
   char RadiusWord[80];
   char PhotCodeFile[256];
+  AddstarClientOptions options;
 
   /*** load configuration info ***/
@@ -19,6 +20,5 @@
   XMIN = XMAX = YMIN = YMAX = 0;
 
-  ScanConfig (config, "RADIUS",                 "%s",  0, RadiusWord);
-  ScanConfig (config, "NSIGMA",                 "%lf", 0, &NSIGMA);
+  /* used by client to interpret input data */
   ScanConfig (config, "XOVERSCAN",              "%d",  0, &XOVERSCAN);
   ScanConfig (config, "YOVERSCAN",              "%d",  0, &YOVERSCAN);
@@ -28,16 +28,4 @@
   ScanConfig (config, "ADDSTAR_YMAX",           "%d",  0, &YMAX);
   ScanConfig (config, "MIN_SN_FSTAT",           "%lf", 0, &SNLIMIT);
-
-  ScanConfig (config, "2MASS_DIR_AS",           "%s",  0, TWO_MASS_DIR_AS);
-  ScanConfig (config, "2MASS_DIR_DR2",          "%s",  0, TWO_MASS_DIR_DR2);
-  ScanConfig (config, "GSCDIR",                 "%s",  0, GSCDIR);
-  ScanConfig (config, "USNO_CDROM",             "%s",  0, CDROM);
-
-  ScanConfig (config, "IMAGE_CATALOG",          "%s",  0, ImageCat);
-  ScanConfig (config, "GSCFILE",                "%s",  0, GSCFILE);
-  ScanConfig (config, "CATDIR",                 "%s",  0, CATDIR);
-  ScanConfig (config, "CATMODE",                "%s",  0, CATMODE);
-  ScanConfig (config, "CATFORMAT",              "%s",  0, CATFORMAT);
-  ScanConfig (config, "PHOTCODE_FILE",          "%s",  0, PhotCodeFile);
 
   /* used by parse_time to find time-related keywords */
@@ -55,4 +43,17 @@
   ScanConfig (config, "OBSERVATORY-LATITUDE",   "%lf", 0, &Latitude);
   ScanConfig (config, "SUBPIX_DATAFILE",        "%s",  0, SubpixDatafile);
+
+  /* location of needed data sources */
+  ScanConfig (config, "2MASS_DIR_AS",           "%s",  0, TWO_MASS_DIR_AS);
+  ScanConfig (config, "2MASS_DIR_DR2",          "%s",  0, TWO_MASS_DIR_DR2);
+  ScanConfig (config, "GSCDIR",                 "%s",  0, GSCDIR);
+  ScanConfig (config, "USNO_CDROM",             "%s",  0, CDROM);
+
+  ScanConfig (config, "IMAGE_CATALOG",          "%s",  0, ImageCat);
+  ScanConfig (config, "GSCFILE",                "%s",  0, GSCFILE);
+  ScanConfig (config, "CATDIR",                 "%s",  0, CATDIR);
+  ScanConfig (config, "CATMODE",                "%s",  0, CATMODE);
+  ScanConfig (config, "CATFORMAT",              "%s",  0, CATFORMAT);
+  ScanConfig (config, "PHOTCODE_FILE",          "%s",  0, PhotCodeFile);
 
   /* used by client/server setup */
@@ -92,8 +93,11 @@
   }
 
+  /* set the default search radius */
+  ScanConfig (config, "RADIUS",                 "%s",  0, RadiusWord);
+  ScanConfig (config, "NSIGMA",                 "%lf", 0, &options.Nsigma);
   if (!strcasecmp (RadiusWord, "header")) {
-    DEFAULT_RADIUS = 0;
+    options.radius = 0;
   } else {
-    DEFAULT_RADIUS = atof (RadiusWord);
+    options.radius = atof (RadiusWord);
   }
 
Index: /trunk/Ohana/src/addstar/src/NewImage.c
===================================================================
--- /trunk/Ohana/src/addstar/src/NewImage.c	(revision 5321)
+++ /trunk/Ohana/src/addstar/src/NewImage.c	(revision 5322)
@@ -38,5 +38,5 @@
 
   for (i = 0; i < Nimage; i++) {
-    fprintf (stderr, "name: %s\n", image[i].name);
+    fprintf (stderr, "name: %s, %d stars\n", image[i].name, Nstars);
   }
 
Index: /trunk/Ohana/src/addstar/src/SocketOps.c
===================================================================
--- /trunk/Ohana/src/addstar/src/SocketOps.c	(revision 5321)
+++ /trunk/Ohana/src/addstar/src/SocketOps.c	(revision 5322)
@@ -11,8 +11,10 @@
 
   host = gethostbyname (hostname);
+  fprintf (stderr, "errno: %d\n", h_errno);
+  fprintf (stderr, "host: %d\n", host);
 
   bzero (hostip, 80);
   for (i = 0; i < host[0].h_length; i++) {
-    sprintf (tmpline, "%3u", (0xff & host[0].h_addr[i]));
+    sprintf (tmpline, "%u", (0xff & host[0].h_addr[i]));
     strcat (hostip, tmpline);
     if (i < host[0].h_length - 1) strcat (hostip, ".");
Index: /trunk/Ohana/src/addstar/src/addstar.c
===================================================================
--- /trunk/Ohana/src/addstar/src/addstar.c	(revision 5321)
+++ /trunk/Ohana/src/addstar/src/addstar.c	(revision 5322)
@@ -10,4 +10,5 @@
   Catalog catalog;
   FITS_DB db;
+  AddstarClientOptions options;
 
   double dtime;
@@ -17,6 +18,6 @@
 
   SetSignals ();
-  ConfigInit (&argc, argv);
-  args (argc, argv);
+  options = ConfigInit (&argc, argv);
+  options = args (argc, argv, options);
 
   stars = NULL;
@@ -24,4 +25,9 @@
   regions = NULL;
   set_db (&db);
+  if (options.update) {
+    catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
+  } else {
+    catalog.catflags = LOAD_AVES | LOAD_MEAS      | LOAD_MISS | LOAD_SECF;
+  }
 
   if (SKYPROBE) load_subpix ();
@@ -33,5 +39,5 @@
   fprintf (stderr, "mark: lock_image_db: time %9.4f sec\n", dtime);
 
-  switch (MODE) {
+  switch (options.mode) {
   case M_IMAGE:
     stars = gstars (argv[1], &Nstars, &image);
@@ -50,5 +56,5 @@
     break;
   }
-  if (ONLY_MATCH || EXISTING_REGIONS) {
+  if (options.only_match || options.existing_regions) {
     regions = gregion_match (regions, &Nregions);
   }
@@ -64,5 +70,12 @@
     gettimeofday (&t1, NULL);
 
-    if (!load_pt_catalog (&catalog, &regions[i])) continue;
+    load_pt_catalog (&catalog, &regions[i]);
+
+    /* for only_match, skip empty catalogs XXX EAM : this leaves behind empty files */
+    if ((catalog.Nave_disk == 0) && options.only_match) {
+      unlock_catalog (&catalog);
+      continue;
+    }
+
     Nm = catalog.Nmeasure + catalog.Nmeas_off;
     Na = catalog.Naverage;
@@ -78,11 +91,11 @@
     gettimeofday (&t1, NULL);
 
-    switch (MODE) {
+    switch (options.mode) {
     case M_IMAGE:
       Nsubset = Nstars;
-      if (CLOSEST) {
-	find_matches_closest (&regions[i], stars, Nstars, &catalog, &image, overlap, Noverlap);
+      if (options.closest) {
+	find_matches_closest (&regions[i], stars, Nstars, &catalog, &image, overlap, Noverlap, options);
       } else {
-	find_matches (&regions[i], stars, Nstars, &catalog, &image, overlap, Noverlap);
+	find_matches (&regions[i], stars, Nstars, &catalog, &image, overlap, Noverlap, options);
       }
       break;
@@ -91,5 +104,5 @@
     case M_REFLIST:
       subset = find_subset (&regions[i], stars, Nstars, &Nsubset);
-      find_matches_refstars (&regions[i], subset, Nsubset, &catalog);
+      find_matches_refstars (&regions[i], subset, Nsubset, &catalog, options);
       if (Nsubset) free (subset);
       break;
@@ -105,5 +118,8 @@
       unlock_catalog (&catalog);
     } else {
-      save_pt_catalog (&catalog);
+      SetProtect (TRUE);
+      if (!options.only_images) wcatalog (&catalog);
+      SetProtect (FALSE);
+      unlock_catalog (&catalog);
     }
 
@@ -118,5 +134,5 @@
   fprintf (stderr, "mark: match: time %9.4f sec\n", dtime);
 
-  if (CALIBRATE) { FindCalibration (&image); }
+  if (options.calibrate) { FindCalibration (&image); }
 
   if (db.dbstate == LCK_EMPTY) {
@@ -127,5 +143,5 @@
 
   /* write out new image */
-  if (MODE == M_IMAGE) {
+  if (options.mode == M_IMAGE) {
     dvo_image_addrows (&db, &image, 1);
     SetProtect (TRUE);
@@ -143,8 +159,6 @@
 
 /* names:
-
    catalog - existing object db table
-   regions  - sky area which may or may contain data
+   regions - sky area which may or may not contain data
    patch   - RA,DEC bounded portion of sky
-   
 */
Index: /trunk/Ohana/src/addstar/src/addstarc.c
===================================================================
--- /trunk/Ohana/src/addstar/src/addstarc.c	(revision 5321)
+++ /trunk/Ohana/src/addstar/src/addstarc.c	(revision 5322)
@@ -10,6 +10,6 @@
 
   /* load config and options */
-  ConfigInit (&argc, argv);
-  options = args_client (argc, argv);
+  options = ConfigInit (&argc, argv);
+  options = args_client (argc, argv, options);
 
   /* load data */
Index: /trunk/Ohana/src/addstar/src/addstard.c
===================================================================
--- /trunk/Ohana/src/addstar/src/addstard.c	(revision 5321)
+++ /trunk/Ohana/src/addstar/src/addstard.c	(revision 5322)
@@ -6,6 +6,7 @@
   SockAddress Address;
   IOBuffer message;
+  AddstarClientOptions options;
 
-  ConfigInit (&argc, argv);
+  options = ConfigInit (&argc, argv);
   args_server (argc, argv);
 
Index: /trunk/Ohana/src/addstar/src/args.c
===================================================================
--- /trunk/Ohana/src/addstar/src/args.c	(revision 5321)
+++ /trunk/Ohana/src/addstar/src/args.c	(revision 5322)
@@ -1,3 +1,208 @@
 # include "addstar.h"
+void help (void);
+
+AddstarClientOptions args (int argc, char **argv, AddstarClientOptions options) {
+  
+  int N;
+
+  /* check for help request */
+  if (get_argument (argc, argv, "-help") ||
+      get_argument (argc, argv, "-h")) {
+    help ();
+  }
+
+  /*** check for command line options ***/
+
+  /* basic mode: image, list, refcat */
+  options.mode = M_IMAGE;
+  if ((N = get_argument (argc, argv, "-ref"))) {
+    options.mode = M_REFLIST;
+    remove_argument (N, &argc, argv);
+  }
+  if ((N = get_argument (argc, argv, "-cat"))) {
+    options.mode = M_REFCAT;
+    remove_argument (N, &argc, argv);
+  }
+
+  /*** provide additional data ***/ 
+  /* restrict to a portion of the sky? (REFCAT only) */
+  UserPatch.RA[0] = 0;
+  UserPatch.RA[1] = 360;
+  UserPatch.DEC[0] = -90;
+  UserPatch.DEC[1] = +90;
+  if ((N = get_argument (argc, argv, "-region"))) {
+    remove_argument (N, &argc, argv);
+    UserPatch.RA[0] = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    UserPatch.RA[1] = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    UserPatch.DEC[0] = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    UserPatch.DEC[1] = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  /* override any header PHOTCODE values */
+  thiscode = NULL;
+  options.photcode = 0;
+  if ((N = get_argument (argc, argv, "-p"))) {
+    remove_argument (N, &argc, argv);
+    options.photcode = GetPhotcodeCodebyName (argv[N]);
+    thiscode = GetPhotcodebyName (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  /* provide a time for dataset */
+  TIMEREF = 0; 
+  if ((N = get_argument (argc, argv, "-time"))) {
+    time_t tmp;
+    remove_argument (N, &argc, argv);
+    if (!str_to_time (argv[N], &tmp)) { 
+      fprintf (stderr, "syntax error in time\n");
+      exit (1);
+    }
+    TIMEREF = tmp;
+    remove_argument (N, &argc, argv);
+  }
+  /* provide a mosaic for distortion */
+  MOSAIC = NULL;
+  options.mosaic = FALSE;
+  if ((N = get_argument (argc, argv, "-mosaic"))) {
+    Header header;
+    ALLOCATE (MOSAIC, Coords, 1);
+
+    remove_argument (N, &argc, argv);
+    if (!fits_read_header (argv[N], &header)) {
+      fprintf (stderr, "ERROR: can't read header for mosaic %s\n", argv[N]);
+      exit (1);
+    }
+    if (!GetCoords (MOSAIC, &header)) {
+      fprintf (stderr, "ERROR: no astrometric solution in header\n");
+      exit (1);
+    }
+    if (strcmp(&MOSAIC[0].ctype[4], "-DIS")) {
+      fprintf (stderr, "ERROR: not a mosaic distortion header\n");
+      exit (1);
+    }
+    remove_argument (N, &argc, argv);
+    fits_free_header (&header);
+    options.mosaic = TRUE;
+  }
+  
+  /*** modify behavior ***/
+  /* only add to existing objects */
+  options.existing_regions = FALSE;
+  if ((N = get_argument (argc, argv, "-existing-regions"))) {
+    options.existing_regions = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  /* only add to existing objects */
+  options.only_match = FALSE;
+  if ((N = get_argument (argc, argv, "-only-match"))) {
+    options.only_match = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  /* don't add missed pts to Missed table (image only) */
+  options.skip_missed = FALSE;
+  if ((N = get_argument (argc, argv, "-missed"))) {
+    options.skip_missed = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  /* replace measurement, don't duplicate (ref/cat only) */
+  options.replace = FALSE;
+  if ((N = get_argument (argc, argv, "-replace"))) {
+    options.replace = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  /* use 'closest star' matching, rather than traditional method */
+  options.closest = FALSE;
+  if ((N = get_argument (argc, argv, "-closest"))) {
+    options.closest = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
+  /* don't re-sort the measure sequence */
+  options.nosort = FALSE;
+  if ((N = get_argument (argc, argv, "-nosort"))) {
+    options.nosort = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  /* only add new rows (-update) or re-write complete measure table (forces -nosort) */
+  options.update = FALSE;
+  if ((N = get_argument (argc, argv, "-update"))) {
+    options.update = TRUE;
+    options.nosort = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
+  /* only add image potion to image table */
+  options.only_images = FALSE;
+  if ((N = get_argument (argc, argv, "-image"))) {
+    options.only_images = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  /* apply average zpt offset calibration (image only) */
+  options.calibrate = FALSE;
+  if ((N = get_argument (argc, argv, "-cal"))) {
+    options.calibrate = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
+  /*** optional situations ***/
+  /* treat data specially for skyprobe (calibration, subpix) */ 
+  SKYPROBE = FALSE;
+  if ((N = get_argument (argc, argv, "-skyprobe"))) {
+    SKYPROBE = TRUE;
+    remove_argument (N, &argc, argv);
+    /* XXX EAM : define airmass calculation method?
+                 set calibrate to true
+		 perhaps a 'skyprobe' data format (for image.sky issue)
+    */
+  }
+  /* define 2MASS quality flags to keep */
+  SELECT_2MASS_QUALITY = NULL;
+  if ((N = get_argument (argc, argv, "-2massquality"))) {
+    remove_argument (N, &argc, argv);
+    SELECT_2MASS_QUALITY = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  /* accept bad header astrometry */
+  ACCEPT_ASTROM = FALSE;
+  if ((N = get_argument (argc, argv, "-accept"))) {
+    ACCEPT_ASTROM = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  /* force read of image database with mismatched NSTARS & size */ 
+  FORCE_READ = FALSE;
+  if ((N = get_argument (argc, argv, "-force"))) {
+    FORCE_READ = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  /* force read of image database with mismatched NSTARS & size */ 
+  TEXTMODE = FALSE;
+  if ((N = get_argument (argc, argv, "-textmode"))) {
+    TEXTMODE = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  /* extra error messages */
+  VERBOSE = FALSE;
+  if ((N = get_argument (argc, argv, "-v"))) {
+    VERBOSE = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  DUMP = NULL;
+  if ((N = get_argument (argc, argv, "-dump"))) {
+    remove_argument (N, &argc, argv);
+    DUMP = strcreate(argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+
+  if (argc != 2) {
+    fprintf (stderr, "USAGE: addstar (filename)\n");
+    fprintf (stderr, "USAGE: addstar -cat (catalog)\n");
+    fprintf (stderr, "USAGE: addstar -ref (filename)\n");
+    exit (2);
+  }
+  return (options);
+}
 
 void help () {
@@ -16,5 +221,5 @@
   fprintf (stderr, "  -time (YYYY/MM/DD,HH:MM:SS) : specify date/time (override header)\n");
   fprintf (stderr, "  -mosaic (filename)    	  : identify associated mosaic frame for chip image\n");
-  fprintf (stderr, "  -fits                 	  : input file is FITS table, not TEXT table\n");
+  fprintf (stderr, "  -textmode                	  : input file is RAW TEXT table, not FITS table\n");
   fprintf (stderr, "  -existing-regions           : only add measurements to existing catalog files\n");
   fprintf (stderr, "  -only-match           	  : only add measurements to existing objects\n");
@@ -36,207 +241,4 @@
 }
 
-int args (int argc, char **argv) {
-  
-  int N;
-
-  /* check for help request */
-  if (get_argument (argc, argv, "-help") ||
-      get_argument (argc, argv, "-h")) {
-    help ();
-  }
-
-  /*** check for command line options ***/
-
-  /* basic mode: image, list, refcat */
-  MODE = M_IMAGE;
-  if ((N = get_argument (argc, argv, "-ref"))) {
-    MODE = M_REFLIST;
-    remove_argument (N, &argc, argv);
-  }
-  if ((N = get_argument (argc, argv, "-cat"))) {
-    MODE = M_REFCAT;
-    remove_argument (N, &argc, argv);
-  }
-
-  /*** provide additional data ***/ 
-  /* restrict to a portion of the sky? (REFCAT only) */
-  UserPatch.RA[0] = 0;
-  UserPatch.RA[1] = 360;
-  UserPatch.DEC[0] = -90;
-  UserPatch.DEC[1] = +90;
-  if ((N = get_argument (argc, argv, "-region"))) {
-    remove_argument (N, &argc, argv);
-    UserPatch.RA[0] = atof (argv[N]);
-    remove_argument (N, &argc, argv);
-    UserPatch.RA[1] = atof (argv[N]);
-    remove_argument (N, &argc, argv);
-    UserPatch.DEC[0] = atof (argv[N]);
-    remove_argument (N, &argc, argv);
-    UserPatch.DEC[1] = atof (argv[N]);
-    remove_argument (N, &argc, argv);
-  }
-  /* override any header PHOTCODE values */
-  thiscode = NULL;
-  if ((N = get_argument (argc, argv, "-p"))) {
-    remove_argument (N, &argc, argv);
-    thiscode = GetPhotcodebyName (argv[N]);
-    remove_argument (N, &argc, argv);
-  }
-  /* provide a time for dataset */
-  TIMEREF = 0; 
-  if ((N = get_argument (argc, argv, "-time"))) {
-    remove_argument (N, &argc, argv);
-    if (!str_to_time (argv[N], &TIMEREF)) { 
-      fprintf (stderr, "syntax error in time\n");
-      exit (1);
-    }
-    remove_argument (N, &argc, argv);
-  }
-  /* provide a mosaic for distortion */
-  MOSAIC = NULL;
-  if ((N = get_argument (argc, argv, "-mosaic"))) {
-    Header header;
-    ALLOCATE (MOSAIC, Coords, 1);
-
-    remove_argument (N, &argc, argv);
-    if (!fits_read_header (argv[N], &header)) {
-      fprintf (stderr, "ERROR: can't read header for mosaic %s\n", argv[N]);
-      exit (1);
-    }
-    if (!GetCoords (MOSAIC, &header)) {
-      fprintf (stderr, "ERROR: no astrometric solution in header\n");
-      exit (1);
-    }
-    if (strcmp(&MOSAIC[0].ctype[4], "-DIS")) {
-      fprintf (stderr, "ERROR: not a mosaic distortion header\n");
-      exit (1);
-    }
-    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);
-  }
-  
-  /*** modify behavior ***/
-  /* only add to existing objects */
-  EXISTING_REGIONS = FALSE;
-  if ((N = get_argument (argc, argv, "-existing-regions"))) {
-    EXISTING_REGIONS = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* only add to existing objects */
-  ONLY_MATCH = FALSE;
-  if ((N = get_argument (argc, argv, "-only-match"))) {
-    ONLY_MATCH = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* don't add missed pts to Missed table (image only) */
-  SKIP_MISSED = FALSE;
-  if ((N = get_argument (argc, argv, "-missed"))) {
-    SKIP_MISSED = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* replace measurement, don't duplicate (ref/cat only) */
-  REPLACE = FALSE;
-  if ((N = get_argument (argc, argv, "-replace"))) {
-    REPLACE = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* use 'closest star' matching, rather than traditional method */
-  CLOSEST = FALSE;
-  if ((N = get_argument (argc, argv, "-closest"))) {
-    CLOSEST = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-
-  /* don't re-sort the measure sequence */
-  NOSORT = FALSE;
-  if ((N = get_argument (argc, argv, "-nosort"))) {
-    NOSORT = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* only add new rows (-update) or re-write complete measure table (forces -nosort) */
-  UPDATE = FALSE;
-  if ((N = get_argument (argc, argv, "-update"))) {
-    UPDATE = TRUE;
-    NOSORT = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-
-  /* only add image potion to image table */
-  ONLY_IMAGES = FALSE;
-  if ((N = get_argument (argc, argv, "-image"))) {
-    ONLY_IMAGES = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* apply average zpt offset calibration (image only) */
-  CALIBRATE = FALSE;
-  if ((N = get_argument (argc, argv, "-cal"))) {
-    CALIBRATE = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* define 2MASS quality flags to keep */
-  SELECT_2MASS_QUALITY = NULL;
-  if ((N = get_argument (argc, argv, "-2massquality"))) {
-    remove_argument (N, &argc, argv);
-    SELECT_2MASS_QUALITY = strcreate (argv[N]);
-    remove_argument (N, &argc, argv);
-  }
-
-  /*** optional situations ***/
-  /* treat data specially for skyprobe (calibration, subpix) */ 
-  SKYPROBE = FALSE;
-  if ((N = get_argument (argc, argv, "-skyprobe"))) {
-    SKYPROBE = TRUE;
-    remove_argument (N, &argc, argv);
-    /* XXX EAM : define airmass calculation method?
-                 set calibrate to true
-		 perhaps a 'skyprobe' data format (for image.sky issue)
-    */
-  }
-  /* accept bad header astrometry */
-  ACCEPT_ASTROM = FALSE;
-  if ((N = get_argument (argc, argv, "-accept"))) {
-    ACCEPT_ASTROM = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* force read of image database with mismatched NSTARS & size */ 
-  FORCE_READ = FALSE;
-  if ((N = get_argument (argc, argv, "-force"))) {
-    FORCE_READ = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* force read of image database with mismatched NSTARS & size */ 
-  TEXTMODE = FALSE;
-  if ((N = get_argument (argc, argv, "-textmode"))) {
-    TEXTMODE = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* extra error messages */
-  VERBOSE = FALSE;
-  if ((N = get_argument (argc, argv, "-v"))) {
-    VERBOSE = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  DUMP = NULL;
-  if ((N = get_argument (argc, argv, "-dump"))) {
-    remove_argument (N, &argc, argv);
-    DUMP = strcreate(argv[N]);
-    remove_argument (N, &argc, argv);
-  }
-
-
-  if (argc != 2) {
-    fprintf (stderr, "USAGE: addstar (filename)\n");
-    fprintf (stderr, "USAGE: addstar -cat (catalog)\n");
-    fprintf (stderr, "USAGE: addstar -ref (filename)\n");
-    exit (2);
-  }
-  return (TRUE);
-}
-
 /** addstar modes:
  
Index: /trunk/Ohana/src/addstar/src/args_client.c
===================================================================
--- /trunk/Ohana/src/addstar/src/args_client.c	(revision 5321)
+++ /trunk/Ohana/src/addstar/src/args_client.c	(revision 5322)
@@ -2,8 +2,7 @@
 void help (void);
 
-AddstarClientOptions args_client (int argc, char **argv) {
+AddstarClientOptions args_client (int argc, char **argv, AddstarClientOptions options) {
   
   int N;
-  AddstarClientOptions options;  // used to pass options to server
 
   /* check for help request */
Index: /trunk/Ohana/src/addstar/src/args_server.c
===================================================================
--- /trunk/Ohana/src/addstar/src/args_server.c	(revision 5321)
+++ /trunk/Ohana/src/addstar/src/args_server.c	(revision 5322)
@@ -2,5 +2,5 @@
 void help (void);
 
-int args_server (int argc, char **argv) {
+void args_server (int argc, char **argv) {
   
   int N;
@@ -12,16 +12,4 @@
   }
 
-  /* basic mode: image, list, refcat */
-  MODE = M_IMAGE;
-  if ((N = get_argument (argc, argv, "-ref"))) {
-    MODE = M_REFLIST;
-    remove_argument (N, &argc, argv);
-  }
-  if ((N = get_argument (argc, argv, "-cat"))) {
-    MODE = M_REFCAT;
-    remove_argument (N, &argc, argv);
-  }
-
-  /*** provide additional data ***/ 
   /* restrict to a portion of the sky? (REFCAT only) */
   UserPatch.RA[0] = 0;
@@ -40,107 +28,5 @@
     remove_argument (N, &argc, argv);
   }
-  /* override any header PHOTCODE values */
-  thiscode = NULL;
-  if ((N = get_argument (argc, argv, "-p"))) {
-    remove_argument (N, &argc, argv);
-    thiscode = GetPhotcodebyName (argv[N]);
-    remove_argument (N, &argc, argv);
-  }
-  /* provide a time for dataset */
-  TIMEREF = 0; 
-  if ((N = get_argument (argc, argv, "-time"))) {
-    remove_argument (N, &argc, argv);
-    if (!str_to_time (argv[N], &TIMEREF)) { 
-      fprintf (stderr, "syntax error in time\n");
-      exit (1);
-    }
-    remove_argument (N, &argc, argv);
-  }
-  /* provide a mosaic for distortion */
-  MOSAIC = NULL;
-  if ((N = get_argument (argc, argv, "-mosaic"))) {
-    Header header;
-    ALLOCATE (MOSAIC, Coords, 1);
-
-    remove_argument (N, &argc, argv);
-    if (!fits_read_header (argv[N], &header)) {
-      fprintf (stderr, "ERROR: can't read header for mosaic %s\n", argv[N]);
-      exit (1);
-    }
-    if (!GetCoords (MOSAIC, &header)) {
-      fprintf (stderr, "ERROR: no astrometric solution in header\n");
-      exit (1);
-    }
-    if (strcmp(&MOSAIC[0].ctype[4], "-DIS")) {
-      fprintf (stderr, "ERROR: not a mosaic distortion header\n");
-      exit (1);
-    }
-    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);
-  }
   
-  /*** modify behavior ***/
-  /* only add to existing objects */
-  EXISTING_REGIONS = FALSE;
-  if ((N = get_argument (argc, argv, "-existing-regions"))) {
-    EXISTING_REGIONS = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* only add to existing objects */
-  ONLY_MATCH = FALSE;
-  if ((N = get_argument (argc, argv, "-only-match"))) {
-    ONLY_MATCH = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* don't add missed pts to Missed table (image only) */
-  SKIP_MISSED = FALSE;
-  if ((N = get_argument (argc, argv, "-missed"))) {
-    SKIP_MISSED = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* replace measurement, don't duplicate (ref/cat only) */
-  REPLACE = FALSE;
-  if ((N = get_argument (argc, argv, "-replace"))) {
-    REPLACE = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* use 'closest star' matching, rather than traditional method */
-  CLOSEST = FALSE;
-  if ((N = get_argument (argc, argv, "-closest"))) {
-    CLOSEST = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-
-  /* don't re-sort the measure sequence */
-  NOSORT = FALSE;
-  if ((N = get_argument (argc, argv, "-nosort"))) {
-    NOSORT = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* only add new rows (-update) or re-write complete measure table (forces -nosort) */
-  UPDATE = FALSE;
-  if ((N = get_argument (argc, argv, "-update"))) {
-    UPDATE = TRUE;
-    NOSORT = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-
-  /* only add image potion to image table */
-  ONLY_IMAGES = FALSE;
-  if ((N = get_argument (argc, argv, "-image"))) {
-    ONLY_IMAGES = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* apply average zpt offset calibration (image only) */
-  CALIBRATE = FALSE;
-  if ((N = get_argument (argc, argv, "-cal"))) {
-    CALIBRATE = TRUE;
-    remove_argument (N, &argc, argv);
-  }
   /* define 2MASS quality flags to keep */
   SELECT_2MASS_QUALITY = NULL;
@@ -151,17 +37,4 @@
   }
 
-  /*** optional situations ***/
-  /* treat data specially for skyprobe (calibration, subpix) */ 
-  SKYPROBE = FALSE;
-  if ((N = get_argument (argc, argv, "-skyprobe"))) {
-    SKYPROBE = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  /* accept bad header astrometry */
-  ACCEPT_ASTROM = FALSE;
-  if ((N = get_argument (argc, argv, "-accept"))) {
-    ACCEPT_ASTROM = TRUE;
-    remove_argument (N, &argc, argv);
-  }
   /* force read of image database with mismatched NSTARS & size */ 
   FORCE_READ = FALSE;
@@ -170,20 +43,9 @@
     remove_argument (N, &argc, argv);
   }
-  /* force read of image database with mismatched NSTARS & size */ 
-  TEXTMODE = FALSE;
-  if ((N = get_argument (argc, argv, "-textmode"))) {
-    TEXTMODE = TRUE;
-    remove_argument (N, &argc, argv);
-  }
+
   /* extra error messages */
   VERBOSE = FALSE;
   if ((N = get_argument (argc, argv, "-v"))) {
     VERBOSE = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  DUMP = NULL;
-  if ((N = get_argument (argc, argv, "-dump"))) {
-    remove_argument (N, &argc, argv);
-    DUMP = strcreate(argv[N]);
     remove_argument (N, &argc, argv);
   }
@@ -199,50 +61,9 @@
 
   fprintf (stderr, "USAGE\n");
-  fprintf (stderr, "  addstar (filename)\n");
-  fprintf (stderr, "     add specified image (cmp format) to database\n\n");
-  fprintf (stderr, "  addstar -ref (filename)");
-  fprintf (stderr, "     add ASCII data (ra dec mag dmag) to database\n\n");
-  fprintf (stderr, "  addstar -cat (catalog)");
-  fprintf (stderr, "     add data from catalog (USNO/2MASS/GSC) to database\n\n");
-
-  fprintf (stderr, "  optional flags:\n");
-  fprintf (stderr, "  -region ra ra dec dec 	  : only add data in specified region (-ref mode only)\n");
-  fprintf (stderr, "  -p (photcode)         	  : specify photcode (override header)\n");
-  fprintf (stderr, "  -time (YYYY/MM/DD,HH:MM:SS) : specify date/time (override header)\n");
-  fprintf (stderr, "  -mosaic (filename)    	  : identify associated mosaic frame for chip image\n");
-  fprintf (stderr, "  -fits                 	  : input file is FITS table, not TEXT table\n");
-  fprintf (stderr, "  -existing-regions           : only add measurements to existing catalog files\n");
-  fprintf (stderr, "  -only-match           	  : only add measurements to existing objects\n");
-  fprintf (stderr, "  -missed               	  : skipped 'missed' entries\n");
-  fprintf (stderr, "  -replace              	  : replace time/photcode measurements (no duplication)\n");
-  fprintf (stderr, "  -closest             	  : use closest-star algorith\n");
-  fprintf (stderr, "  -nosort             	  : don't re-sort the measure entries (improves speed)\n");
-  fprintf (stderr, "  -update             	  : only update the new rows (foreces -nosort)\n");
-  fprintf (stderr, "  -image                	  : only insert image data\n");
-  fprintf (stderr, "  -cal                  	  : perform zero-point calibration\n");
-  fprintf (stderr, "  -skyprobe             	  : specify skyprobe mode\n");
-  fprintf (stderr, "  -accept               	  : accept bad astrometry from header\n");
+  fprintf (stderr, "  addstard (host)\n");
   fprintf (stderr, "  -force                	  : force read of database with inconsistent info\n");
   fprintf (stderr, "  -v                    	  : verbose mode\n");
-  fprintf (stderr, "  -dump (mode)          	  : output test data\n");
   fprintf (stderr, "  -help                 	  : this list\n");
   fprintf (stderr, "  -h                    	  : this list\n\n");
   exit (2);
 }
-
-/** addstar modes:
- 
-    addstar (image.smp)  - add cmp/smp image data to db
-    addstar -ref (file.dat) (photcode) 
-    addstar -cat (USNO/2MASS/GSC) -region (ra dec - ra dec)
-
-    -replace : ref/cat - replace existing match (photcode/time)
-    -match   : ref/cat - only add measures to existing averages
-
-    ref types: 
-    ASCII - RA,DEC,M,dM in a table
-
-    addstar 
-
-**/
-
Index: /trunk/Ohana/src/addstar/src/find_matches.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches.c	(revision 5321)
+++ /trunk/Ohana/src/addstar/src/find_matches.c	(revision 5322)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-void find_matches (GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap) {
+void find_matches (GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap, AddstarClientOptions options) {
 
   int i, j, n, N, J;
@@ -85,8 +85,8 @@
 
   /* choose a radius for matches */
-  if (DEFAULT_RADIUS == 0) {
-    RADIUS = NSIGMA * 0.02 * image[0].cerror;  /* 0.02 corrects cerror to arcsec from storage units */
+  if (options.radius == 0) {
+    RADIUS = options.Nsigma * 0.02 * image[0].cerror;  /* 0.02 corrects cerror to arcsec from storage units */
   } else {
-    RADIUS = DEFAULT_RADIUS; /* provided by config */
+    RADIUS = options.radius; /* provided by config */
   }
   RADIUS2 = RADIUS*RADIUS;
@@ -162,5 +162,5 @@
 
       /* adds the measurement to the calibration if appropriate color terms are found */
-      if (CALIBRATE) {
+      if (options.calibrate) {
 	AddToCalibration (&catalog[0].average[n], catalog[0].measure, &catalog[0].measure[Nmeas], next_meas, N);
       }
@@ -190,5 +190,5 @@
       Nmeas ++;
 
-      if (!UPDATE) {
+      if (!options.update) {
 	/* in UPDATE mode, newly calculated coordinates are not saved */
 	update_coords (&catalog[0].average[n], &catalog[0].measure[0], next_meas);
@@ -200,5 +200,5 @@
   /* add reference for undetected catalog stars */
   if (!strcmp (&image[0].coords.ctype[4], "-WRP")) RegisterMosaic (MOSAIC);
-  for (j = 0; (j < Nave) && !SKIP_MISSED; j++) {
+  for (j = 0; (j < Nave) && !options.skip_missed; j++) {
     n = N2[j];
     if (catalog[0].found[n] < 0) { 
@@ -224,5 +224,5 @@
   /* incorporate unmatched image stars, if this star is in field of this catalog */
   /* these new entries are all written out in UPDATE mode */ 
-  for (i = 0; (i < Nstars) && !ONLY_MATCH; i++) {
+  for (i = 0; (i < Nstars) && !options.only_match; i++) {
     /* make sure there is space for next entry */
     if (Nmeas >= NMEAS) {
@@ -285,5 +285,5 @@
 
     /** now add references from all previous non-detection observations of this spot on the sky */
-    for (j = 0; (j < Noverlap) && !SKIP_MISSED; j++) {
+    for (j = 0; (j < Noverlap) && !options.skip_missed; j++) {
       /* make sure there is space for next entry */
       if (Nmiss >= NMISS) {
@@ -316,5 +316,5 @@
   REALLOCATE (catalog[0].missing, Missing, Nmiss);
  
-  if (NOSORT) {
+  if (options.nosort) {
     catalog[0].sorted = FALSE;
   } else {
Index: /trunk/Ohana/src/addstar/src/find_matches_closest.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 5321)
+++ /trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 5322)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-void find_matches_closest (GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap) {
+void find_matches_closest (GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap, AddstarClientOptions options) {
 
   int i, j, n, N, J, Jmin;
@@ -85,8 +85,8 @@
 
   /* choose a radius for matches */
-  if (DEFAULT_RADIUS == 0) {
-    RADIUS = NSIGMA * 0.02 * image[0].cerror;  /* 0.02 corrects cerror to arcsec from storage units */
+  if (options.radius == 0) {
+    RADIUS = options.Nsigma * 0.02 * image[0].cerror;  /* 0.02 corrects cerror to arcsec from storage units */
   } else {
-    RADIUS = DEFAULT_RADIUS; /* provided by config */
+    RADIUS = options.radius; /* provided by config */
   }
   RADIUS2 = RADIUS*RADIUS;
@@ -178,5 +178,5 @@
 
     /* adds the measurement to the calibration if appropriate color terms are found */
-    if (CALIBRATE) {
+    if (options.calibrate) {
       AddToCalibration (&catalog[0].average[n], catalog[0].measure, &catalog[0].measure[Nmeas], next_meas, N);
     }
@@ -198,5 +198,5 @@
   /** add reference for undetected catalog stars **/
   if (!strcmp (&image[0].coords.ctype[4], "-WRP")) RegisterMosaic (MOSAIC);
-  for (j = 0; (j < Nave) && !SKIP_MISSED; j++) {
+  for (j = 0; (j < Nave) && !options.skip_missed; j++) {
     n = N2[j];
     if (catalog[0].found[n] < 0) { 
@@ -222,5 +222,5 @@
   /** incorporate unmatched image stars, if this star is in field of this catalog **/
   /* these new entries are all written out in UPDATE mode */ 
-  for (i = 0; (i < Nstars) && !ONLY_MATCH; i++) {
+  for (i = 0; (i < Nstars) && !options.only_match; i++) {
     /* make sure there is space for next entry */
     if (Nmeas >= NMEAS) {
@@ -283,5 +283,5 @@
 
     /** now add references from all previous non-detection observations of this spot on the sky */
-    for (j = 0; (j < Noverlap) && !SKIP_MISSED; j++) {
+    for (j = 0; (j < Noverlap) && !options.skip_missed; j++) {
       /* make sure there is space for next entry */
       if (Nmiss >= NMISS) {
@@ -314,5 +314,5 @@
   REALLOCATE (catalog[0].missing, Missing, Nmiss);
  
-  if (NOSORT) {
+  if (options.nosort) {
     catalog[0].sorted = FALSE;
   } else {
Index: /trunk/Ohana/src/addstar/src/find_matches_refstars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 5321)
+++ /trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 5322)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-void find_matches_refstars (GSCRegion *region, Stars **stars, int Nstars, Catalog *catalog) {
+void find_matches_refstars (GSCRegion *region, Stars **stars, int Nstars, Catalog *catalog, AddstarClientOptions options) {
 
   int i, j, k, n, m, N, J;
@@ -82,8 +82,8 @@
 
   /* choose a radius for matches */
-  if (DEFAULT_RADIUS == 0) {
+  if (options.radius == 0) {
     RADIUS = 2.0; /* hardwired default for refstars */
   } else {
-    RADIUS = DEFAULT_RADIUS; /* provided by config */
+    RADIUS = options.radius; /* provided by config */
   }
   RADIUS2 = RADIUS*RADIUS;
@@ -115,5 +115,5 @@
 
       /** in replace mode, search for entry and replace values M, dM, R, D */
-      if (REPLACE && replace_match (&catalog[0].average[n], &catalog[0].measure[m], stars[N])) continue;
+      if (options.replace && replace_match (&catalog[0].average[n], &catalog[0].measure[m], stars[N])) continue;
 
       /** insert star in measurement list */
@@ -189,5 +189,5 @@
      the reference up-to-date with known stars only */
 
-  for (i = 0; (i < Nstars) && !ONLY_MATCH; i++) {
+  for (i = 0; (i < Nstars) && !options.only_match; i++) {
     N = N1[i];
     if (stars[N][0].found >= 0) continue;
Index: /trunk/Ohana/src/addstar/src/gcatalog.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gcatalog.c	(revision 5321)
+++ /trunk/Ohana/src/addstar/src/gcatalog.c	(revision 5322)
@@ -9,10 +9,5 @@
 
   /* read catalog header */
-  if (UPDATE) {
-    mode = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
-  } else {
-    mode = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
-  }
-  if (!load_catalog (catalog, mode, VERBOSE)) {
+  if (!load_catalog (catalog, VERBOSE)) {
     fprintf (stderr, "ERROR: failure loading catalog\n");
     exit (1);
Index: /trunk/Ohana/src/addstar/src/load_pt_catalog.c
===================================================================
--- /trunk/Ohana/src/addstar/src/load_pt_catalog.c	(revision 5321)
+++ /trunk/Ohana/src/addstar/src/load_pt_catalog.c	(revision 5322)
@@ -11,6 +11,4 @@
   switch (lock_catalog (catalog, LCK_XCLD)) {
   case 0:
-    /* catalog file is locked.  this is an unexpected error because
-       ImageCat was NOT locked so we should be the only locking entity */
     fprintf (stderr, "ERROR: can't lock file %s\n", catalog[0].filename);
     exit (1);
@@ -19,5 +17,4 @@
     break;
   case 2:
-    if (ONLY_MATCH) return (FALSE);
     mkcatalog (region, catalog); /* fills in new header info */
     break;
@@ -25,2 +22,6 @@
   return (TRUE);
 }
+
+/* If the catalog file is locked, something weird is happening...  this is an unexpected error
+   because ImageCat was NOT locked so we should be the only locking entity.  However, this logic
+   breaks down for the server design: image and catalog are updated independently... */
Index: /trunk/Ohana/src/addstar/src/replace_match.c
===================================================================
--- /trunk/Ohana/src/addstar/src/replace_match.c	(revision 5321)
+++ /trunk/Ohana/src/addstar/src/replace_match.c	(revision 5322)
@@ -5,7 +5,5 @@
   int i;
 
-  if (!REPLACE) return (FALSE);
-
-  /** in replace mode, search for entry and replace values M, dM, R, D */
+  /* search for entry and replace values M, dM, R, D */
   for (i = 0; i < average[0].Nm; i++) {
     if (measure[i].source != thiscode[0].code) continue;
Index: /trunk/Ohana/src/addstar/src/wcatalog.c
===================================================================
--- /trunk/Ohana/src/addstar/src/wcatalog.c	(revision 5321)
+++ /trunk/Ohana/src/addstar/src/wcatalog.c	(revision 5322)
@@ -9,5 +9,6 @@
   fits_modify (&catalog[0].header, "SORTED",  "%t", 1, catalog[0].sorted);
 
-  if (UPDATE) {
+  /* if partial load, must use update */
+  if (catalog[0].Nmeas_off != 0) {
     if (!update_catalog (catalog, VERBOSE)) {
       fprintf (stderr, "ERROR: failure updating catalog\n");
