Index: /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/include/fakeastro.h
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/include/fakeastro.h	(revision 37477)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/include/fakeastro.h	(revision 37478)
@@ -30,5 +30,4 @@
   Average  average;
   Measure  measure;
-  Lensing *lensing; // optionally carry out the lensing measurements
   int found;
 } Stars;
@@ -87,4 +86,10 @@
 
 int    FORCE;
+
+int FAKEASTRO_NLOOP;
+int FAKEASTRO_NSTARS;
+float FAKEASTRO_ZGAL; // parsec
+float FAKEASTRO_RGAL; // parsec
+char FAKEASTRO_REF_EPOCH[80];
 
 float  RADIUS;
Index: /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/ConfigInit.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/ConfigInit.c	(revision 37477)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/ConfigInit.c	(revision 37478)
@@ -34,4 +34,21 @@
   if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) SKY_DEPTH = 2;
   if (!ScanConfig (config, "SKY_TABLE",         "%s",  0, SKY_TABLE)) SKY_TABLE[0] = 0;
+
+  
+  if (!ScanConfig (config, "FAKEASTRO_NLOOP", "%d", 0, &FAKEASTRO_NLOOP)) {
+    FAKEASTRO_NLOOP = 1;
+  }
+  if (!ScanConfig (config, "FAKEASTRO_NSTARS", "%d", 0, &FAKEASTRO_NSTARS)) {
+    FAKEASTRO_NSTARS = 5000000;
+  }
+  if (!ScanConfig (config, "FAKEASTRO_ZGAL", "%f", 0, &FAKEASTRO_ZGAL)) {
+    FAKEASTRO_ZGAL = 500.0; // parsec
+  }
+  if (!ScanConfig (config, "FAKEASTRO_RGAL", "%f", 0, &FAKEASTRO_RGAL)) {
+    FAKEASTRO_RGAL = 2000.0; // parsec
+  }
+  if (!ScanConfig (config, "FAKEASTRO_REF_EPOCH", "%s", 0, FAKEASTRO_REF_EPOCH)) {
+    strcpy (FAKEASTRO_REF_EPOCH, "2011/05/11,00:00:00"); // epoch of reference catalog
+  }
 
   /* set the default search radius */
Index: /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/fakeastro_galaxy.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/fakeastro_galaxy.c	(revision 37477)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/fakeastro_galaxy.c	(revision 37478)
@@ -29,12 +29,12 @@
   }
 
-  int Nloop = 1;
-  int Nstars = 5000000;
-
-  for (n = 0; n < Nloop; n++) {
+  for (n = 0; n < FAKEASTRO_NLOOP; n++) {
 
     INITTIME;
 
+    int Nstars = FAKEASTRO_NSTARS;
     FakeAstro_Stars *stars = make_fakestars (Nstars);
+
+    FakeAstro_Stars *qso_icrf = make_fakeqsos (Nstars);
 
     MARKTIME ("generate %d fake stars in %f sec\n", Nstars, dtime);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/fit_fake_stars.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/fit_fake_stars.c	(revision 37477)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/fit_fake_stars.c	(revision 37478)
@@ -3,6 +3,13 @@
 int fit_fake_stars (Stars *stars, int Nstars, Image *image) {
 
-  // XXX I should set this based on Nstars
-  int order_use = 6;
+  // if we are doing imagemap or high-order polynomial fits, this is the order we should
+  // use
+  int order_use = 0;
+  if (Nstars >   5) order_use = 1; //  5 stars per cell
+  if (Nstars >  24) order_use = 2; //  6 stars per cell
+  if (Nstars >  63) order_use = 3; //  7 stars per cell
+  if (Nstars > 128) order_use = 4; //  8 stars per cell
+  if (Nstars > 225) order_use = 5; //  9 stars per cell
+  if (Nstars > 360) order_use = 6; // 10 stars per cell
 
   // I have Nstars with "reference" positions stars[].Rref,Dref and 
@@ -12,5 +19,5 @@
 
   int CHIPMAP = (image[0].coords.Npolyterms == -1);
-  if (CHIPMAP) image[0].coords.Npolyterms = -1;
+  image[0].coords.Npolyterms = CHIPMAP ? -1 : order_use;
 
   CoordFit *fit = fit_init (image[0].coords.Npolyterms);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/make_fake_images.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/make_fake_images.c	(revision 37477)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/make_fake_images.c	(revision 37478)
@@ -59,4 +59,6 @@
       fakeImage[N].coords.Npolyterms = 1;
 
+      // XXX add higher order polynomials or imagemaps here
+
       fakeImage[N].coords.mosaic = &fakeImage[0].coords;
 
Index: /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/make_fake_stars_catalog.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/make_fake_stars_catalog.c	(revision 37477)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/make_fake_stars_catalog.c	(revision 37478)
@@ -20,5 +20,5 @@
   int Nstars = *nstars;
   
-  time_t timeRef = ohana_date_to_sec("2011/05/11,00:00:00");
+  time_t timeRef = ohana_date_to_sec(FAKEASTRO_REF_EPOCH);
   
   if (!stars) {
Index: /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/make_fakeqsos.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/make_fakeqsos.c	(revision 37478)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/make_fakeqsos.c	(revision 37478)
@@ -0,0 +1,73 @@
+# include "fakeastro.h"
+
+FakeAstro_Stars *make_fakeqsos (int Nstars) {
+
+  FakeAstro_Stars *stars;
+  ALLOCATE (stars, FakeAstro_Stars, Nstars);
+
+  // do I want to add in a galaxy obscuration (P(b) ?)
+
+  int i;
+  for (i = 0; i < Nstars; i++) {
+
+    // ra, dec, distance, (absolute mag, colors) or (mass) or (MK type)
+
+    if (i % 100000 == 0) fprintf (stderr, ".");
+    double R,D;
+
+    int inPatch = FALSE;
+    while (!inPatch) {
+      double phi = 2.0 * drand48() - 1.0;
+      D = DEG_RAD * asin(phi);
+      R = drand48() * 2 * M_PI;
+      if (R < UserPatch.Rmin) continue;
+      if (R > UserPatch.Rmax) continue;
+      if (D < UserPatch.Dmin) continue;
+      if (D > UserPatch.Dmax) continue;
+      break;
+    }
+
+    double Mr = rnd_gauss (11.25, 1.0);
+    
+    // C1, C2 are from http://arxiv.org/pdf/1306.2945v2.pdf
+    double Rrad = R*RAD_DEG;
+    double Drad = D*RAD_DEG;
+
+    stars[i].R = R;
+    stars[i].D = D;
+    stars[i].flag  = FALSE;
+    stars[i].found = FALSE;
+
+    stars[i].starpar.galLon = NAN;
+    stars[i].starpar.galLat = NAN;
+
+    // how shall I ma
+    stars[i].starpar.Ebv      = 0.0;
+    stars[i].starpar.dEbv     = 0.0;
+    stars[i].starpar.DistMag  = 0.0;
+    stars[i].starpar.dDistMag = 0.0;
+    stars[i].starpar.M_r      = Mr;
+    stars[i].starpar.dM_r     = 0.0;
+    stars[i].starpar.FeH      = 0.0;
+    stars[i].starpar.dFeH     = 0.0;
+
+    stars[i].starpar.uRA  = uR;
+    stars[i].starpar.uDEC = uD;
+  }
+  fprintf (stderr, "\n");
+  return stars;
+}
+
+int sortStars (FakeAstro_Stars *stars, int Nstars) {
+
+# define SWAPFUNC(A,B){ FakeAstro_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/fakeastro/src/make_fakestars.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/make_fakestars.c	(revision 37477)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/make_fakestars.c	(revision 37478)
@@ -1,7 +1,3 @@
 # include "fakeastro.h"
-
-// # define Z_GAL 500.0
-# define Z_GAL 2000.0
-# define R_GAL 2000.0
 
 static double iFkap = 0.001 / 4.74047; // (km/sec/kpc) / (arcsec/ year)
@@ -41,6 +37,6 @@
     int inPatch = FALSE;
     while (!inPatch) {
-      z = rnd_gauss (0.0, Z_GAL);
-      r = sqrt(drand48()) * R_GAL;
+      z = rnd_gauss (0.0, FAKEASTRO_ZGAL);
+      r = sqrt(drand48()) * FAKEASTRO_RGAL;
       Lrad = drand48() * 2 * M_PI;
       Brad = atan2(z,r);
