Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/Makefile
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/Makefile	(revision 37569)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/Makefile	(revision 37570)
@@ -26,4 +26,6 @@
 loadstarpar  : $(BIN)/loadstarpar.$(ARCH)
 loadstarpar_client : $(BIN)/loadstarpar_client.$(ARCH)
+loadICRF  : $(BIN)/loadICRF.$(ARCH)
+loadICRF_client : $(BIN)/loadICRF_client.$(ARCH)
 loadwise     : $(BIN)/loadwise.$(ARCH)
 dumpskycells : $(BIN)/dumpskycells.$(ARCH)
@@ -33,7 +35,7 @@
 mkcmf        : $(BIN)/mkcmf.$(ARCH)
 
-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
+all: addstar addstar_client sedstar load2mass loadstarpar loadstarpar_client loadICRF loadICRF_client skycells mkcmf loadwise loadsupercos dumpskycells findskycell
+
+INSTALL = addstar addstar_client sedstar load2mass loadstarpar loadstarpar_client loadICRF loadICRF_client skycells mkcmf loadwise loadsupercos dumpskycells findskycell
 
 # I need to fix the client/server version of addstar now that I have dropped Stars
@@ -277,4 +279,38 @@
 $(SRC)/psps_ids.$(ARCH).o
 
+LOAD-ICRF = \
+$(SRC)/loadICRF.$(ARCH).o \
+$(SRC)/ConfigInit.$(ARCH).o \
+$(SRC)/SetSignals.$(ARCH).o \
+$(SRC)/Shutdown.$(ARCH).o \
+$(SRC)/SkyRegionUtils.$(ARCH).o \
+$(SRC)/args_loadICRF.$(ARCH).o \
+$(SRC)/find_matches_ICRF.$(ARCH).o \
+$(SRC)/loadICRF_catalog.$(ARCH).o \
+$(SRC)/loadICRF_io.$(ARCH).o \
+$(SRC)/loadICRF_make_subset.$(ARCH).o \
+$(SRC)/loadICRF_readstars.$(ARCH).o \
+$(SRC)/loadICRF_remote_hosts.$(ARCH).o \
+$(SRC)/loadICRF_save_remote.$(ARCH).o \
+$(SRC)/loadICRF_table.$(ARCH).o \
+$(SRC)/psps_ids.$(ARCH).o
+
+LOAD-ICRF-CLIENT = \
+$(SRC)/loadICRF_client.$(ARCH).o \
+$(SRC)/ConfigInit.$(ARCH).o \
+$(SRC)/SetSignals.$(ARCH).o \
+$(SRC)/Shutdown.$(ARCH).o \
+$(SRC)/SkyRegionUtils.$(ARCH).o \
+$(SRC)/args_loadICRF.$(ARCH).o \
+$(SRC)/find_matches_ICRF.$(ARCH).o \
+$(SRC)/loadICRF_catalog.$(ARCH).o \
+$(SRC)/loadICRF_io.$(ARCH).o \
+$(SRC)/loadICRF_make_subset.$(ARCH).o \
+$(SRC)/loadICRF_readstars.$(ARCH).o \
+$(SRC)/loadICRF_remote_hosts.$(ARCH).o \
+$(SRC)/loadICRF_save_remote.$(ARCH).o \
+$(SRC)/loadICRF_table.$(ARCH).o \
+$(SRC)/psps_ids.$(ARCH).o
+
 LOAD-WISE = \
 $(SRC)/loadwise.$(ARCH).o \
@@ -356,4 +392,6 @@
 $(LOAD-STARPAR)	       : $(INC)/addstar.h $(INC)/loadstarpar.h
 $(LOAD-STARPAR-CLIENT) : $(INC)/addstar.h $(INC)/loadstarpar.h
+$(LOAD-ICRF)	       : $(INC)/addstar.h $(INC)/loadICRF.h
+$(LOAD-ICRF-CLIENT)    : $(INC)/addstar.h $(INC)/loadICRF.h
 $(LOAD-WISE)   	       : $(INC)/addstar.h $(INC)/WISE.h
 $(MKCMF)       	       : $(INC)/mkcmf.h
@@ -370,4 +408,6 @@
 $(BIN)/loadstarpar.$(ARCH)    : $(LOAD-STARPAR)
 $(BIN)/loadstarpar_client.$(ARCH) : $(LOAD-STARPAR-CLIENT)
+$(BIN)/loadICRF.$(ARCH)       : $(LOAD-ICRF)
+$(BIN)/loadICRF_client.$(ARCH): $(LOAD-ICRF-CLIENT)
 $(BIN)/loadsupercos.$(ARCH)   : $(LOAD-SUPERCOS)
 $(BIN)/skycells.$(ARCH)       : $(SKYCELLS)
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/include/loadICRF.h
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/include/loadICRF.h	(revision 37570)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/include/loadICRF.h	(revision 37570)
@@ -0,0 +1,42 @@
+
+typedef struct {
+  double R, D;
+  Measure measure;
+  int found; // TRUE == matched to an input star
+  int flag; // TRUE == included in a subset
+} ICRF_Stars;
+
+int   HOST_ID;
+char *HOSTDIR;
+char *CPT_FILE;
+char *INPUT;
+
+AddstarClientOptions args_loadICRF (int argc, char **argv, AddstarClientOptions options);
+AddstarClientOptions args_loadICRF_client (int argc, char **argv, AddstarClientOptions options);
+
+int loadICRF_table (SkyList *skylistInput, HostTable *hosts, char *filename, AddstarClientOptions *options);
+
+ICRF_Stars *loadICRF_make_subset (ICRF_Stars *stars, int Nstars, int start, SkyRegion *region, int *nsubset);
+
+int loadICRF_save_remote (ICRF_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 loadICRF_catalog (ICRF_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_ICRF (SkyRegion *region, ICRF_Stars *stars, int Nstars, Catalog *catalog, AddstarClientOptions *options);
+
+int loadICRF_save_stars (char *filename, ICRF_Stars *stars, int Nstars);
+ICRF_Stars *loadICRF_load_stars (char *filename, int *nstars);
+
+ICRF_Stars *loadICRF_readstars (char *filename, int *nstars);
+
+int loadICRF_sortStars (ICRF_Stars *stars, int Nstars);
+int InitICRF_Star (ICRF_Stars *star);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/args_loadICRF.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/args_loadICRF.c	(revision 37569)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/args_loadICRF.c	(revision 37570)
@@ -1,9 +1,9 @@
 # include "addstar.h"
-# include "loadstarpar.h"
+# include "loadICRF.h"
 
 static void help (void);
 static void help_client (void);
 
-AddstarClientOptions args_loadstarpar (int argc, char **argv, AddstarClientOptions options) {
+AddstarClientOptions args_loadICRF (int argc, char **argv, AddstarClientOptions options) {
   
   int N;
@@ -59,10 +59,4 @@
     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);
-  }
   /* replace measurement, don't duplicate (ref/cat only) */
   options.replace = FALSE;
@@ -79,5 +73,5 @@
   }
 
-  /* other addstar options which cannot be used in loadstarpar */
+  /* other addstar options which cannot be used in loadICRF */
   options.photcode = 0;
   options.timeref = 0; 
@@ -97,5 +91,5 @@
 
   if (argc < 2) {
-    fprintf (stderr, "USAGE: loadstarpar [options] (fitsfile) [..more files]\n");
+    fprintf (stderr, "USAGE: loadICRF [options] (file) [..more files]\n");
     exit (2);
   }
@@ -103,5 +97,5 @@
 }
 
-AddstarClientOptions args_loadstarpar_client (int argc, char **argv, AddstarClientOptions options) {
+AddstarClientOptions args_loadICRF_client (int argc, char **argv, AddstarClientOptions options) {
   
   int N;
@@ -175,5 +169,5 @@
   }
 
-  /* other addstar options which cannot be used in loadstarpar */
+  /* other addstar options which cannot be used in loadICRF */
   options.photcode = 0;
   options.timeref = 0; 
@@ -193,5 +187,5 @@
 
   if (argc != 1) {
-    fprintf (stderr, "USAGE: loadstarpar_client -cpt (file) -input (file)\n");
+    fprintf (stderr, "USAGE: loadICRF_client -cpt (file) -input (file)\n");
     exit (2);
   }
@@ -201,9 +195,8 @@
 static void help () {
 
-  fprintf (stderr, "USAGE: loadstarpar [options] (file) [..more files]\n");
-  fprintf (stderr, "  add data from stellar parameter file to DVO\n\n");
+  fprintf (stderr, "USAGE: loadICRF [options] (file) [..more files]\n");
+  fprintf (stderr, "  add data from ICRF list to DVO\n\n");
 
   fprintf (stderr, "  optional flags:\n");
-  fprintf (stderr, "  -only-match           	  : only add measurements to existing objects\n");
   fprintf (stderr, "  -replace              	  : replace time/photcode measurements (no duplication)\n");
   fprintf (stderr, "  -v                    	  : verbose mode\n");
@@ -215,9 +208,8 @@
 static void help_client () {
 
-  fprintf (stderr, "USAGE: loadstarpar_client -D CATDIR catdir -hostID ID -hostdir (dir) -cpt (filename) -input (input) [options]\n");
+  fprintf (stderr, "USAGE: loadICRF_client -D CATDIR catdir -hostID ID -hostdir (dir) -cpt (filename) -input (input) [options]\n");
   fprintf (stderr, "  add data from stellar parameter file to DVO\n\n");
 
   fprintf (stderr, "  optional flags:\n");
-  fprintf (stderr, "  -only-match           	  : only add measurements to existing objects\n");
   fprintf (stderr, "  -replace              	  : replace time/photcode measurements (no duplication)\n");
   fprintf (stderr, "  -v                    	  : verbose mode\n");
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches_ICRF.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches_ICRF.c	(revision 37570)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches_ICRF.c	(revision 37570)
@@ -0,0 +1,178 @@
+# include "addstar.h"
+# include "loadICRF.h"
+
+// we find matching stars by (R,D).  we add the ICRF to the array of ICRFs with appropriate links.  
+int find_matches_ICRF (SkyRegion *region, ICRF_Stars *stars, int Nstars, Catalog *catalog, AddstarClientOptions *options) {
+  
+  off_t i, j, n, N, J, Jmin;
+  double RADIUS, RADIUS2, Rmin;
+  double *X1, *Y1, *X2, *Y2;
+  double dX, dY, dR;
+  off_t *N1, *N2;
+  off_t Nave, NAVE, Nmeas, NMEAS, Nmatch;
+
+  /** allocate local arrays (stars) **/
+  ALLOCATE (X1, double, Nstars);
+  ALLOCATE (Y1, double, Nstars);
+  ALLOCATE (N1, off_t,  Nstars);
+
+  /** allocate local arrays (catalog) **/
+  NAVE = Nave = catalog[0].Naverage;
+  ALLOCATE (X2, double, NAVE);
+  ALLOCATE (Y2, double, NAVE);
+  ALLOCATE (N2, off_t,  NAVE);
+
+  /* internal counters */
+  Nmatch = 0;
+
+  // current max obj ID for this catalog
+  unsigned int catID = catalog[0].catID;
+
+  int Nsecfilt = catalog[0].Nsecfilt;
+
+  NMEAS = Nmeas = catalog[0].Nmeasure;
+
+  /* project onto rectilinear grid with 1 arcsec pixels. the choice of ARC projection has
+   * the advantage that every point in R,D has a mapping to a unique X,Y.  However, note
+   * that not all possible X,Y points map back to R,D and the local plate scale changes
+   * far from the projection pole. We use the center of the region (catalog) for crval1,2.
+   */
+  Coords tcoords;
+  InitCoords (&tcoords, "DEC--ARC");
+  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
+  tcoords.crval2 = (region[0].Dmax < 90) ? 0.5*(region[0].Dmin + region[0].Dmax) : 90.0;
+  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
+
+  /* build spatial index (RA sort) referencing input array sequence */
+  for (i = 0; i < Nstars; i++) {
+    RD_to_XY (&X1[i], &Y1[i], stars[i].R, stars[i].D, &tcoords);
+    N1[i] = i;
+  }
+  sort_coords_index (X1, Y1, N1, Nstars);
+
+  /* build spatial index (RA sort) */
+  for (i = 0; i < Nave; i++) {
+    RD_to_XY (&X2[i], &Y2[i], catalog[0].average[i].R, catalog[0].average[i].D, &tcoords);
+    N2[i] = i;
+  }
+  sort_coords_index (X2, Y2, N2, Nave);
+
+  /* choose a radius for matches */
+  RADIUS = options->radius; /* provided by config */
+  RADIUS2 = RADIUS*RADIUS;
+
+  /** find matched stars **/
+  for (i = j = 0; (i < Nstars) && (j < Nave); ) {
+    if (!finite(X1[i]) || !finite(Y1[i])) { 
+      i++; 
+      continue;
+    }
+    if (!finite(X2[j]) || !finite(Y2[j])) { 
+      j++; 
+      continue;
+    }
+    
+    /* negative dX: j is too large */
+    dX = X1[i] - X2[j];
+    if (dX <= -1.02*RADIUS) {
+      i++;
+      continue;
+    }
+    /* positive dX, i is too large */
+    if (dX >= 1.02*RADIUS) {
+      j++;
+      continue;
+    }
+
+    if (stars[N1[i]].found) {
+      /* this star has already been assigned to an object in this or another catalog */
+      i++;
+      continue;
+    }
+
+    /* this block will match a given detection to the closest object within range of that
+       detection.  Note that this matches ALL detections within range of the single object
+       to that same object.  In the case of ICRF, this is what I want because I am
+       attaching each radio band as a separate measurement, with a single concatenated
+       list.  This is not super efficient, but ICRF is a small list
+     */
+    
+    /* within match range; look for matches */
+    Jmin = -1;
+    Rmin = RADIUS2;
+    for (J = j; (dX > -1.02*RADIUS) && (J < Nave); J++) {
+      /* find closest match for this detection */
+      dX = X1[i] - X2[J];
+      dY = Y1[i] - Y2[J];
+      dR = dX*dX + dY*dY;
+      if (dR > RADIUS2) continue;
+      if (dR < Rmin) {
+	Rmin = dR;
+	Jmin  = J;
+      }
+    }
+
+    /* no match, try next detection */ 
+    if (Jmin == -1) {
+      i++;
+      continue;
+    }
+
+    /*** a match is found, add to measure with links to average ***/
+    Nmatch ++;
+    n = N2[Jmin];
+    N = N1[i];
+
+    /* make sure there is space for next entry */
+    if (Nmeas >= NMEAS) {
+      NMEAS = Nmeas + 1000;
+      REALLOCATE (catalog[0].measure, Measure, NMEAS);
+    }
+
+    /** add new measurement for this star **/
+
+    // set the new measurements
+    catalog[0].measure[Nmeas]          = stars[N].measure;
+
+    // measure now carries R,D (not dR,dD) 
+    catalog[0].measure[Nmeas].dbFlags  = 0;
+    catalog[0].measure[Nmeas].averef   = n;
+    catalog[0].measure[Nmeas].objID    = catalog[0].average[n].objID;
+    catalog[0].measure[Nmeas].catID    = catID;
+
+    catalog[0].average[n].flags |= ID_ICRF_QSO;
+
+    stars[N].found = TRUE;
+    catalog[0].average[n].Nmeasure ++;
+    Nmeas ++;
+    i++;
+  }
+
+  // list missed QSOs, do not insert
+  for (i = 0; i < Nstars; i++) {
+    if (stars[i].found) continue;
+    if (!IN_REGION (stars[i].R, stars[i].D)) continue;
+    fprintf (stderr, "missed ICRF QSO @ %10.6f %10.6f\n", stars[i].R, stars[i].D);
+  }
+
+  REALLOCATE (catalog[0].average, Average, Nave);
+  REALLOCATE (catalog[0].measure, Measure, Nmeas);
+ 
+  catalog[0].sorted = FALSE;
+
+  /* check if the catalog has changed?  if no change, no need to write */
+  // catalog[0].objID     = objID; -- I am not adding new entries, so objID does not change
+  catalog[0].Naverage  = Nave;
+  catalog[0].Nmeasure  = Nmeas;
+  catalog[0].Nsecf_mem = Nave*Nsecfilt;
+  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %d "OFF_T_FMT" "OFF_T_FMT" ("OFF_T_FMT" matches)\n",  Nstars, Nave, Nmeas, Nmatch);
+
+  free (X1);
+  free (Y1);
+  free (N1);
+  free (N2);
+  free (X2);
+  free (Y2);
+
+  return (Nmatch);
+}
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF.c	(revision 37569)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF.c	(revision 37570)
@@ -1,12 +1,12 @@
 # include "addstar.h"
-# include "loadstarpar.h"
+# include "loadICRF.h"
 
-/* This is the DVO program to upload Greg Green's stellar parametersq into a DVO database.
-   It is modeled on the loadwise program and is expected to be run only rarely (once?).
-   The stellar parameter data are delivered as *.fits files.  It does not allow a subset
-   of the sky to be uploaded; entire stellar parameter files are loaded if supplied on the
-   command line.
+/* This is the DVO program to upload ICRF QSO data (eg, from Leonid Petrov) into a DVO
+   database.  It is modeled on the loadstarpar program and is expected to be run only
+   rarely (once?).  The ICRF QSO parameter data are delivered as text file.  It does not
+   allow a subset of the sky to be uploaded; entire QSO parameter files are loaded if
+   supplied on the command line.
 
-   USAGE: loadstarpar -D CATDIR (catdir) (file.fits) [...more files]
+   USAGE: loadICRF -D CATDIR (catdir) (file.fits) [...more files]
 */
 
@@ -16,7 +16,6 @@
   AddstarClientOptions options;
 
-  // need to construct these options with args_loadstarpar...
   options = ConfigInit (&argc, argv);
-  options = args_loadstarpar (argc, argv, options);
+  options = args_loadICRF (argc, argv, options); // XXX fix args after rest is done
 
   // load the full sky description table (dvodb must exist)
@@ -47,7 +46,8 @@
   SkyList *skylist = SkyListByPatch (sky, -1, &UserPatch);
 
+  // argv[i] are a list of input tables; load one at a time
   for (i = 1; i < argc; i++) {
     fprintf (stderr, "loading %s\n", argv[i]);
-    loadstarpar_table (skylist, hosts, argv[i], &options);
+    loadICRF_table (skylist, hosts, argv[i], &options);
   }
   exit (0);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_catalog.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_catalog.c	(revision 37569)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_catalog.c	(revision 37570)
@@ -1,6 +1,6 @@
 # include "addstar.h"
-# include "loadstarpar.h"
+# include "loadICRF.h"
 
-int loadstarpar_catalog (StarPar_Stars *stars, int Nstars, SkyRegion *region, char *filename, AddstarClientOptions *options) {
+int loadICRF_catalog (ICRF_Stars *stars, int Nstars, SkyRegion *region, char *filename, AddstarClientOptions *options) {
 
   Catalog catalog;
@@ -10,5 +10,5 @@
   catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
   catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
-  catalog.catflags = LOAD_AVES | LOAD_SECF | LOAD_STARPAR;
+  catalog.catflags = LOAD_AVES | LOAD_SECF | LOAD_MEAS;
   catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
     
@@ -19,5 +19,5 @@
   }
 
-  find_matches_starpar (region, stars, Nstars, &catalog, options);
+  find_matches_ICRF (region, stars, Nstars, &catalog, options);
     
   dvo_catalog_save (&catalog, VERBOSE);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_client.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_client.c	(revision 37569)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_client.c	(revision 37570)
@@ -1,4 +1,4 @@
 # include "addstar.h"
-# include "loadstarpar.h"
+# include "loadICRF.h"
 
 int main (int argc, char **argv) {
@@ -6,7 +6,7 @@
   AddstarClientOptions options;
 
-  // need to construct these options with args_loadstarpar...
+  // need to construct these options with args_loadICRF...
   options = ConfigInit (&argc, argv);
-  options = args_loadstarpar_client (argc, argv, options);
+  options = args_loadICRF_client (argc, argv, options);
 
   // client is called with a pointer to the file to be loaded
@@ -18,7 +18,7 @@
 
   int Nstars;
-  StarPar_Stars *stars = loadstarpar_load_stars (INPUT, &Nstars);
+  ICRF_Stars *stars = loadICRF_load_stars (INPUT, &Nstars);
 
-  loadstarpar_catalog (stars, Nstars, skylist->regions[0], CPT_FILE, &options);
+  loadICRF_catalog (stars, Nstars, skylist->regions[0], CPT_FILE, &options);
 
   free (stars);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_io.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_io.c	(revision 37569)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_io.c	(revision 37570)
@@ -1,6 +1,6 @@
 # include "addstar.h"
-# include "loadstarpar.h"
+# include "loadICRF.h"
 
-int loadstarpar_save_stars (char *filename, StarPar_Stars *stars, int Nstars) {
+int loadICRF_save_stars (char *filename, ICRF_Stars *stars, int Nstars) {
 
   Header header;
@@ -24,38 +24,36 @@
   gfits_free_matrix (&matrix);
 
-  gfits_create_table_header (&theader, "BINTABLE", "STARPAR");
+  gfits_create_table_header (&theader, "BINTABLE", "ICRF");
 
   gfits_define_bintable_column (&theader, "D", "RA",       "", "degree", 1.0, 0.0);
   gfits_define_bintable_column (&theader, "D", "DEC",      "", "degree", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "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", "RA_ERR",   "", "arcsec", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "DEC_ERR",  "", "arcsec", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "F_PSF",    "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "dF_PSF",   "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "F_AP",     "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "dF_AP",    "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "M_PSF",    "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "dM_PSF",   "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "M_AP",     "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "dM_AP",    "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "J", "PHOTCODE", "", "", 1.0, FT_BZERO_INT32);
+  gfits_define_bintable_column (&theader, "J", "FLAGS",    "", "", 1.0, FT_BZERO_INT32);
 
   int i;
-  double       *ra       = NULL; ALLOCATE (ra      , double	 , Nstars); for (i = 0; i < Nstars; i++) ra      [i] = stars[i].starpar.R ;
-  double       *dec      = NULL; ALLOCATE (dec     , double	 , Nstars); for (i = 0; i < Nstars; i++) dec     [i] = stars[i].starpar.D ;
-  float        *glon     = NULL; ALLOCATE (glon    , float 	 , Nstars); for (i = 0; i < Nstars; i++) glon    [i] = stars[i].starpar.galLon  ;
-  float        *glat     = NULL; ALLOCATE (glat    , float 	 , Nstars); for (i = 0; i < Nstars; i++) glat    [i] = stars[i].starpar.galLat  ;
-  float        *Ebv      = NULL; ALLOCATE (Ebv     , float	 , Nstars); for (i = 0; i < Nstars; i++) Ebv     [i] = stars[i].starpar.Ebv     ;
-  float        *dEbv     = NULL; ALLOCATE (dEbv    , float	 , Nstars); for (i = 0; i < Nstars; i++) dEbv    [i] = stars[i].starpar.dEbv    ;
-  float        *DistMag  = NULL; ALLOCATE (DistMag , float	 , Nstars); for (i = 0; i < Nstars; i++) DistMag [i] = stars[i].starpar.DistMag ;
-  float        *dDistMag = NULL; ALLOCATE (dDistMag, float	 , Nstars); for (i = 0; i < Nstars; i++) dDistMag[i] = stars[i].starpar.dDistMag;
-  float        *M_r      = NULL; ALLOCATE (M_r     , float	 , Nstars); for (i = 0; i < Nstars; i++) M_r     [i] = stars[i].starpar.M_r     ;
-  float        *dM_r     = NULL; ALLOCATE (dM_r    , float	 , Nstars); for (i = 0; i < Nstars; i++) dM_r    [i] = stars[i].starpar.dM_r    ;
-  float        *FeH      = NULL; ALLOCATE (FeH     , float	 , Nstars); for (i = 0; i < Nstars; i++) FeH     [i] = stars[i].starpar.FeH     ;
-  float        *dFeH     = NULL; ALLOCATE (dFeH    , float	 , Nstars); for (i = 0; i < Nstars; i++) dFeH    [i] = stars[i].starpar.dFeH    ;
-  unsigned int *averef   = NULL; ALLOCATE (averef  , unsigned int, Nstars); for (i = 0; i < Nstars; i++) averef  [i] = stars[i].starpar.averef  ;
-  unsigned int *objID    = NULL; ALLOCATE (objID   , unsigned int, Nstars); for (i = 0; i < Nstars; i++) objID   [i] = stars[i].starpar.objID   ;
-  unsigned int *catID    = NULL; ALLOCATE (catID   , unsigned int, Nstars); for (i = 0; i < Nstars; i++) catID   [i] = stars[i].starpar.catID   ;
+  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 ;
+  float        *dR       = NULL; ALLOCATE (dR      , float 	 , Nstars); for (i = 0; i < Nstars; i++) dR      [i] = stars[i].measure.dXccd   ;
+  float        *dD       = NULL; ALLOCATE (dD      , float 	 , Nstars); for (i = 0; i < Nstars; i++) dD      [i] = stars[i].measure.dYccd   ;
+  float        *Fpsf     = NULL; ALLOCATE (Fpsf    , float	 , Nstars); for (i = 0; i < Nstars; i++) Fpsf    [i] = stars[i].measure.FluxPSF ;
+  float        *dFpsf    = NULL; ALLOCATE (dFpsf   , float	 , Nstars); for (i = 0; i < Nstars; i++) dFpsf   [i] = stars[i].measure.dFluxPSF;
+  float        *Fap      = NULL; ALLOCATE (Fap     , float	 , Nstars); for (i = 0; i < Nstars; i++) Fap     [i] = stars[i].measure.FluxAp  ;
+  float        *dFap     = NULL; ALLOCATE (dFap    , float	 , Nstars); for (i = 0; i < Nstars; i++) dFap    [i] = stars[i].measure.dFluxAp ;
+  float        *Mpsf     = NULL; ALLOCATE (Mpsf    , float	 , Nstars); for (i = 0; i < Nstars; i++) Mpsf    [i] = stars[i].measure.M       ;
+  float        *dMpsf    = NULL; ALLOCATE (dMpsf   , float	 , Nstars); for (i = 0; i < Nstars; i++) dMpsf   [i] = stars[i].measure.dM      ;
+  float        *Map      = NULL; ALLOCATE (Map     , float	 , Nstars); for (i = 0; i < Nstars; i++) Map     [i] = stars[i].measure.Map     ;
+  float        *dMap     = NULL; ALLOCATE (dMap    , float	 , Nstars); for (i = 0; i < Nstars; i++) dMap    [i] = stars[i].measure.dMap    ;
+  unsigned int *photcode = NULL; ALLOCATE (photcode, unsigned int, Nstars); for (i = 0; i < Nstars; i++) photcode[i] = stars[i].measure.photcode;
+  unsigned int *flags    = NULL; ALLOCATE (flags   , unsigned int, Nstars); for (i = 0; i < Nstars; i++) flags   [i] = stars[i].measure.dbFlags ;
 
   // generate the output array that carries the data
@@ -65,17 +63,16 @@
   gfits_set_bintable_column (&theader, &ftable, "RA",       ra      , Nstars);
   gfits_set_bintable_column (&theader, &ftable, "DEC",      dec     , Nstars);
-  gfits_set_bintable_column (&theader, &ftable, "GLON",     glon    , Nstars);
-  gfits_set_bintable_column (&theader, &ftable, "GLAT",     glat    , Nstars);
-  gfits_set_bintable_column (&theader, &ftable, "Ebv",      Ebv     , Nstars);
-  gfits_set_bintable_column (&theader, &ftable, "dEbv",     dEbv    , Nstars);
-  gfits_set_bintable_column (&theader, &ftable, "DistMag",  DistMag , Nstars);
-  gfits_set_bintable_column (&theader, &ftable, "dDistMag", dDistMag, Nstars);
-  gfits_set_bintable_column (&theader, &ftable, "M_r",      M_r     , Nstars);
-  gfits_set_bintable_column (&theader, &ftable, "dM_r",     dM_r    , Nstars);
-  gfits_set_bintable_column (&theader, &ftable, "FeH",      FeH     , Nstars);
-  gfits_set_bintable_column (&theader, &ftable, "dFeH",     dFeH    , Nstars);
-  gfits_set_bintable_column (&theader, &ftable, "averef",   averef  , Nstars);
-  gfits_set_bintable_column (&theader, &ftable, "objID",    objID   , Nstars);
-  gfits_set_bintable_column (&theader, &ftable, "catID",    catID   , Nstars);
+  gfits_set_bintable_column (&theader, &ftable, "RA_ERR",   dR      , Nstars);
+  gfits_set_bintable_column (&theader, &ftable, "DEC_ERR",  dD      , Nstars);
+  gfits_set_bintable_column (&theader, &ftable, "F_PSF",    Fpsf    , Nstars);
+  gfits_set_bintable_column (&theader, &ftable, "dF_PSF",   dFpsf   , Nstars);
+  gfits_set_bintable_column (&theader, &ftable, "F_AP",     Fap     , Nstars);
+  gfits_set_bintable_column (&theader, &ftable, "dF_AP",    dFap    , Nstars);
+  gfits_set_bintable_column (&theader, &ftable, "M_PSF",    Mpsf    , Nstars);
+  gfits_set_bintable_column (&theader, &ftable, "dM_PSF",   dMpsf   , Nstars);
+  gfits_set_bintable_column (&theader, &ftable, "M_AP",     Map     , Nstars);
+  gfits_set_bintable_column (&theader, &ftable, "dM_AP",    dMap    , Nstars);
+  gfits_set_bintable_column (&theader, &ftable, "PHOTCODE", photcode, Nstars);
+  gfits_set_bintable_column (&theader, &ftable, "FLAGS",    flags   , Nstars);
     
   gfits_fwrite_Theader (f, &theader);
@@ -92,5 +89,5 @@
   myAssert (!strcmp(type, #TYPE), "wrong column type");
 
-StarPar_Stars *loadstarpar_load_stars (char *filename, int *nstars) {
+ICRF_Stars *loadICRF_load_stars (char *filename, int *nstars) {
 
   int i, Ncol;
@@ -98,5 +95,5 @@
   char type[16];
 
-  StarPar_Stars *stars = NULL;
+  ICRF_Stars *stars = NULL;
 
   Header header;
@@ -134,19 +131,18 @@
   if (!gfits_fread_ftable_data (f, &ftable, FALSE)) goto escape;
  
-  GET_COLUMN(ra      , "RA"        ,   double);
-  GET_COLUMN(dec     , "DEC"       ,   double);
-  GET_COLUMN(glon    , "GLON"      ,   float);
-  GET_COLUMN(glat    , "GLAT"      ,   float);
-  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);
+  GET_COLUMN(ra      , "RA",          double);
+  GET_COLUMN(dec     , "DEC",         double);
+  GET_COLUMN(dR      , "RA_ERR",      float);
+  GET_COLUMN(dD      , "DEC_ERR",     float);
+  GET_COLUMN(Fpsf    , "F_PSF",       float);
+  GET_COLUMN(dFpsf   , "dF_PSF",      float);
+  GET_COLUMN(Fap     , "F_AP",        float);
+  GET_COLUMN(dFap    , "dF_AP",       float);
+  GET_COLUMN(Mpsf    , "M_PSF",       float);
+  GET_COLUMN(dMpsf   , "dM_PSF",      float);
+  GET_COLUMN(Map     , "M_AP",        float);
+  GET_COLUMN(dMap    , "dM_AP",       float);
+  GET_COLUMN(photcode, "PHOTCODE",    unsigned int);
+  GET_COLUMN(flags   , "FLAGS",       unsigned int);
 
   gfits_free_header (&theader);
@@ -155,24 +151,24 @@
   gfits_free_matrix (&matrix);
 
-  ALLOCATE (stars, StarPar_Stars, Nrow);
+  ALLOCATE (stars, ICRF_Stars, Nrow);
 
   for (i = 0; i < Nrow; i++) {
-    stars[i].R                = ra      [i];
-    stars[i].D	              = dec     [i];
-    stars[i].starpar.R        = ra      [i];
-    stars[i].starpar.D        = dec     [i];
-    stars[i].starpar.galLon   = glon    [i];
-    stars[i].starpar.galLat   = glat    [i];
-    stars[i].starpar.Ebv      = Ebv     [i];
-    stars[i].starpar.dEbv     = dEbv    [i];
-    stars[i].starpar.DistMag  = DistMag [i];
-    stars[i].starpar.dDistMag = dDistMag[i];
-    stars[i].starpar.M_r      = M_r     [i];
-    stars[i].starpar.dM_r     = dM_r    [i];
-    stars[i].starpar.FeH      = FeH     [i];
-    stars[i].starpar.dFeH     = dFeH    [i];
-    stars[i].starpar.averef   = averef  [i];
-    stars[i].starpar.objID    = objID   [i];
-    stars[i].starpar.catID    = catID   [i];
+    InitICRF_Star (&stars[i]);
+    stars[i].R               = ra      [i];
+    stars[i].D	             = dec     [i];
+    stars[i].measure.R       = ra      [i];
+    stars[i].measure.D       = dec     [i];
+    stars[i].measure.dXccd   = dR      [i];
+    stars[i].measure.dYccd   = dD      [i];
+    stars[i].measure.FluxPSF = Fpsf    [i];
+    stars[i].measure.dFluxPSF= dFpsf   [i];
+    stars[i].measure.FluxAp  = Fap     [i];
+    stars[i].measure.dFluxAp = dFap    [i];
+    stars[i].measure.M       = Mpsf    [i];
+    stars[i].measure.dM      = dMpsf   [i];
+    stars[i].measure.Map     = Map     [i];
+    stars[i].measure.dMap    = dMap    [i];
+    stars[i].measure.photcode= photcode[i];
+    stars[i].measure.dbFlags = flags   [i];
   }
 
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_make_subset.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_make_subset.c	(revision 37569)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_make_subset.c	(revision 37570)
@@ -1,18 +1,18 @@
 # include "addstar.h"
-# include "loadstarpar.h"
+# include "loadICRF.h"
 
 // assign stars in the given region to the subset (NOTE: stars are sorted by RA, start is
 // first entry in stars array in this region)
 
-StarPar_Stars *loadstarpar_make_subset (StarPar_Stars *stars, int Nstars, int start, SkyRegion *region, int *nsubset) {
+ICRF_Stars *loadICRF_make_subset (ICRF_Stars *stars, int Nstars, int start, SkyRegion *region, int *nsubset) {
 
   int i;
 
-  StarPar_Stars *subset = NULL;
+  ICRF_Stars *subset = NULL;
 
   // collect array of (Stars *) stars in a new output catalog
   int Nsubset = 0;
   int NSUBSET = 3000;
-  ALLOCATE (subset, StarPar_Stars, NSUBSET);
+  ALLOCATE (subset, ICRF_Stars, NSUBSET);
 
   // find the rest of the stars in this output region
@@ -35,7 +35,7 @@
     Nsubset ++;
 
-    stars[i].flag = TRUE;
+    stars[i].flag = TRUE;  // set flag for stars we have already assigned to a subset
 
-    CHECK_REALLOCATE (subset, StarPar_Stars, NSUBSET, Nsubset, 10000);
+    CHECK_REALLOCATE (subset, ICRF_Stars, NSUBSET, Nsubset, 10000);
   }
 
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_readstars.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_readstars.c	(revision 37569)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_readstars.c	(revision 37570)
@@ -1,10 +1,40 @@
 # include "addstar.h"
-# include "loadstarpar.h"
+# include "loadICRF.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");
+// ICRF table is ASCII text, with the following interesting columns (fixed bytes)
+//   0       : type (C - calibrator, N - non-calibrator, U - unreliable)
+//   3 -  21 : names (make into an extID?)
+//  24 -  39 : RA (ICRF)
+//  40 -  55 : DEC (ICRF)
+//  57 -  62 : dR (mas) [use dX,dY in milliarcsec 'pixels']
+//  64 -  69 : dD (mas)
+//  79 -  84 : Number of observations used (put in dt?)
+//  87 -  92 : S-band total flux density integrated over entire map,  Jy  (note 87 may be <) : 
+//  94 -  99 : S-band unresolved flux density at long VLBA baselines, Jy
+// 102 - 107 : C-band total flux density integrated over entire map,  Jy
+// 109 - 114 : C-band unresolved flux density at long VLBA baselines, Jy
+// 117 - 122 : X-band total flux density integrated over entire map,  Jy
+// 124 - 129 : X-band unresolved flux density at long VLBA baselines, Jy
+// 132 - 137 : U-band total flux density integrated over entire map,  Jy
+// 139 - 144 : U-band unresolved flux density at long VLBA baselines, Jy
+// 147 - 152 : K-band total flux density integrated over entire map,  Jy
+// 154 - 159 : K-band unresolved flux density at long VLBA baselines, Jy
 
-StarPar_Stars *loadstarpar_readstars (char *filename, int *nstars) {
+// I'm going to save these are FluxPSF (total), FluxAp (unresolved), and mags for 
+// the signficant ones (AB_m from Jy).  Use new photcodes to represent C,X,U,K
+
+/* 
+#  IVS name J2000 name  Right ascension Declination        D_alp  D_Del   Corr    #Obs  S-band flux    C-band Flux    X-band Flux   U-band flux    K-band Flux    Type Cat
+#                                                                                       Total  Unres   Total  Unres   Total  Unres  Total  Unres   Total  Unres
+#                       hr mn seconds   deg mn seconds      mas    mas                   Jy     Jy      Jy     Jy      Jy     Jy     Jy     Jy      Jy     Jy
+C  2357+080 J0000+0816  00 00 07.031141 +08 16 45.05175    0.46   0.85   0.758     41  -1.00  -1.00   -1.00  -1.00    0.020 <0.014  -1.00  -1.00   -1.00  -1.00   X    rfc_2014c
+01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
+0         1         2         3         4         5         6         7         8         9         0         1         2         3         4         5         6         
+*/
+
+
+int loadICRF_addstar(ICRF_Stars *star, float fluxPSF, float fluxAp, double R, double D, float dX, float dY, int photcode);
+
+ICRF_Stars *loadICRF_readstars (char *filename, int *nstars) {
 
   // read in the full FITS files ('cause I don't have a partial read option)
@@ -12,145 +42,124 @@
   if (f == NULL) Shutdown ("can't read stellar parameter file: %s", filename);
 
-  int i, Ncol;
-  off_t Nrow;
+  int Nstars = 0;
+  int NSTARS = 1000;
+  ICRF_Stars *stars = NULL;
+  ALLOCATE (stars, ICRF_Stars, NSTARS);
 
-  Header header;
-  Matrix matrix;
-  Header theader;
-  FTable ftable;
-  
-  // load in PHU segment (ignore)
-  if (!gfits_fread_header (f, &header)) {
-    if (VERBOSE) fprintf (stderr, "can't read image subset header\n");
-    fclose (f);
-    return NULL;
+  double R, D;
+
+  // ICRF QSO photcodes (we store flux in Jy and AB mags) 
+  PhotCode *codeS = GetPhotcodebyName ("ICRF_S");
+  PhotCode *codeC = GetPhotcodebyName ("ICRF_C");
+  PhotCode *codeX = GetPhotcodebyName ("ICRF_X");
+  PhotCode *codeU = GetPhotcodebyName ("ICRF_U");
+  PhotCode *codeK = GetPhotcodebyName ("ICRF_K");
+
+  /* read in stars line-by-line */
+  char line[1024];
+  while (scan_line (f, line) != EOF) {
+    stripwhite (line);
+    if (line[0] == 0) continue;
+    if (line[0] == '#') continue;
+
+    // objects with values other than "C" in the first column are not good for
+    // calibration, so just skip.
+    if (line[0] != 'C') continue;
+
+    // terminate the partial strings containing RA and DEC:
+    char cr = line[39]; line[39] = 0;
+    char cd = line[55]; line[55] = 0;
+
+    if (!ohana_str_to_radec (&R, &D, &line[24], &line[40])) {
+      line[39] = cr;
+      line[55] = cd;
+      fprintf (stderr, "problem with coords: %s\n", line);
+      exit (1);
+    }
+    R = ohana_normalize_angle (R);
+    
+    line[63] = 0;
+    float dR = atof(&line[57]);
+    line[70] = 0;
+    float dD = atof(&line[64]);
+
+    int dX = 1000.0*100*dR;
+    int dY = 1000.0*100*dD;
+
+    // XXX set this somewhere?
+    // line[85] = 0;
+    // int Nmeas = atoi(&line[79]);
+
+    line[ 93] = 0; float fluxSt = (line[ 87] == '<') ? NAN : atof(&line[ 87]); if (fluxSt == -1.0) fluxSt = NAN;
+    line[100] = 0; float fluxSu = (line[ 94] == '<') ? NAN : atof(&line[ 94]); if (fluxSu == -1.0) fluxSu = NAN;
+    line[108] = 0; float fluxCt = (line[102] == '<') ? NAN : atof(&line[102]); if (fluxCt == -1.0) fluxCt = NAN;
+    line[115] = 0; float fluxCu = (line[109] == '<') ? NAN : atof(&line[109]); if (fluxCu == -1.0) fluxCu = NAN;
+    line[123] = 0; float fluxXt = (line[117] == '<') ? NAN : atof(&line[117]); if (fluxXt == -1.0) fluxXt = NAN;
+    line[130] = 0; float fluxXu = (line[124] == '<') ? NAN : atof(&line[124]); if (fluxXu == -1.0) fluxXu = NAN;
+    line[138] = 0; float fluxUt = (line[132] == '<') ? NAN : atof(&line[132]); if (fluxUt == -1.0) fluxUt = NAN;
+    line[145] = 0; float fluxUu = (line[139] == '<') ? NAN : atof(&line[139]); if (fluxUu == -1.0) fluxUu = NAN;
+    line[153] = 0; float fluxKt = (line[147] == '<') ? NAN : atof(&line[147]); if (fluxKt == -1.0) fluxKt = NAN;
+    line[160] = 0; float fluxKu = (line[154] == '<') ? NAN : atof(&line[154]); if (fluxKu == -1.0) fluxKu = NAN;
+
+    // we treat each valid flux as a new star
+    if (isfinite(fluxSt)) {
+      loadICRF_addstar (&stars[Nstars], fluxSt, fluxSu, R, D, dX, dY, codeS->code);
+      Nstars++;
+      CHECK_REALLOCATE (stars, ICRF_Stars, NSTARS, Nstars, 1000);
+    }
+    if (isfinite(fluxCt)) {
+      loadICRF_addstar (&stars[Nstars], fluxCt, fluxCu, R, D, dX, dY, codeC->code);
+      Nstars++;
+      CHECK_REALLOCATE (stars, ICRF_Stars, NSTARS, Nstars, 1000);
+    }
+    if (isfinite(fluxXt)) {
+      loadICRF_addstar (&stars[Nstars], fluxXt, fluxXu, R, D, dX, dY, codeX->code);
+      Nstars++;
+      CHECK_REALLOCATE (stars, ICRF_Stars, NSTARS, Nstars, 1000);
+    }
+    if (isfinite(fluxUt)) {
+      loadICRF_addstar (&stars[Nstars], fluxUt, fluxUu, R, D, dX, dY, codeU->code);
+      Nstars++;
+      CHECK_REALLOCATE (stars, ICRF_Stars, NSTARS, Nstars, 1000);
+    }
+    if (isfinite(fluxKt)) {
+      loadICRF_addstar (&stars[Nstars], fluxKt, fluxKu, R, D, dX, dY, codeK->code);
+      Nstars++;
+      CHECK_REALLOCATE (stars, ICRF_Stars, NSTARS, Nstars, 1000);
+    }
+
   }
-  if (!gfits_fread_matrix (f, &matrix, &header)) {
-    if (VERBOSE) fprintf (stderr, "can't read image subset matrix\n");
-    gfits_free_header (&header);
-    fclose (f);
-    return NULL;
-  }
-
-  ftable.header = &theader;
-
-  // load data for this header 
-  if (!gfits_load_header (f, &theader)) {
-    fclose (f);
-    return NULL;
-  }
-  if (!gfits_fread_ftable_data (f, &ftable, FALSE)) {
-    fclose (f);
-    return (NULL);
-  }
-
-  char type[16];
-
-  GET_COLUMN (glat,    "l",    float);
-  GET_COLUMN (glon,    "b",    float);
-  GET_COLUMN (conv,    "conv", byte);
-  GET_COLUMN (lnZ,     "lnZ",  float);
-  GET_COLUMN (DistMag, "DM",   float);
-  GET_COLUMN (Ebv,     "EBV",  float);
-  GET_COLUMN (M_r,     "Mr",   float);
-  GET_COLUMN (FeH,     "FeH",  float);
-
-  // free the memory associated with the FITS files
-  gfits_free_header (&header);
-  gfits_free_matrix (&matrix);
-  gfits_free_header (&theader);
-  gfits_free_table (&ftable);
-
-  // the next FITS extension contains the error information
-  if (!gfits_fread_header (f, &header)) {
-    if (VERBOSE) fprintf (stderr, "can't read image subset header\n");
-    fclose (f);
-    return NULL;
-  }
-  if (!gfits_fread_matrix (f, &matrix, &header)) {
-    if (VERBOSE) fprintf (stderr, "can't read image subset matrix\n");
-    gfits_free_header (&header);
-    fclose (f);
-    return NULL;
-  }
-  fclose (f);
-
-  double *errImage = (double *) matrix.buffer;
-
-  myAssert (Nrow == matrix.Naxis[2], "size mismatch?");
-
-  int NstarsIn = matrix.Naxis[2];
-
-  double Rmin = +360.0;
-  double Rmax = -360.0;
-  double Dmin = +360.0;
-  double Dmax = -360.0;
-
-  int Nstars = 0;
-  int NSTARS = 0.1*NstarsIn;
-
-  StarPar_Stars *stars = NULL;
-  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++) {
-
-    // skip stars based on conv and lnZ
-    if (!conv[i]) continue;
-    if (lnZ[i] < -15.0) continue;
-
-    double R, D;
-    ApplyTransform (&R, &D, glon[i], glat[i], transform);
-
-    Rmin = MIN (Rmin, R);
-    Rmax = MAX (Rmax, R);
-    Dmin = MIN (Dmin, D);
-    Dmax = MAX (Dmax, D);
-
-    float dEbv     = 0.5*(errImage[i*20 + 5*0 + 3] - errImage[i*20 + 5*0 + 1]);
-    float dDistMag = 0.5*(errImage[i*20 + 5*1 + 3] - errImage[i*20 + 5*1 + 1]);
-    float dM_r     = 0.5*(errImage[i*20 + 5*2 + 3] - errImage[i*20 + 5*2 + 1]);
-    float dFeH     = 0.5*(errImage[i*20 + 5*3 + 3] - errImage[i*20 + 5*3 + 1]);
-
-    stars[Nstars].R = R;
-    stars[Nstars].D = D;
-    stars[Nstars].flag  = FALSE;
-    stars[Nstars].found = FALSE;
-
-    // NOTE that we have both stars.R,D and stars.starpar.R,D.  stars.R,D are used 
-    // here (in parallel with addstar) to locate the objects.  BUT, in the database,
-    // starpar.R,D is the authoratative position for the object (either that coming 
-    // from Greg / Eddie's table or that coming from the simulation)
-    stars[Nstars].starpar.R      = R;
-    stars[Nstars].starpar.D      = D;
-    stars[Nstars].starpar.galLon = glon[i];
-    stars[Nstars].starpar.galLat = glat[i];
-
-    stars[Nstars].starpar.Ebv      = Ebv[i]    ;
-    stars[Nstars].starpar.dEbv     = dEbv      ;
-    stars[Nstars].starpar.DistMag  = DistMag[i];
-    stars[Nstars].starpar.dDistMag = dDistMag  ;
-    stars[Nstars].starpar.M_r      = M_r[i]    ;
-    stars[Nstars].starpar.dM_r     = dM_r      ;
-    stars[Nstars].starpar.FeH      = FeH[i]    ;
-    stars[Nstars].starpar.dFeH     = dFeH      ;
-
-    Nstars ++;
-
-    CHECK_REALLOCATE (stars, StarPar_Stars, NSTARS, Nstars, 10000);
-  }
-  gfits_free_header (&header);
-  gfits_free_matrix (&matrix);
-
   *nstars = Nstars;
   return (stars);
 }
 
-int loadstarpar_sortStars (StarPar_Stars *stars, int Nstars) {
+int loadICRF_addstar(ICRF_Stars *star, float fluxPSF, float fluxAp, double R, double D, float dX, float dY, int photcode) {
 
-# define SWAPFUNC(A,B){ StarPar_Stars temp = stars[A]; stars[A] = stars[B]; stars[B] = temp; }
+  InitICRF_Star (star);
+
+  star->R = R;
+  star->D = D;
+  star->measure.R = R;
+  star->measure.D = D;
+  star->measure.dXccd = dX;   // in centi-pixels, where 1 pixel = 1 mas
+  star->measure.dYccd = dY;   // in centi-pixels, where 1 pixel = 1 mas
+
+  star->measure.FluxPSF = fluxPSF; // flux in Jy
+  star->measure.dFluxPSF = 0.01;  // this is just a guess
+  star->measure.FluxAp = fluxAp;  // flux in Jy
+  star->measure.dFluxAp = 0.01;   // this is just a guess
+
+  star->measure.M = (fluxPSF > 0.0) ? 8.9 - 2.5*log10(fluxPSF) : NAN;
+  star->measure.dM = (fluxPSF > 0.0) ? 0.01 / fluxPSF : NAN;
+  star->measure.Map = (fluxAp > 0.0) ? 8.9 - 2.5*log10(fluxAp) : NAN;
+  star->measure.dMap = (fluxAp > 0.0) ? 0.01 / fluxAp: NAN;
+  star->measure.photcode = photcode;
+  star->measure.dbFlags |= ID_MEAS_ICRF_QSO;
+  return TRUE;
+}
+
+int loadICRF_sortStars (ICRF_Stars *stars, int Nstars) {
+
+# define SWAPFUNC(A,B){ ICRF_Stars temp = stars[A]; stars[A] = stars[B]; stars[B] = temp; }
 # define COMPARE(A,B)(stars[A].R < stars[B].R)
 
@@ -163,2 +172,9 @@
 }
 
+int InitICRF_Star (ICRF_Stars *star) {
+
+    dvo_measure_init (&star[0].measure);
+    star[0].found = FALSE; // FALSE = not yet assigned to an object
+    star[0].flag = FALSE; // FALSE = not yet assigned to a subset
+    return TRUE;
+}
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_remote_hosts.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_remote_hosts.c	(revision 37569)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_remote_hosts.c	(revision 37570)
@@ -1,4 +1,4 @@
 # include "addstar.h"
-# include "loadstarpar.h"
+# include "loadICRF.h"
 # include <sys/types.h>
 # include <sys/wait.h>
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_save_remote.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_save_remote.c	(revision 37569)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_save_remote.c	(revision 37570)
@@ -1,4 +1,4 @@
 # include "addstar.h"
-# include "loadstarpar.h"
+# include "loadICRF.h"
 # define DEBUG 1
 
@@ -16,5 +16,5 @@
 }
 
-int loadstarpar_save_remote (StarPar_Stars *stars, int Nstars, HostTable *hosts, SkyRegion *region, char *fullname, AddstarClientOptions *options) {
+int loadICRF_save_remote (ICRF_Stars *stars, int Nstars, HostTable *hosts, SkyRegion *region, char *fullname, AddstarClientOptions *options) {
 
   char uniquer[12];
@@ -25,5 +25,5 @@
   // if this region is a parallel thing, save and launch remote
   if (!PARALLEL) { 
-    loadstarpar_catalog (stars, Nstars, region, fullname, options);
+    loadICRF_catalog (stars, Nstars, region, fullname, options);
   } else {
     int N = hosts->index[region->hostID];
@@ -31,9 +31,9 @@
 
     // save to a unique filename
-    char filename[1024]; // CATDIR/tmpdir/starpar.PID.index.fits
-    snprintf (filename, 1024, "%s/tmpdir/starpar.%s.%05d.fits", CATDIR, uniquer, region->index);
+    char filename[1024]; // CATDIR/tmpdir/ICRF.PID.index.fits
+    snprintf (filename, 1024, "%s/tmpdir/ICRF.%s.%05d.fits", CATDIR, uniquer, region->index);
 
     // write the data to the given FITS file
-    loadstarpar_save_stars (filename, stars, Nstars);
+    loadICRF_save_stars (filename, stars, Nstars);
 
     int slot = -1;
@@ -63,5 +63,5 @@
     // need to generate the remote command
     char command[1024];
-    snprintf (command, 1024, "loadstarpar_client");
+    snprintf (command, 1024, "loadICRF_client");
     strextend (command, "-hostID %d", host->hostID);
     strextend (command, "-D CATDIR %s", CATDIR);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_table.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_table.c	(revision 37569)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadICRF_table.c	(revision 37570)
@@ -1,4 +1,4 @@
 # include "addstar.h"
-# include "loadstarpar.h"
+# include "loadICRF.h"
 
 # define GET_COLUMN(OUT,NAME,TYPE) \
@@ -6,12 +6,12 @@
   myAssert (!strcmp(type, #TYPE), "wrong column type");
 
-int loadstarpar_table (SkyList *skylistInput, HostTable *hosts, char *filename, AddstarClientOptions *options) {
+int loadICRF_table (SkyList *skylistInput, HostTable *hosts, char *filename, AddstarClientOptions *options) {
   
   int i, Nstars;
 
-  StarPar_Stars *stars = loadstarpar_readstars (filename, &Nstars);
+  ICRF_Stars *stars = loadICRF_readstars (filename, &Nstars);
 
   // sort the stars by RA
-  loadstarpar_sortStars (stars, Nstars);
+  loadICRF_sortStars (stars, Nstars);
 
   // scan through the stars, loading the containing catalogs
@@ -36,9 +36,9 @@
     // select stars matching this region
     int Nsubset;
-    StarPar_Stars *subset = loadstarpar_make_subset (stars, Nstars, i, region, &Nsubset);
+    ICRF_Stars *subset = loadICRF_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);
+    loadICRF_save_remote (subset, Nsubset, hosts, region, skylist[0].filename[0], options);
   }
 
Index: /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/images.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/images.c	(revision 37569)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/images.c	(revision 37570)
@@ -132,4 +132,15 @@
   if ((image = LoadImagesDVO (&Nimage)) == NULL) return (TRUE);
   BuildChipMatch (image, Nimage);
+
+  // XXX push this and BuildChipMatch into LoadImagesDVO?
+  char mapfile[DVO_MAX_PATH];
+  char *catdir = dvo_get_catdir ();
+  snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.fits", catdir);
+  AstromOffsetTable *table = AstromOffsetMapLoad (mapfile, FALSE);
+
+  // assign images.coords.offsetMap -> table->map[i]
+  if (table) {
+    AstromOffsetTableMatchChips (image, Nimage, table);
+  }
 
   if (SOLO_MOSAIC && photcode) {
