Index: trunk/Ohana/src/uniphot/Makefile
===================================================================
--- trunk/Ohana/src/uniphot/Makefile	(revision 39354)
+++ trunk/Ohana/src/uniphot/Makefile	(revision 39355)
@@ -75,4 +75,5 @@
 $(SRC)/update_catalog_setphot.$(ARCH).o \
 $(SRC)/update_catalog_setastrom.$(ARCH).o \
+$(SRC)/update_catalog_setgalmodel.$(ARCH).o \
 $(SRC)/repair_catalog_by_objID.$(ARCH).o \
 $(SRC)/SetSignals.$(ARCH).o	    \
@@ -87,4 +88,5 @@
 $(SRC)/update_catalog_setphot.$(ARCH).o \
 $(SRC)/update_catalog_setastrom.$(ARCH).o \
+$(SRC)/update_catalog_setgalmodel.$(ARCH).o \
 $(SRC)/repair_catalog_by_objID.$(ARCH).o \
 $(SRC)/initialize_setphot_client.$(ARCH).o \
Index: trunk/Ohana/src/uniphot/include/setphot.h
===================================================================
--- trunk/Ohana/src/uniphot/include/setphot.h	(revision 39354)
+++ trunk/Ohana/src/uniphot/include/setphot.h	(revision 39355)
@@ -62,4 +62,6 @@
 int          DCR_RESET;
 int          CAM_RESET;
+
+int          SET_GAL_MODEL;
 
 int          VERBOSE;
@@ -139,4 +141,4 @@
 int CamAstromCorrectionValue (int chipID, int filter, float Xccd, float Yccd, double *dX, double *dY);
 
-
+int           update_catalog_setgalmodel        PROTO((Catalog *catalog));
 int           update_catalog_setastrom        PROTO((Catalog *catalog));
Index: trunk/Ohana/src/uniphot/src/initialize_setphot.c
===================================================================
--- trunk/Ohana/src/uniphot/src/initialize_setphot.c	(revision 39354)
+++ trunk/Ohana/src/uniphot/src/initialize_setphot.c	(revision 39355)
@@ -78,4 +78,10 @@
     char *tmpfile = strcreate (argv[N]);
     CAM_PHOTOM_FILE = abspath (tmpfile, DVO_MAX_PATH);
+    remove_argument (N, &argc, argv);
+  }
+
+  SET_GAL_MODEL = FALSE;
+  if ((N = get_argument (argc, argv, "-setgalmodel"))) {
+    SET_GAL_MODEL = TRUE;
     remove_argument (N, &argc, argv);
   }
Index: trunk/Ohana/src/uniphot/src/initialize_setphot_client.c
===================================================================
--- trunk/Ohana/src/uniphot/src/initialize_setphot_client.c	(revision 39354)
+++ trunk/Ohana/src/uniphot/src/initialize_setphot_client.c	(revision 39355)
@@ -66,13 +66,14 @@
   }
 
+  // NOTE: I do not need to pass the cam-flat file to the 
+  // setphot clients because the database gets an update to 
+  // CATDIR/flatfield.fits which is loaded by setphot_client
   CAM_PHOTOM_FILE = NULL;
-/*
-  if ((N = get_argument (argc, argv, "-cam-flat"))) {
-    remove_argument (N, &argc, argv);
-    char *tmpfile = strcreate (argv[N]);
-    CAM_PHOTOM_FILE = abspath (tmpfile, DVO_MAX_PATH);
+
+  SET_GAL_MODEL = FALSE;
+  if ((N = get_argument (argc, argv, "-setgalmodel"))) {
+    SET_GAL_MODEL = TRUE;
     remove_argument (N, &argc, argv);
   }
-*/
 
   VERBOSE = FALSE;
Index: trunk/Ohana/src/uniphot/src/update_catalog_setgalmodel.c
===================================================================
--- trunk/Ohana/src/uniphot/src/update_catalog_setgalmodel.c	(revision 39354)
+++ trunk/Ohana/src/uniphot/src/update_catalog_setgalmodel.c	(revision 39355)
@@ -13,4 +13,11 @@
 
   CoordTransform *transform = InitTransform (COORD_CELESTIAL, COORD_GALACTIC);
+
+  // the typical motions do not vary so much as a function of position, we can use the
+  // median uR,uD values for all objects without stellar parameters
+
+  int Nsave = 0;
+  ALLOCATE_PTR (uRsave, double, catalog[0].Nstarpar);
+  ALLOCATE_PTR (uDsave, double, catalog[0].Nstarpar);
 
   // first set the proper motion based on Galactic rotation and solar motion
@@ -57,5 +64,31 @@
     average[i].uRgal = uR;
     average[i].uDgal = uD;
+
+    if (Nsave < catalog[0].Nstarpar) {
+      uRsave[Nsave] = uR;
+      uDsave[Nsave] = uD;
+      Nsave ++;
+    }
   }
+
+  // below we attempt to set the uRgal, uDgal values for objects
+  // without starpar data.  but if we do not have enough information, 
+  // give up and return
+  if (Nsave < 3) return TRUE;
+
+  dsort (uRsave, Nsave);
+  dsort (uDsave, Nsave);
+
+  int Nmid = 0.5*Nsave;
+  double uRmid = uRsave[Nmid];
+  double uDmid = uDsave[Nmid];
+
+  // set the value for unassigned stars based on the median uR,uD values for this patch
+  for (i = 0; i < catalog[0].Naverage; i++) {
+    if (isfinite(average[i].uRgal)) continue;
+
+    average[i].uRgal = uRmid;
+    average[i].uDgal = uDmid;
+  }  
 
   return (TRUE);
Index: trunk/Ohana/src/uniphot/src/update_dvo_setphot.c
===================================================================
--- trunk/Ohana/src/uniphot/src/update_dvo_setphot.c	(revision 39354)
+++ trunk/Ohana/src/uniphot/src/update_dvo_setphot.c	(revision 39355)
@@ -62,4 +62,7 @@
       catalog.catflags |= DVO_LOAD_SECFILT;
     }
+    if (SET_GAL_MODEL) {
+      catalog.catflags |= DVO_LOAD_STARPAR;
+    }
     catalog.Nsecfilt    = GetPhotcodeNsecfilt ();
 
@@ -85,4 +88,8 @@
     if (KH_FILE || DCR_FILE || CAM_ASTROM_FILE) {
       update_catalog_setastrom (&catalog);
+    }
+
+    if (SET_GAL_MODEL) {
+      update_catalog_setgalmodel (&catalog);
     }
 
@@ -166,4 +173,6 @@
     if (DCR_FILE)      	  { strextend (&command, "-DCR %s", DCR_FILE); }
     if (CAM_ASTROM_FILE)  { strextend (&command, "-CAM %s", CAM_ASTROM_FILE); }
+
+    if (SET_GAL_MODEL)    { strextend (&command, "-setgalmodel"); }
 
     if (KH_RESET)      	  { strextend (&command, "-KH-reset"); }
