Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/Makefile
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/Makefile	(revision 37421)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/Makefile	(revision 37422)
@@ -250,5 +250,4 @@
 $(SRC)/SkyRegionUtils.$(ARCH).o \
 $(SRC)/args_loadstarpar.$(ARCH).o \
-$(SRC)/coord_transforms.$(ARCH).o \
 $(SRC)/find_matches_starpar.$(ARCH).o \
 $(SRC)/loadstarpar_catalog.$(ARCH).o \
@@ -268,5 +267,4 @@
 $(SRC)/SkyRegionUtils.$(ARCH).o \
 $(SRC)/args_loadstarpar.$(ARCH).o \
-$(SRC)/coord_transforms.$(ARCH).o \
 $(SRC)/find_matches_starpar.$(ARCH).o \
 $(SRC)/loadstarpar_catalog.$(ARCH).o \
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/include/loadstarpar.h
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/include/loadstarpar.h	(revision 37421)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/include/loadstarpar.h	(revision 37422)
@@ -3,5 +3,5 @@
   double R, D;
   StarPar starpar;
-  int flag; // XXX how is this used?
+  int flag; // in a subset?
   int found; // assigned to an object?
 } StarPar_Stars;
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/args_loadstarpar.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/args_loadstarpar.c	(revision 37421)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/args_loadstarpar.c	(revision 37422)
@@ -23,4 +23,33 @@
   UserPatch.Dmin = -90;
   UserPatch.Dmax = +90;
+
+  // XXX for the moment, make this selection manual.  it needs to be automatic 
+  // based on the state of the SkyTable
+  HOST_ID = 0;
+  PARALLEL = FALSE;
+  if ((N = get_argument (argc, argv, "-parallel"))) {
+    PARALLEL = TRUE;
+    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"))) {
+    PARALLEL = TRUE; // -parallel-manual implies -parallel
+    PARALLEL_MANUAL = TRUE;
+    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 (PARALLEL_MANUAL) {
+      fprintf (stderr, "ERROR: cannot mix -parallel-manual and -parallel-serial\n");
+      exit (1);
+    }
+    PARALLEL = TRUE; // -parallel-serial implies -parallel
+    PARALLEL_SERIAL = TRUE;
+    remove_argument (N, &argc, argv);
+  }
 
   /* only add to existing regions */
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/coord_transforms.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/coord_transforms.c	(revision 37421)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/coord_transforms.c	(revision 37422)
@@ -1,4 +1,10 @@
 # include "addstar.h"
 # include "loadstarpar.h"
+
+// values used by libdvo/coord_systems (from Liu et al 2011, A&A 526, A16):
+// Liu etal and Reid etal disagree at the 0.3 arcsec level
+// transform->phi =  62.8717488056*RAD_DEG;
+// transform->Xo  =  32.9319185700*RAD_DEG;
+// transform->xo  = 282.8594812080;
 
 int galactic_to_celestial (double *R, double *D, double l, double b) {
@@ -7,2 +13,64 @@
   abort();
 }
+
+int celestial_to_galactic (double *l, double *b, double R, double D) {
+
+_angp = np.radians(192.859508333) #  12h 51m 26.282s (J2000)
+_dngp = np.radians(27.128336111)  # +27d 07' 42.01" (J2000) 
+_l0   = np.radians(32.932)
+_ce   = np.cos(_dngp)
+_se   = np.sin(_dngp)
+
+
+
+}
+
+
+
+
+/*** python version from LSD (Mario Juric)
+
+# Appendix of Reid et al. (http://adsabs.harvard.edu/cgi-bin/bib_query?2004ApJ...616..872R)
+# This convention is also used by LAMBDA/WMAP (http://lambda.gsfc.nasa.gov/toolbox/tb_coordconv.cfm)
+_angp = np.radians(192.859508333) #  12h 51m 26.282s (J2000)
+_dngp = np.radians(27.128336111)  # +27d 07' 42.01" (J2000) 
+_l0   = np.radians(32.932)
+_ce   = np.cos(_dngp)
+_se   = np.sin(_dngp)
+
+def equgal(ra, dec):
+	ra = np.radians(ra)
+	dec = np.radians(dec)
+
+	cd, sd = np.cos(dec), np.sin(dec)
+	ca, sa = np.cos(ra - _angp), np.sin(ra - _angp)
+
+	sb = cd*_ce*ca + sd*_se
+	l = np.arctan2(sd - sb*_se, cd*sa*_ce) + _l0
+	b = np.arcsin(sb)
+
+	l = np.where(l < 0, l + 2.*np.pi, l)
+
+	l = np.degrees(l)
+	b = np.degrees(b)
+
+	return NamedList(('l', l), ('b', b))
+
+def galequ(l, b):
+	l = np.radians(l)
+	b = np.radians(b)
+
+	cb, sb = np.cos(b), np.sin(b)
+	cl, sl = np.cos(l-_l0), np.sin(l-_l0)
+
+	ra  = np.arctan2(cb*cl, sb*_ce-cb*_se*sl) + _angp
+	dec = np.arcsin(cb*_ce*sl + sb*_se)
+
+	ra = np.where(ra < 0, ra + 2.*np.pi, ra)
+
+	ra = np.degrees(ra)
+	dec = np.degrees(dec)
+
+	return NamedList(('ra', ra), ('dec', dec))
+
+ ***/
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches_starpar.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches_starpar.c	(revision 37421)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches_starpar.c	(revision 37422)
@@ -151,5 +151,5 @@
   }
 
-# if (0)
+# if (1)
   /** incorporate unmatched image stars? **/
   for (i = 0; (i < Nstars) && !options->only_match; i++) {
@@ -157,10 +157,10 @@
     // skip already matched stars
     if (stars[i].found != -1) continue;
-    if (!IN_REGION (stars[i].average.R, stars[i].average.D)) continue;
+    if (!IN_REGION (stars[i].R, stars[i].D)) continue;
 
     /* make sure there is space for next entry */
     if (Nstarpar >= NSTARPAR) {
       NSTARPAR = Nstarpar + 1000;
-      REALLOCATE (catalog[0].starpar, Starpar, NSTARPAR);
+      REALLOCATE (catalog[0].starpar, StarPar, NSTARPAR);
     }
     if (Nave >= NAVE) {
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar.c	(revision 37421)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar.c	(revision 37422)
@@ -25,9 +25,22 @@
   
   // load the list of hosts
-  HostTable *hosts = HostTableLoad (CATDIR, sky->hosts);
-  if (!hosts) {
-    fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR);
-    exit (1);
-  }    
+  HostTable *hosts = NULL;
+  if (PARALLEL) {
+    hosts = HostTableLoad (CATDIR, sky->hosts);
+    if (!hosts) {
+      fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR);
+      exit (1);
+    }    
+
+    // ensure that the paths are absolute path names
+    for (i = 0; i < hosts->Nhosts; i++) {
+      char *tmppath = abspath (hosts->hosts[i].pathname, DVO_MAX_PATH);
+      free (hosts->hosts[i].pathname);
+      hosts->hosts[i].pathname = tmppath;
+    }
+
+    // set up the array of active hosts
+    init_remote_hosts ();
+  }
 
   // generate the subset matching the user-selected region
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_make_subset.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_make_subset.c	(revision 37421)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_make_subset.c	(revision 37422)
@@ -35,4 +35,6 @@
     Nsubset ++;
 
+    stars[i].flag = TRUE;
+
     CHECK_REALLOCATE (subset, StarPar_Stars, NSUBSET, Nsubset, 10000);
   }
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_readstars.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_readstars.c	(revision 37421)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_readstars.c	(revision 37422)
@@ -44,5 +44,4 @@
     return (NULL);
   }
-  fclose (f);
 
   char type[16];
@@ -75,4 +74,5 @@
     return NULL;
   }
+  fclose (f);
 
   double *errImage = (double *) matrix.buffer;
@@ -93,4 +93,8 @@
   ALLOCATE (stars, StarPar_Stars, NSTARS);
 
+  // libdvo uses Liu et al 2011 (A&A 526, A16) for default galactic coords,
+  // but Greg Green / LSD use the older Reid et al 2004 (ApJ 616, 872) definition
+  CoordTransform *transform = InitTransform (COORD_GALACTIC_REID_2004, COORD_CELESTIAL);
+
   for (i = 0; i < NstarsIn; i++) {
 
@@ -100,5 +104,5 @@
 
     double R, D;
-    galactic_to_celestial (&R, &D, glon[i], glat[i]);
+    ApplyTransform (&R, &D, glon[i], glat[i], transform);
 
     Rmin = MIN (Rmin, R);
@@ -114,4 +118,6 @@
     stars[Nstars].R = R;
     stars[Nstars].D = D;
+    stars[Nstars].flag  = FALSE;
+    stars[Nstars].found = FALSE;
 
     stars[Nstars].starpar.galLon = glon[i];
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_save_remote.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_save_remote.c	(revision 37421)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_save_remote.c	(revision 37422)
@@ -24,5 +24,5 @@
 
   // if this region is a parallel thing, save and launch remote
-  if (!region->hostID) { 
+  if (!PARALLEL) { 
     loadstarpar_catalog (stars, Nstars, region, fullname, options);
   } else {
@@ -61,10 +61,4 @@
     // got a valid slot, so launch a new host
 
-    // XXX do this after we load the host table:
-    // ensure that the paths are absolute path names
-    // char *tmppath = abspath (table->hosts[i].pathname, DVO_MAX_PATH);
-    // free (table->hosts[i].pathname);
-    // table->hosts[i].pathname = tmppath;
-
     // need to generate the remote command
     char command[1024];
