Index: trunk/Ohana/src/addstar/include/loadgalphot.h
===================================================================
--- trunk/Ohana/src/addstar/include/loadgalphot.h	(revision 38598)
+++ trunk/Ohana/src/addstar/include/loadgalphot.h	(revision 38600)
@@ -36,9 +36,9 @@
 } GalPhotIDset;
 
-AddstarClientOptions args_loadgalphot (int argc, char **argv, AddstarClientOptions options);
+AddstarClientOptions args_loadgalphot (int *argc, char **argv, AddstarClientOptions options);
 
 int loadgalphot_table (SkyList *skylistInput, HostTable *hosts, char *filename, AddstarClientOptions *options);
 
-GalPhot_Stars *loadgalphot_readstars (char *filename, int *nstars);
+GalPhot_Stars *loadgalphot_readstars (char *filename, int *nstars, AddstarClientOptions *options);
 
 int loadgalphot_sortStars (GalPhot_Stars *stars, int Nstars);
Index: trunk/Ohana/src/addstar/src/args_loadgalphot.c
===================================================================
--- trunk/Ohana/src/addstar/src/args_loadgalphot.c	(revision 38598)
+++ trunk/Ohana/src/addstar/src/args_loadgalphot.c	(revision 38600)
@@ -4,11 +4,11 @@
 static void help (void);
 
-AddstarClientOptions args_loadgalphot (int argc, char **argv, AddstarClientOptions options) {
+AddstarClientOptions args_loadgalphot (int *argc, char **argv, AddstarClientOptions options) {
   
   int N;
 
   /* check for help request */
-  if (get_argument (argc, argv, "-help") ||
-      get_argument (argc, argv, "-h")) {
+  if (get_argument (*argc, argv, "-help") ||
+      get_argument (*argc, argv, "-h")) {
     help ();
   }
@@ -27,20 +27,20 @@
   HOST_ID = 0;
   PARALLEL = FALSE;
-  if ((N = get_argument (argc, argv, "-parallel"))) {
+  if ((N = get_argument (*argc, argv, "-parallel"))) {
     PARALLEL = TRUE;
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
   }
   // this is a test mode : rather than launching the remote jobs and waiting for completion,
   // relphot will simply list the remote command and wait for the user to signal completion
   PARALLEL_MANUAL = FALSE;
-  if ((N = get_argument (argc, argv, "-parallel-manual"))) {
+  if ((N = get_argument (*argc, argv, "-parallel-manual"))) {
     PARALLEL = TRUE; // -parallel-manual implies -parallel
     PARALLEL_MANUAL = TRUE;
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
   }
   // this is a test mode : rather than launching the relphot_client jobs remotely, they are 
   // run in serial via 'system'
   PARALLEL_SERIAL = FALSE;
-  if ((N = get_argument (argc, argv, "-parallel-serial"))) {
+  if ((N = get_argument (*argc, argv, "-parallel-serial"))) {
     if (PARALLEL_MANUAL) {
       fprintf (stderr, "ERROR: cannot mix -parallel-manual and -parallel-serial\n");
@@ -49,35 +49,46 @@
     PARALLEL = TRUE; // -parallel-serial implies -parallel
     PARALLEL_SERIAL = TRUE;
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
   }
 
   /* only add to existing regions */
   options.existing_regions = FALSE;
-  if ((N = get_argument (argc, argv, "-existing-regions"))) {
+  if ((N = get_argument (*argc, argv, "-existing-regions"))) {
     options.existing_regions = TRUE;
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
   }
   /* only add to existing objects */
   options.only_match = FALSE;
-  if ((N = get_argument (argc, argv, "-only-match"))) {
+  if ((N = get_argument (*argc, argv, "-only-match"))) {
     options.only_match = TRUE;
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
   }
   /* replace measurement, don't duplicate (ref/cat only) */
   options.replace = FALSE;
-  if ((N = get_argument (argc, argv, "-replace"))) {
+  if ((N = get_argument (*argc, argv, "-replace"))) {
     options.replace = TRUE;
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
+  }
+  /* override any header PHOTCODE values */
+  options.photcode = 0;
+  if ((N = get_argument (*argc, argv, "-p"))) {
+    remove_argument (N, argc, argv);
+    options.photcode = GetPhotcodeCodebyName (argv[N]);
+    remove_argument (N, argc, argv);
+  }
+  if ((N = get_argument (*argc, argv, "-photcode"))) {
+    remove_argument (N, argc, argv);
+    options.photcode = GetPhotcodeCodebyName (argv[N]);
+    remove_argument (N, argc, argv);
   }
 
   /* extra error messages */
   VERBOSE = FALSE;
-  if ((N = get_argument (argc, argv, "-v"))) {
+  if ((N = get_argument (*argc, argv, "-v"))) {
     VERBOSE = TRUE;
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
   }
 
   /* other addstar options which cannot be used in loadgalphot */
-  options.photcode = 0;
   options.timeref = 0; 
   options.mosaic = FALSE;
@@ -95,5 +106,5 @@
   DUMP = NULL;
 
-  if (argc < 2) {
+  if (*argc < 2) {
     fprintf (stderr, "USAGE: loadgalphot [options] (fitsfile) [..more files]\n");
     exit (2);
Index: trunk/Ohana/src/addstar/src/loadgalphot.c
===================================================================
--- trunk/Ohana/src/addstar/src/loadgalphot.c	(revision 38598)
+++ trunk/Ohana/src/addstar/src/loadgalphot.c	(revision 38600)
@@ -14,5 +14,5 @@
   // need to construct these options with args_loadgalphot...
   options = ConfigInit (&argc, argv);
-  options = args_loadgalphot (argc, argv, options);
+  options = args_loadgalphot (&argc, argv, options);
 
   // load the full sky description table (dvodb must exist)
Index: trunk/Ohana/src/addstar/src/loadgalphot_readstars.c
===================================================================
--- trunk/Ohana/src/addstar/src/loadgalphot_readstars.c	(revision 38598)
+++ trunk/Ohana/src/addstar/src/loadgalphot_readstars.c	(revision 38600)
@@ -15,6 +15,7 @@
 
 static float *chisqFit = NULL;
-
-GalPhot_Stars *loadgalphot_readstars (char *filename, int *nstars) {
+static float ZeroPt = 0;
+
+GalPhot_Stars *loadgalphot_readstars (char *filename, int *nstars, AddstarClientOptions *options) {
 
   // read in the full FITS files ('cause I don't have a partial read option)
@@ -67,4 +68,6 @@
     namehash[i][2] = -1;
   }
+
+  ZeroPt = GetZeroPoint();
 
   char name[256], tmpname[256];
@@ -228,4 +231,5 @@
     stars[i].galphot.modelType = MODEL_TYPE_gal[i];
     stars[i].galphot.detID     = ID_gal[i];
+    stars[i].galphot.photcode  = options->photcode;
 
     // I have a grid of measurements with (Flux, dFlux, Chisq) at each point
@@ -377,5 +381,5 @@
 
   // use bilinear interpolation to choose Flux @ (Xmin,Ymin)?
-  galphot->mag    = -2.5*log10(flux[iMin]); // correct for exptime?
+  galphot->mag    = -2.5*log10(flux[iMin]) + ZeroPt; // correct for exptime?
   galphot->magErr = sqrt(fluxErr[iMin]) / flux[iMin];
   galphot->chisq  = chisqMin;
Index: trunk/Ohana/src/addstar/src/loadgalphot_table.c
===================================================================
--- trunk/Ohana/src/addstar/src/loadgalphot_table.c	(revision 38598)
+++ trunk/Ohana/src/addstar/src/loadgalphot_table.c	(revision 38600)
@@ -6,5 +6,5 @@
   int i, Nstars;
 
-  GalPhot_Stars *stars = loadgalphot_readstars (filename, &Nstars);
+  GalPhot_Stars *stars = loadgalphot_readstars (filename, &Nstars, options);
 
   // sort the stars by RA
Index: trunk/Ohana/src/libdvo/include/dvodb.h
===================================================================
--- trunk/Ohana/src/libdvo/include/dvodb.h	(revision 38598)
+++ trunk/Ohana/src/libdvo/include/dvodb.h	(revision 38600)
@@ -304,4 +304,16 @@
       AVE_REF_COLOR_RED,
       AVE_PHOT, // photometry class of values
+      AVE_GAL_MAG,
+      AVE_GAL_MAG_ERR,
+      AVE_GAL_MAJ,
+      AVE_GAL_MAJ_ERR,
+      AVE_GAL_MIN,
+      AVE_GAL_MIN_ERR,
+      AVE_GAL_THETA,
+      AVE_GAL_THETA_ERR,
+      AVE_GAL_INDEX,
+      AVE_GAL_CHISQ,
+      AVE_GAL_NPIX,
+      AVE_GAL_TYPE,
       AVE_E_BV,		      // extinction (mags)
       AVE_E_BV_ERR,
Index: trunk/Ohana/src/libdvo/src/dbFields.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dbFields.c	(revision 38598)
+++ trunk/Ohana/src/libdvo/src/dbFields.c	(revision 38600)
@@ -159,4 +159,24 @@
   }
   return FALSE;
+}
+
+int dbFieldNeedStarpar (dbField *fields, int Nfields, int isAverage) {
+  int i;
+  for (i = 0; i < Nfields; i++) {
+    if (isAverage) {
+      if (fields[i].ID == AVE_E_BV)             return TRUE;
+      if (fields[i].ID == AVE_E_BV_ERR)         return TRUE;
+      if (fields[i].ID == AVE_DISTANCE_MOD)     return TRUE;
+      if (fields[i].ID == AVE_DISTANCE_MOD_ERR) return TRUE;
+      if (fields[i].ID == AVE_M_R)              return TRUE;
+      if (fields[i].ID == AVE_M_R_ERR)          return TRUE;
+      if (fields[i].ID == AVE_FEH)              return TRUE;
+      if (fields[i].ID == AVE_FEH_ERR)          return TRUE;
+      if (fields[i].ID == AVE_URA_GALMODEL)     return TRUE;
+      if (fields[i].ID == AVE_UDEC_GALMODEL)    return TRUE;
+      if (fields[i].ID == AVE_RA_GALMODEL)      return TRUE;
+      if (fields[i].ID == AVE_DEC_GALMODEL)     return TRUE;
+    }
+  }
 }
 
@@ -690,4 +710,17 @@
   if (!strcasecmp (fieldName, "REF_COLOR_RED"))  ESCAPE (AVE_REF_COLOR_RED,  OPIHI_FLT);
 
+  if (!strcasecmp (fieldName, "GAL_MAG"    ))      ESCAPE (AVE_GAL_MAG       ,   OPIHI_FLT);
+  if (!strcasecmp (fieldName, "GAL_MAG_ERR"))      ESCAPE (AVE_GAL_MAG_ERR   ,   OPIHI_FLT);
+  if (!strcasecmp (fieldName, "GAL_MAJ"    ))      ESCAPE (AVE_GAL_MAJ       ,   OPIHI_FLT);
+  if (!strcasecmp (fieldName, "GAL_MAJ_ERR"))      ESCAPE (AVE_GAL_MAJ_ERR   ,   OPIHI_FLT);
+  if (!strcasecmp (fieldName, "GAL_MIN"    ))      ESCAPE (AVE_GAL_MIN       ,   OPIHI_FLT);
+  if (!strcasecmp (fieldName, "GAL_MIN_ERR"))      ESCAPE (AVE_GAL_MIN_ERR   ,   OPIHI_FLT);
+  if (!strcasecmp (fieldName, "GAL_THETA"  ))      ESCAPE (AVE_GAL_THETA     ,   OPIHI_FLT);
+  if (!strcasecmp (fieldName, "GAL_THETA_ERR"))    ESCAPE (AVE_GAL_THETA_ERR ,   OPIHI_FLT);
+  if (!strcasecmp (fieldName, "GAL_INDEX"  ))      ESCAPE (AVE_GAL_INDEX     ,   OPIHI_FLT);
+  if (!strcasecmp (fieldName, "GAL_CHISQ"  ))      ESCAPE (AVE_GAL_CHISQ     ,   OPIHI_FLT);
+  if (!strcasecmp (fieldName, "GAL_NPIX"   ))      ESCAPE (AVE_GAL_NPIX      ,   OPIHI_FLT);
+  if (!strcasecmp (fieldName, "GAL_TYPE"   ))      ESCAPE (AVE_GAL_TYPE      ,   OPIHI_FLT);
+
   if (!strcasecmp (fieldName, "E_BV"))             ESCAPE (AVE_E_BV          ,   OPIHI_FLT);
   if (!strcasecmp (fieldName, "E_BV_ERR"))         ESCAPE (AVE_E_BV_ERR      ,   OPIHI_FLT);
Index: trunk/Ohana/src/opihi/dvo/avextract.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/avextract.c	(revision 38598)
+++ trunk/Ohana/src/opihi/dvo/avextract.c	(revision 38600)
@@ -167,4 +167,5 @@
   int needLensobj = dbFieldNeedLensobj (fields, Nfields);
   int needStarpar = dbFieldNeedStarpar (fields, Nfields, TRUE);
+  int needGalphot = dbFieldNeedGalphot (fields, Nfields, TRUE);
 
   // grab data from all selected sky regions
