Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/Makefile
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/Makefile	(revision 37416)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/Makefile	(revision 37417)
@@ -25,4 +25,5 @@
 load2mass    : $(BIN)/load2mass.$(ARCH)
 loadstarpar  : $(BIN)/loadstarpar.$(ARCH)
+loadstarpar_client : $(BIN)/loadstarpar_client.$(ARCH)
 loadwise     : $(BIN)/loadwise.$(ARCH)
 dumpskycells : $(BIN)/dumpskycells.$(ARCH)
@@ -32,7 +33,7 @@
 mkcmf        : $(BIN)/mkcmf.$(ARCH)
 
-all: addstar addstar_client sedstar load2mass loadstarpar skycells mkcmf loadwise loadsupercos dumpskycells findskycell
-
-INSTALL = addstar addstar_client sedstar load2mass loadstarpar skycells mkcmf loadwise loadsupercos dumpskycells findskycell
+all: addstar addstar_client sedstar load2mass loadstarpar loadstarpar_client skycells mkcmf loadwise loadsupercos dumpskycells findskycell
+
+INSTALL = addstar addstar_client sedstar load2mass loadstarpar loadstarpar_client skycells mkcmf loadwise loadsupercos dumpskycells findskycell
 
 # I need to fix the client/server version of addstar now that I have dropped Stars
@@ -244,20 +245,36 @@
 LOAD-STARPAR = \
 $(SRC)/loadstarpar.$(ARCH).o \
-$(SRC)/loadstarpar_rawdata.$(ARCH).o \
+$(SRC)/ConfigInit.$(ARCH).o \
+$(SRC)/SetSignals.$(ARCH).o \
+$(SRC)/Shutdown.$(ARCH).o \
+$(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 \
+$(SRC)/loadstarpar_io.$(ARCH).o \
+$(SRC)/loadstarpar_make_subset.$(ARCH).o \
 $(SRC)/loadstarpar_readstars.$(ARCH).o \
+$(SRC)/loadstarpar_remote_hosts.$(ARCH).o \
+$(SRC)/loadstarpar_save_remote.$(ARCH).o \
+$(SRC)/loadstarpar_table.$(ARCH).o \
+$(SRC)/psps_ids.$(ARCH).o
+
+LOAD-STARPAR-CLIENT = \
+$(SRC)/loadstarpar_client.$(ARCH).o \
+$(SRC)/ConfigInit.$(ARCH).o \
+$(SRC)/SetSignals.$(ARCH).o \
+$(SRC)/Shutdown.$(ARCH).o \
+$(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 \
+$(SRC)/loadstarpar_io.$(ARCH).o \
 $(SRC)/loadstarpar_make_subset.$(ARCH).o \
+$(SRC)/loadstarpar_readstars.$(ARCH).o \
+$(SRC)/loadstarpar_remote_hosts.$(ARCH).o \
 $(SRC)/loadstarpar_save_remote.$(ARCH).o \
-$(SRC)/loadstarpar_io.$(ARCH).o \
-$(SRC)/loadstarpar_remote_hosts.$(ARCH).o \
-$(SRC)/find_matches_refstars.$(ARCH).o \
-$(SRC)/args_loadstarpar.$(ARCH).o \
-$(SRC)/replace_match.$(ARCH).o \
-$(SRC)/update_coords.$(ARCH).o \
-$(SRC)/SkyRegionUtils.$(ARCH).o \
-$(SRC)/StarOps.$(ARCH).o \
-$(SRC)/ConfigInit.$(ARCH).o \
-$(SRC)/Shutdown.$(ARCH).o \
-$(SRC)/SetSignals.$(ARCH).o \
+$(SRC)/loadstarpar_table.$(ARCH).o \
 $(SRC)/psps_ids.$(ARCH).o
 
@@ -330,15 +347,17 @@
 $(SRC)/Shutdown.$(ARCH).o 
 
-$(ADDSTARC)   	  : $(INC)/addstar.h
-$(ADDSTARD)   	  : $(INC)/addstar.h
-$(ADDSTART)   	  : $(INC)/addstar.h
-$(ADDSTAR)    	  : $(INC)/addstar.h
-$(ADDSTAR_CLIENT) : $(INC)/addstar.h
-$(SKYCELLS)    	  : $(INC)/addstar.h
-$(DUMPSKYCELLS)	  : $(INC)/addstar.h
-$(FINDSKYCELL)	  : $(INC)/addstar.h
-$(LOAD-2MASS)  	  : $(INC)/addstar.h $(INC)/2mass.h
-$(LOAD-WISE)   	  : $(INC)/addstar.h $(INC)/WISE.h
-$(MKCMF)       	  : $(INC)/mkcmf.h
+$(ADDSTARC)   	       : $(INC)/addstar.h
+$(ADDSTARD)   	       : $(INC)/addstar.h
+$(ADDSTART)   	       : $(INC)/addstar.h
+$(ADDSTAR)    	       : $(INC)/addstar.h
+$(ADDSTAR_CLIENT)      : $(INC)/addstar.h
+$(SKYCELLS)    	       : $(INC)/addstar.h
+$(DUMPSKYCELLS)	       : $(INC)/addstar.h
+$(FINDSKYCELL)	       : $(INC)/addstar.h
+$(LOAD-2MASS)  	       : $(INC)/addstar.h $(INC)/2mass.h
+$(LOAD-STARPAR)	       : $(INC)/addstar.h $(INC)/loadstarpar.h
+$(LOAD-STARPAR-CLIENT) : $(INC)/addstar.h $(INC)/loadstarpar.h
+$(LOAD-WISE)   	       : $(INC)/addstar.h $(INC)/WISE.h
+$(MKCMF)       	       : $(INC)/mkcmf.h
 
 $(BIN)/addstar.$(ARCH) 	      : $(ADDSTAR)
@@ -351,4 +370,6 @@
 $(BIN)/load2mass.$(ARCH)      : $(LOAD-2MASS)
 $(BIN)/loadwise.$(ARCH)       : $(LOAD-WISE)
+$(BIN)/loadstarpar.$(ARCH)    : $(LOAD-STARPAR)
+$(BIN)/loadstarpar_client.$(ARCH) : $(LOAD-STARPAR-CLIENT)
 $(BIN)/loadsupercos.$(ARCH)   : $(LOAD-SUPERCOS)
 $(BIN)/skycells.$(ARCH)       : $(SKYCELLS)
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/include/addstar.h
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/include/addstar.h	(revision 37416)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/include/addstar.h	(revision 37417)
@@ -31,4 +31,6 @@
 # define dCOS(A)   ((double) cos ((double)RAD_DEG*A))
 # define dSIN(A)   ((double) sin ((double)RAD_DEG*A))
+
+# define myAbortF(FORMAT,...) { fprintf (stderr, FORMAT, __VA_ARGS__); abort(); }
 
 typedef struct {
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/include/loadstarpar.h
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/include/loadstarpar.h	(revision 37416)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/include/loadstarpar.h	(revision 37417)
@@ -7,6 +7,35 @@
 } StarPar_Stars;
 
-int   HOST_ID
+int   HOST_ID;
 char *HOSTDIR;
 char *CPT_FILE;
 char *INPUT;
+
+AddstarClientOptions args_loadstarpar (int argc, char **argv, AddstarClientOptions options);
+AddstarClientOptions args_loadstarpar_client (int argc, char **argv, AddstarClientOptions options);
+
+int loadstarpar_table (SkyList *skylistInput, HostTable *hosts, char *filename, AddstarClientOptions *options);
+
+StarPar_Stars *loadstarpar_make_subset (StarPar_Stars *stars, int Nstars, int start, SkyRegion *region, int *nsubset);
+
+int loadstarpar_save_remote (StarPar_Stars *stars, int Nstars, HostTable *hosts, SkyRegion *region, char *fullname, AddstarClientOptions *options);
+
+int save_remote_host (HostInfo *host);
+
+int init_remote_hosts ();
+int find_empty_slot ();
+int harvest_all ();
+int harvest_host ();
+
+int loadstarpar_catalog (StarPar_Stars *stars, int Nstars, SkyRegion *region, char *filename, AddstarClientOptions *options);
+
+int galactic_to_celestial (double *R, double *D, double l, double b);
+
+int find_matches_starpar (SkyRegion *region, StarPar_Stars *stars, int Nstars, Catalog *catalog, AddstarClientOptions *options);
+
+int loadstarpar_save_stars (char *filename, StarPar_Stars *stars, int Nstars);
+StarPar_Stars *loadstarpar_load_stars (char *filename, int *nstars);
+
+StarPar_Stars *loadstarpar_readstars (char *filename, int *nstars);
+
+int loadstarpar_sortStars (StarPar_Stars *stars, int Nstars);
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 37416)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/args_loadstarpar.c	(revision 37417)
@@ -1,6 +1,7 @@
 # include "addstar.h"
-# include "WISE.h"
+# include "loadstarpar.h"
 
 static void help (void);
+static void help_client (void);
 
 AddstarClientOptions args_loadstarpar (int argc, char **argv, AddstarClientOptions options) {
@@ -13,9 +14,4 @@
     help ();
   }
-
-  // a global used by find_matches_refstars.c
-  NREFSTAR_GROUP = X;
-
-  /*** check for command line options ***/
 
   /* basic mode: image, list, refcat */
@@ -51,11 +47,4 @@
   if ((N = get_argument (argc, argv, "-v"))) {
     VERBOSE = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-
-  /* load the prelim data dump */
-  ALLSKY = TRUE;
-  if ((N = get_argument (argc, argv, "-prelim"))) {
-    ALLSKY = FALSE;
     remove_argument (N, &argc, argv);
   }
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/build_links.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/build_links.c	(revision 37416)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/build_links.c	(revision 37417)
@@ -1,5 +1,3 @@
 # include "addstar.h"
-
-# define myAbortF(FORMAT,...) { fprintf (stderr, FORMAT, __VA_ARGS__); abort(); }
 
 /* 
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 37417)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/coord_transforms.c	(revision 37417)
@@ -0,0 +1,8 @@
+# include "addstar.h"
+# include "loadstarpar.h"
+
+int galactic_to_celestial (double *R, double *D, double l, double b) {
+
+  fprintf (stderr, "define me...");
+  abort();
+}
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 37416)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches_starpar.c	(revision 37417)
@@ -3,7 +3,7 @@
 
 // we find matching stars by (R,D).  we add the starpar to the array of starpars with appropriate links.  
-int find_matches_starpar (SkyRegion *region, StarPar_Stars *stars, int Nstars, Catalog *catalog, AddstarClientOptions options) {
+int find_matches_starpar (SkyRegion *region, StarPar_Stars *stars, int Nstars, Catalog *catalog, AddstarClientOptions *options) {
   
-  off_t i, j, n, N, J, Jmin, status, Nstars;
+  off_t i, j, n, N, J, Jmin;
   double RADIUS, RADIUS2, Rmin;
   double *X1, *Y1, *X2, *Y2;
@@ -48,5 +48,5 @@
   /* build spatial index (RA sort) referencing input array sequence */
   for (i = 0; i < Nstars; i++) {
-    status = RD_to_XY (&X1[i], &Y1[i], stars[i].R, stars[i].D, &tcoords);
+    RD_to_XY (&X1[i], &Y1[i], stars[i].R, stars[i].D, &tcoords);
     N1[i] = i;
   }
@@ -62,5 +62,5 @@
 
   /* choose a radius for matches */
-  RADIUS = options.radius; /* provided by config */
+  RADIUS = options->radius; /* provided by config */
   RADIUS2 = RADIUS*RADIUS;
 
@@ -153,5 +153,5 @@
 # if (0)
   /** incorporate unmatched image stars? **/
-  for (i = 0; (i < Nstars) && !options.only_match; i++) {
+  for (i = 0; (i < Nstars) && !options->only_match; i++) {
 
     // skip already matched stars
@@ -206,5 +206,5 @@
 
   /* note stars which have been found in this catalog */
-  for (i = 0; i < NstarsIn; i++) {
+  for (i = 0; i < Nstars; i++) {
     if (stars[i].found > -1) {
       stars[i].found = -2;
@@ -217,5 +217,5 @@
   catalog[0].Nstarpar  = Nstarpar;
   catalog[0].Nsecf_mem = Nave*Nsecfilt;
-  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nstarpar, Nlens: "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT", ("OFF_T_FMT" matches)\n",  Nstars,  Nave, Nmatch);
+  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nstarpar: %d "OFF_T_FMT" "OFF_T_FMT" ("OFF_T_FMT" matches)\n",  Nstars, Nave, Nstarpar, Nmatch);
 
   free (X1);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar.c	(revision 37416)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar.c	(revision 37417)
@@ -1,4 +1,4 @@
 # include "addstar.h"
-# include "WISE.h"
+# include "loadstarpar.h"
 
 /* This is the DVO program to upload Greg Green's stellar parametersq into a DVO database.
@@ -9,5 +9,5 @@
 
    USAGE: loadstarpar -D CATDIR (catdir) (file.fits) [...more files]
- */
+*/
 
 int main (int argc, char **argv) {
@@ -35,8 +35,7 @@
 
   for (i = 1; i < argc; i++) {
-      fprintf (stderr, "loading %s\n", argv[i]);
-      loadstarpar_rawdata (skylist, hosts, argv[i], options);
+    fprintf (stderr, "loading %s\n", argv[i]);
+    loadstarpar_table (skylist, hosts, argv[i], &options);
   }
   exit (0);
 }  
-
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_catalog.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_catalog.c	(revision 37416)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_catalog.c	(revision 37417)
@@ -2,5 +2,5 @@
 # include "loadstarpar.h"
 
-int loadstarpar_catalog (StarPar_Stars *stars, int Nstars, SkyRegion *region, char *filename) {
+int loadstarpar_catalog (StarPar_Stars *stars, int Nstars, SkyRegion *region, char *filename, AddstarClientOptions *options) {
 
   Catalog catalog;
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_client.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_client.c	(revision 37416)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_client.c	(revision 37417)
@@ -4,5 +4,4 @@
 int main (int argc, char **argv) {
 
-  int i;
   AddstarClientOptions options;
 
@@ -13,7 +12,13 @@
   // client is called with a pointer to the file to be loaded
 
+  SkyTable *sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, FALSE, SKY_DEPTH, VERBOSE);
+  SkyTableSetFilenames (sky, CATDIR, "cpt");
+  
+  SkyList *skylist = SkyRegionByCPT (sky, CPT_FILE);
+
+  int Nstars;
   StarPar_Stars *stars = loadstarpar_load_stars (INPUT, &Nstars);
 
-  loadstarpar_catalog (stars, Nstars, region, CPT_FILE);
+  loadstarpar_catalog (stars, Nstars, skylist->regions[0], CPT_FILE, &options);
 
   free (stars);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_io.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_io.c	(revision 37416)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_io.c	(revision 37417)
@@ -30,16 +30,17 @@
   gfits_define_bintable_column (&theader, "D", "GLON",     "", "degree", 1.0, 0.0);
   gfits_define_bintable_column (&theader, "D", "GLAT",     "", "degree", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "Ebv",      "", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "dEbv",     "", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "DistMag",  "", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "dDistMag", "", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "M_r",      "", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "dM_r",     "", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "FeH",      "", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "dFeH",     "", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "J", "averef",   "", 1.0, FT_BZERO_INT32);
-  gfits_define_bintable_column (&theader, "J", "objID",    "", 1.0, FT_BZERO_INT32);
-  gfits_define_bintable_column (&theader, "J", "catID",    "", 1.0, FT_BZERO_INT32);
+  gfits_define_bintable_column (&theader, "E", "Ebv",      "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "dEbv",     "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "DistMag",  "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "dDistMag", "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "M_r",      "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "dM_r",     "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "FeH",      "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "dFeH",     "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "J", "averef",   "", "", 1.0, FT_BZERO_INT32);
+  gfits_define_bintable_column (&theader, "J", "objID",    "", "", 1.0, FT_BZERO_INT32);
+  gfits_define_bintable_column (&theader, "J", "catID",    "", "", 1.0, FT_BZERO_INT32);
 
+  int i;
   double       *ra       = NULL; ALLOCATE (ra      , double	 , Nstars); for (i = 0; i < Nstars; i++) ra      [i] = stars[i].R               ;
   double       *dec      = NULL; ALLOCATE (dec     , double	 , Nstars); for (i = 0; i < Nstars; i++) dec     [i] = stars[i].D               ;
@@ -82,4 +83,6 @@
   gfits_free_header (&theader);
   gfits_free_table (&ftable);
+
+  return TRUE;
 }
 
@@ -131,19 +134,19 @@
   if (!gfits_fread_ftable_data (f, &ftable, FALSE)) goto escape;
  
-  GET_COLUMN_NEW(ra      , "RA"        ,   double);
-  GET_COLUMN_NEW(dec     , "DEC"       ,   double);
-  GET_COLUMN_NEW(glon    , "GLON"      ,   double);
-  GET_COLUMN_NEW(glat    , "GLAT"      ,   double);
-  GET_COLUMN_NEW(Ebv     , "Ebv"       ,   float);
-  GET_COLUMN_NEW(dEbv    , "dEbv"      ,   float);
-  GET_COLUMN_NEW(DistMag , "DistMag"   ,   float);
-  GET_COLUMN_NEW(dDistMag, "dDistMag"  ,   float);
-  GET_COLUMN_NEW(M_r     , "M_r"       ,   float);
-  GET_COLUMN_NEW(dM_r    , "dM_r"      ,   float);
-  GET_COLUMN_NEW(FeH     , "FeH"       ,   float);
-  GET_COLUMN_NEW(dFeH    , "dFeH"      ,   float);
-  GET_COLUMN_NEW(averef  , "averef"    ,   unsigned int);
-  GET_COLUMN_NEW(objID   , "objID"     ,   unsigned int);
-  GET_COLUMN_NEW(catID   , "catID"     ,   unsigned int);
+  GET_COLUMN(ra      , "RA"        ,   double);
+  GET_COLUMN(dec     , "DEC"       ,   double);
+  GET_COLUMN(glon    , "GLON"      ,   double);
+  GET_COLUMN(glat    , "GLAT"      ,   double);
+  GET_COLUMN(Ebv     , "Ebv"       ,   float);
+  GET_COLUMN(dEbv    , "dEbv"      ,   float);
+  GET_COLUMN(DistMag , "DistMag"   ,   float);
+  GET_COLUMN(dDistMag, "dDistMag"  ,   float);
+  GET_COLUMN(M_r     , "M_r"       ,   float);
+  GET_COLUMN(dM_r    , "dM_r"      ,   float);
+  GET_COLUMN(FeH     , "FeH"       ,   float);
+  GET_COLUMN(dFeH    , "dFeH"      ,   float);
+  GET_COLUMN(averef  , "averef"    ,   unsigned int);
+  GET_COLUMN(objID   , "objID"     ,   unsigned int);
+  GET_COLUMN(catID   , "catID"     ,   unsigned int);
 
   gfits_free_header (&theader);
@@ -152,5 +155,5 @@
   gfits_free_matrix (&matrix);
 
-  ALLOCATE (StarPar_Stars, stars, Nrow);
+  ALLOCATE (stars, StarPar_Stars, Nrow);
 
   for (i = 0; i < Nrow; i++) {
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 37416)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_make_subset.c	(revision 37417)
@@ -7,4 +7,6 @@
 StarPar_Stars *loadstarpar_make_subset (StarPar_Stars *stars, int Nstars, int start, SkyRegion *region, int *nsubset) {
 
+  int i;
+
   StarPar_Stars *subset = NULL;
 
@@ -12,5 +14,5 @@
   int Nsubset = 0;
   int NSUBSET = 3000;
-  ALLOCATE (subset, StarPar_Stars *, NSUBSET);
+  ALLOCATE (subset, StarPar_Stars, NSUBSET);
 
   // find the rest of the stars in this output region
@@ -31,5 +33,5 @@
 	  
     subset[Nsubset] = stars[i];
-    Nsubset ++
+    Nsubset ++;
 
     CHECK_REALLOCATE (subset, StarPar_Stars, NSUBSET, Nsubset, 10000);
Index: anches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_rawdata.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_rawdata.c	(revision 37416)
+++ 	(revision )
@@ -1,49 +1,0 @@
-# include "addstar.h"
-# include "loadstarpar.h"
-
-# define GET_COLUMN(OUT,NAME,TYPE) \
-  TYPE *OUT = gfits_get_bintable_column_data (&theader, &ftable, NAME, type, &Nrow, &Ncol); \
-  myAssert (!strcmp(type, #TYPE), "wrong column type");
-
-int loadstarpar_foobar (SkyList *skylistInput, HostTable *hosts, char *filename, AddstarClientOptions options) {
-  
-  SkyRegion *region;
-
-  StarPar_Stars *stars = loadstarpar_readstars (filename, &Nstars);
-
-  // sort the stars by RA
-  loadstarpar_sortStars (stars, Nstars);
-
-  // scan through the stars, loading the containing catalogs
-  // skip through table for unsaved stars
-  for (i = 0; i < Nstars; i++) {
-    if (stars[i].flag) continue;
-
-    // scan forward until we read the UserPatch
-    if (stars[i].R < UserPatch.Rmin) continue;
-    if (stars[i].R > UserPatch.Rmax) break;
-    if (stars[i].D < UserPatch.Dmin) continue;
-    if (stars[i].D > UserPatch.Dmax) continue;
-
-    // identify the relevant catalog
-    skylist = SkyRegionByPoint_List (skylistInput, -1, stars[i].R, stars[i].D);
-    if (skylist[0].Nregions == 0) {
-      SkyListFree (skylist);
-      continue;
-    }
-    region = skylist[0].regions[0];
-
-    // select stars matching this region
-    StarPar_Stars *subset = loadstarpar_make_subset (stars, Nstars, i, region, &Nsubset);
-
-    // In parallel mode, write out the subset to a disk file.  Block until a remote host
-    // is available.  In serial mode, just match against the appropriate region and save
-    loadstarpar_save_remote (subset, Nsubset, hosts, region, skylist[0].filename[0]);
-  }
-
-  // wait for last remote clients to finish
-  harvest_all ();
-
-  return TRUE;
-}
-
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 37416)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_readstars.c	(revision 37417)
@@ -9,6 +9,9 @@
 
   // read in the full FITS files ('cause I don't have a partial read option)
-  f = fopen (filename, "r");
+  FILE *f = fopen (filename, "r");
   if (f == NULL) Shutdown ("can't read stellar parameter file: %s", filename);
+
+  int i, Ncol;
+  off_t Nrow;
 
   Header header;
@@ -79,8 +82,8 @@
   int NstarsIn = matrix.Naxis[2];
 
-  Rmin = 360.0;
-  Rmax = 360.0;
-  Dmin = 360.0;
-  Dmax = 360.0;
+  double Rmin = +360.0;
+  double Rmax = -360.0;
+  double Dmin = +360.0;
+  double Dmax = -360.0;
 
   int Nstars = 0;
@@ -96,5 +99,6 @@
     if (lnZ[i] < -15.0) continue;
 
-    galactic_to_celestial (&R, &D, glat[i], glon[i]);
+    double R, D;
+    galactic_to_celestial (&R, &D, glon[i], glat[i]);
 
     Rmin = MIN (Rmin, R);
@@ -106,11 +110,11 @@
     float dDistMag = 0.5*(errImage[i*20 + 5*1 + 3] - errImage[i*20 + 5*1 + 1]);
     float dFeH     = 0.5*(errImage[i*20 + 5*2 + 3] - errImage[i*20 + 5*2 + 1]);
-    float dMr      = 0.5*(errImage[i*20 + 5*3 + 3] - errImage[i*20 + 5*3 + 1]);
+    float dM_r     = 0.5*(errImage[i*20 + 5*3 + 3] - errImage[i*20 + 5*3 + 1]);
 
     stars[Nstars].R = R;
     stars[Nstars].D = D;
 
-    stars[Nstars].starpar.galLon = l;
-    stars[Nstars].starpar.galLat = b;
+    stars[Nstars].starpar.galLon = glon[i];
+    stars[Nstars].starpar.galLat = glat[i];
 
     stars[Nstars].starpar.Ebv      = Ebv[i]    ;
@@ -133,2 +137,16 @@
   return (stars);
 }
+
+int loadstarpar_sortStars (StarPar_Stars *stars, int Nstars) {
+
+# define SWAPFUNC(A,B){ StarPar_Stars temp = stars[A]; stars[A] = stars[B]; stars[B] = temp; }
+# define COMPARE(A,B)(stars[A].R < stars[B].R)
+
+  OHANA_SORT (Nstars, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+  
+  return TRUE;
+}
+
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_remote_hosts.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_remote_hosts.c	(revision 37416)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_remote_hosts.c	(revision 37417)
@@ -1,4 +1,8 @@
 # include "addstar.h"
 # include "loadstarpar.h"
+# include <sys/types.h>
+# include <sys/wait.h>
+
+# define DEBUG 1
 
 // we are running N parallel remote jobs on the remote hosts.  In the usual remote
@@ -19,8 +23,10 @@
     hosts[i] = NULL;
   }
+  return TRUE;
 }
 
 int find_empty_slot () {
 
+  int i;
   for (i = 0; i < Nhosts; i++) {
     if (hosts[i] == NULL) return i;
@@ -31,5 +37,5 @@
 int harvest_all () {
 
-  slot = -1;
+  int slot = -1;
 
   while (slot != -2) {
@@ -44,4 +50,5 @@
 int save_remote_host (HostInfo *host) {
 
+  int i;
   for (i = 0; i < Nhosts; i++) {
     if (hosts[i] == NULL) {
@@ -124,6 +131,6 @@
   free (host->hostname);
   free (host->pathname);
-  FreeIOBuffer (host->stdout);
-  FreeIOBuffer (host->stderr);
+  FreeIOBuffer (&host->stdout);
+  FreeIOBuffer (&host->stderr);
   free (host);
 
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 37416)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_save_remote.c	(revision 37417)
@@ -1,6 +1,20 @@
 # include "addstar.h"
 # include "loadstarpar.h"
+# define DEBUG 1
 
-int loadstarpar_save_remote (StarPar_Stars *stars, int Nstars, HostTable *hosts, SkyRegion *region, char *fullname) {
+int strextend (char *input, char *format,...) {
+
+  char tmpextra[1024], tmpline[1024];
+  va_list argp;
+
+  va_start (argp, format);
+  vsnprintf (tmpextra, 1024, format, argp);
+  snprintf (tmpline, 1024, "%s %s", input, tmpextra);
+  strcpy (input, tmpline);
+
+  return TRUE;
+}
+
+int loadstarpar_save_remote (StarPar_Stars *stars, int Nstars, HostTable *hosts, SkyRegion *region, char *fullname, AddstarClientOptions *options) {
 
   char uniquer[12];
@@ -11,8 +25,8 @@
   // if this region is a parallel thing, save and launch remote
   if (!region->hostID) { 
-    loadstarpar_catalog (stars, Nstars, region, fullname);
+    loadstarpar_catalog (stars, Nstars, region, fullname, options);
   } else {
     int N = hosts->index[region->hostID];
-    HostInfo *hostMach = hosts->hosts[N];
+    HostInfo *hostMach = &hosts->hosts[N];
 
     // save to a unique filename
@@ -35,5 +49,5 @@
     // allocate a host for this job
     HostInfo *host = NULL;
-    ALLOCATE (HostInfo, host, 1);
+    ALLOCATE (host, HostInfo, 1);
 
     // we want to run this job on the host described by hostMach.  copy
@@ -42,6 +56,6 @@
     host->hostname = strcreate (hostMach->hostname);
     host->pathname = strcreate (hostMach->pathname);
-    InitIOBuffer (host->stdout, 1000);
-    InitIOBuffer (host->stderr, 1000);
+    InitIOBuffer (&host->stdout, 1000);
+    InitIOBuffer (&host->stderr, 1000);
 
     // got a valid slot, so launch a new host
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_table.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_table.c	(revision 37417)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadstarpar_table.c	(revision 37417)
@@ -0,0 +1,50 @@
+# include "addstar.h"
+# include "loadstarpar.h"
+
+# define GET_COLUMN(OUT,NAME,TYPE) \
+  TYPE *OUT = gfits_get_bintable_column_data (&theader, &ftable, NAME, type, &Nrow, &Ncol); \
+  myAssert (!strcmp(type, #TYPE), "wrong column type");
+
+int loadstarpar_table (SkyList *skylistInput, HostTable *hosts, char *filename, AddstarClientOptions *options) {
+  
+  int i, Nstars;
+
+  StarPar_Stars *stars = loadstarpar_readstars (filename, &Nstars);
+
+  // sort the stars by RA
+  loadstarpar_sortStars (stars, Nstars);
+
+  // scan through the stars, loading the containing catalogs
+  // skip through table for unsaved stars
+  for (i = 0; i < Nstars; i++) {
+    if (stars[i].flag) continue;
+
+    // scan forward until we read the UserPatch
+    if (stars[i].R < UserPatch.Rmin) continue;
+    if (stars[i].R > UserPatch.Rmax) break;
+    if (stars[i].D < UserPatch.Dmin) continue;
+    if (stars[i].D > UserPatch.Dmax) continue;
+
+    // identify the relevant catalog
+    SkyList *skylist = SkyRegionByPoint_List (skylistInput, -1, stars[i].R, stars[i].D);
+    if (skylist[0].Nregions == 0) {
+      SkyListFree (skylist);
+      continue;
+    }
+    SkyRegion *region = skylist[0].regions[0];
+
+    // select stars matching this region
+    int Nsubset;
+    StarPar_Stars *subset = loadstarpar_make_subset (stars, Nstars, i, region, &Nsubset);
+
+    // In parallel mode, write out the subset to a disk file.  Block until a remote host
+    // is available.  In serial mode, just match against the appropriate region and save
+    loadstarpar_save_remote (subset, Nsubset, hosts, region, skylist[0].filename[0], options);
+  }
+
+  // wait for last remote clients to finish
+  harvest_all ();
+
+  return TRUE;
+}
+
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/resort_catalog.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/resort_catalog.c	(revision 37416)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/resort_catalog.c	(revision 37417)
@@ -4,4 +4,5 @@
 void resort_catalog_measure (Catalog *catalog);
 void resort_catalog_lensing (Catalog *catalog);
+void resort_catalog_starpar (Catalog *catalog);
 
 void resort_catalog_old (Catalog *catalog) {
@@ -339,5 +340,5 @@
 
   off_t Naverage, Nstarpar;
-  Starpar *starpar;
+  StarPar *starpar;
   Average *average;
   off_t i, j, N, currentAve;
@@ -345,5 +346,5 @@
   off_t *starparSeq = NULL;
   off_t *averageSeq = NULL;
-  Starpar *starparTMP = NULL;
+  StarPar *starparTMP = NULL;
 
   // struct timeval start, stop;
@@ -410,5 +411,5 @@
 
   // copy the starpar entries in the sorted order
-  ALLOCATE (starparTMP, Starpar, Nstarpar);
+  ALLOCATE (starparTMP, StarPar, Nstarpar);
   for (i = 0; i < Nstarpar; i++) {
     j = starparSeq[i];
