Index: /trunk/Ohana/src/relastro/doc/pv2.txt
===================================================================
--- /trunk/Ohana/src/relastro/doc/pv2.txt	(revision 37038)
+++ /trunk/Ohana/src/relastro/doc/pv2.txt	(revision 37038)
@@ -0,0 +1,121 @@
+
+2014.07.03
+
+Thinking some more about the galactic rotation / solar motion based
+tie of relastro.  What do I need in the db to do this process?  Here
+is an outline:
+
+* generate the PS1 + 2MASS (+ other) database
+
+* ingest the stellar distances from greg.  this boils down to distance
+  (or parallax) + error.  These values exist for ~500M objects, so a
+  non-trivial fraction of the db.  I suppose the easiest way to handle
+  this is as an extra 2 fields in average.d.  The correct (database)
+  way to do this would be to define another table with objID, par,
+  dpar, refID
+
+* a stand-alone process like setastrom would run through the database
+  and set the RoffGAL,DoffGAL offsets.
+
+** I have a model for the motion, but I will need to choose a
+   reference date.  I suppose it does not matter too much in detail,
+   but obviously I should not choose J1900.  I assume I should choose
+   something like the mean epoch (but it needs to be a single epoch
+   for the survey).  so, eg, 2012.01.01.  So, I use the model to
+   predict the offset for the given distance in the dR,dD direction.  
+
+ref: R,D -> P,Q -> L,M -> X,Y (average)
+raw: X,Y -> L,N -> P,Q -> R,D (measure)
+
+* fit is raw.X,Y -> ref.L,M
+
+* KHE : apply correction to raw.X,Y (I can calculate it for all stars
+
+* DCR : apply correction to raw.X,Y (need more than one color, can
+  calculate up front). choose a median color and airmass?  
+
+* GAL : I want the transformation of a given image to convert X,Y to
+  R,D for that epoch. This really says I need to apply the proper
+  motion offset to the ref.R,D so ref.L,M is a prediction of the true
+  position.
+
+* QSO : I have the QSO coordinates in the db as specific measurments
+  with their own photcode(s).  During the iteration, extract all
+  average.R,D for the QSOs and their specific measurements.  Fit
+  Y(l,m) to dR,dD.  Find the significant entries (how).  Subtract the
+  offsets from ALL average.R,D values??
+
+---------------------------------------------------
+
+* external steps:
+
+  * set the KHE X,Y offset values
+  * set the DCR X,Y offset values
+  * ingest the GAL P,dP values, set the GAL dR,dD values
+
+* relastro loop
+  * update objects
+  * fit & apply the QSO correction
+  * update chips
+
+  ** I need to do a better job of tracking the change from each
+     iteration.
+
+  ** add a bunch of visualizations to demonstrate the quality  
+
+2014.07.01
+
+I had a nice conversation with Valeri Makarov about astrometric
+calibration.  I have committed to send them the qsos matched to ps1
+positions.
+
+some things Valeri raised:
+
+1) if I make the QSOs into hard points, then they will drive the
+solution have to a peak consistency at that location.  thus errors
+will build up away from those points, with potential ringing.  His
+suggestion is to use a set of spherical harmonics to fit the residual
+between the QSO positions and relastro fitted position and to correct
+based on this model fit. 
+
+How exactly that works is not completely clear to me.  I imaging doing
+something iteratively.  my sequence is basically:
+
+1) fit the image parameters
+2) determine the per-epoch R,D values
+3) determine mean positions
+4) fit the Ylms between QSO radio positions (selected subset only)
+   and the new fitted R,D values 
+5) identify the significant Ylm terms, the negative of this is the
+   correction (actually, I'm fitting dR,dD = Y^D_lm, Y^R_lm
+6) adjust the mean positions for all objects based on the correction
+7) re-fit the images to these new positions
+8) back to step 2 and repeat...
+
+Clearly I can only do this (consistently) if I fit the entire sky (or
+as much as possible) in a single pass. I'll need to put some smarts
+into the relastro_parallel_regions to get this right.  But, also note
+that having the technology in place to apply the Ylms means that I can
+apply a correction from Valeri, if supplied.
+
+** What new fields do I need to handle this?  
+
+2) regarding the application of the Galactic rotation / solar motion
+model, Valeri raise the concern that different populations follow
+different rotation curves.  This is a good point, and an obvious one
+in retrospect.  In fact, we would like to be able to measure this.  
+
+Now, clearly Pop I and Pop II stars are very different in terms of
+rotation / stellar motions.   How much does this matter?
+Specifically, how much does solar motion matter vs the galactic
+rotation model?  Also, what fraction of my reference stars are likely
+to be giants instead of MS stars?  
+
+Some mitigation strategies:  
+
+1) attempt to use only stars in a modest range of colors and predicted
+distances? 
+2) ??
+
+NOTE: I need to get the QSOs from bertrand
+
Index: /trunk/Ohana/src/relastro/include/relastro.h
===================================================================
--- /trunk/Ohana/src/relastro/include/relastro.h	(revision 37037)
+++ /trunk/Ohana/src/relastro/include/relastro.h	(revision 37038)
@@ -5,13 +5,4 @@
 # include <assert.h>
 # include <pthread.h>
-
-# define MARKTIME(MSG,...) {			\
-    gettimeofday (&stopTimer, (void *) NULL);	\
-    float dtime = DTIME (stopTimer, startTimer);	\
-    fprintf (stderr, MSG, __VA_ARGS__); }
-
-# define INITTIME \
-  struct timeval startTimer, stopTimer; \
-  gettimeofday (&startTimer, (void *) NULL);
 
 // choose off_t or int depending on full-scale relphot analysis resources
@@ -84,5 +75,6 @@
   double X, Y;  /* Chip Coords   - pixels  */
   float Mag;
-  float Color;
+  float ColorBlue;
+  float ColorRed;
   float dMag;
   float dPos;
@@ -218,7 +210,11 @@
 SkyRegionSelection SELECTION;
 
-char         *DCR_COLOR_POS,    *DCR_COLOR_NEG;
-PhotCode     *DCR_PHOTCODE_POS, *DCR_PHOTCODE_NEG; 
-int           DCR_NSEC_POS,      DCR_NSEC_NEG; 
+char         *DCR_BLUE_COLOR_POS,    *DCR_BLUE_COLOR_NEG;
+PhotCode     *DCR_BLUE_PHOTCODE_POS, *DCR_BLUE_PHOTCODE_NEG; 
+int           DCR_BLUE_NSEC_POS,      DCR_BLUE_NSEC_NEG; 
+
+char         *DCR_RED_COLOR_POS,    *DCR_RED_COLOR_NEG;
+PhotCode     *DCR_RED_PHOTCODE_POS, *DCR_RED_PHOTCODE_NEG; 
+int           DCR_RED_NSEC_POS,      DCR_RED_NSEC_NEG; 
 
 int ImagSelect;
@@ -532,5 +528,6 @@
 int select_mosaics_hostregion (RegionHostTable *regionHosts, Image *image, off_t Nimage);
 
-float getColor (off_t meas, int cat);
+float getColorBlue (off_t meas, int cat);
+float getColorRed (off_t meas, int cat);
 
 int strextend (char *input, char *format,...);
Index: /trunk/Ohana/src/relastro/src/BrightCatalog.c
===================================================================
--- /trunk/Ohana/src/relastro/src/BrightCatalog.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/BrightCatalog.c	(revision 37038)
@@ -68,6 +68,6 @@
  
     // need to create and assign to flat-field correction
-    GET_COLUMN(dR,        "RA_OFF",   	float);
-    GET_COLUMN(dD,        "DEC_OFF",  	float);
+    GET_COLUMN(R,         "RA",   	double);
+    GET_COLUMN(D,         "DEC",  	double);
     GET_COLUMN(M,         "MAG_SYS",  	float);
     GET_COLUMN(Mcal,      "MAG_CAL",  	float);
@@ -92,6 +92,6 @@
     ALLOCATE (measure, MeasureTiny, Nrow);
     for (i = 0; i < Nrow; i++) {
-      measure[i].dR        = dR[i];
-      measure[i].dD        = dD[i];
+      measure[i].R         = R[i];
+      measure[i].D         = D[i];
       measure[i].M         = M[i];
       measure[i].Mcal      = Mcal[i];
@@ -113,6 +113,6 @@
     // fprintf (stderr, "loaded data for %lld measures\n", (long long) Nrow);
 
-    free (dR      );
-    free (dD      );
+    free (R       );
+    free (D       );
     free (M       );
     free (Mcal    );
@@ -145,33 +145,34 @@
     if (!gfits_fread_ftable_data (f, &ftable, FALSE)) goto escape;
 
-    GET_COLUMN(R,              "RA",          double);
-    GET_COLUMN(D,              "DEC",         double);
-    GET_COLUMN(dR,             "RA_ERR",      float);
-    GET_COLUMN(dD,             "DEC_ERR",     float);
-    GET_COLUMN(uR,             "U_RA",        float);
-    GET_COLUMN(uD,             "U_DEC",       float);
-    GET_COLUMN(duR,            "V_RA_ERR",    float);
-    GET_COLUMN(duD,            "V_DEC_ERR",   float);
-    GET_COLUMN(P,              "PAR",         float);
-    GET_COLUMN(dP,             "PAR_ERR",     float);
-    GET_COLUMN(ChiSqAve,       "CHISQ_POS",   float);
-    GET_COLUMN(ChiSqPM,        "CHISQ_PM",    float);
-    GET_COLUMN(ChiSqPar,       "CHISQ_PAP",   float);
-    GET_COLUMN(Tmean,          "MEAN_EPOCH",  int);
-    GET_COLUMN(Trange,         "TIME_RANGE",  int);
-    GET_COLUMN(stargal,        "STARGAL_SEP", float);
-    GET_COLUMN(Npos,           "NUMBER_POS",  short);
-    GET_COLUMN(Nmeasure,       "NMEASURE",    short);
-    GET_COLUMN(Nmissing,       "NMISSING",    short);
-    GET_COLUMN(Nextend,        "NEXTEND",     short);
-    GET_COLUMN(measureOffset,  "OFF_MEASURE", int);
-    GET_COLUMN(missingOffset,  "OFF_MISSING", int);
-    GET_COLUMN(refColor,   "REF_COLOR",  float);
-    GET_COLUMN(flags,          "FLAGS",       int);
-    GET_COLUMN(photFlagsUpper, "PHOTFLAGS_U", int);
-    GET_COLUMN(photFlagsLower, "PHOTFLAGS_L", int);
-    GET_COLUMN(objID,          "OBJ_ID",      int);
-    GET_COLUMN(catID,          "CAT_ID",      int);
-    GET_COLUMN(extID,          "EXT_ID",      int64_t);
+    GET_COLUMN(R,              "RA",             double);
+    GET_COLUMN(D,              "DEC",            double);
+    GET_COLUMN(dR,             "RA_ERR",         float);
+    GET_COLUMN(dD,             "DEC_ERR",        float);
+    GET_COLUMN(uR,             "U_RA",           float);
+    GET_COLUMN(uD,             "U_DEC",          float);
+    GET_COLUMN(duR,            "V_RA_ERR",       float);
+    GET_COLUMN(duD,            "V_DEC_ERR",      float);
+    GET_COLUMN(P,              "PAR",            float);
+    GET_COLUMN(dP,             "PAR_ERR",        float);
+    GET_COLUMN(ChiSqAve,       "CHISQ_POS",      float);
+    GET_COLUMN(ChiSqPM,        "CHISQ_PM",       float);
+    GET_COLUMN(ChiSqPar,       "CHISQ_PAP",      float);
+    GET_COLUMN(Tmean,          "MEAN_EPOCH",     int);
+    GET_COLUMN(Trange,         "TIME_RANGE",     int);
+    GET_COLUMN(stargal,        "STARGAL_SEP",    float);
+    GET_COLUMN(Npos,           "NUMBER_POS",     short);
+    GET_COLUMN(Nmeasure,       "NMEASURE",       short);
+    GET_COLUMN(Nmissing,       "NMISSING",       short);
+    GET_COLUMN(Nextend,        "NEXTEND",        short);
+    GET_COLUMN(measureOffset,  "OFF_MEASURE",    int);
+    GET_COLUMN(missingOffset,  "OFF_MISSING",    int);
+    GET_COLUMN(refColorBlue,   "REF_COLOR_BLUE", float);
+    GET_COLUMN(refColorRed,    "REF_COLOR_RED",  float);
+    GET_COLUMN(flags,          "FLAGS",          int);
+    GET_COLUMN(photFlagsUpper, "PHOTFLAGS_U",    int);
+    GET_COLUMN(photFlagsLower, "PHOTFLAGS_L",    int);
+    GET_COLUMN(objID,          "OBJ_ID",         int);
+    GET_COLUMN(catID,          "CAT_ID",         int);
+    GET_COLUMN(extID,          "EXT_ID",         int64_t);
     gfits_free_header (&theader);
     gfits_free_table  (&ftable);
@@ -202,5 +203,6 @@
       average[i].measureOffset   = measureOffset[i]   ; 
       average[i].missingOffset   = missingOffset[i]   ; 
-      average[i].refColor    = refColor[i]    ;  
+      average[i].refColorBlue    = refColorBlue[i]    ;  
+      average[i].refColorRed     = refColorRed[i]     ;  
       average[i].flags           = flags[i]           ;
       average[i].photFlagsUpper  = photFlagsUpper[i]  ;
@@ -234,5 +236,6 @@
     free (measureOffset);
     free (missingOffset);
-    free (refColor);
+    free (refColorBlue);
+    free (refColorRed);
     free (flags);
     free (photFlagsUpper);
@@ -256,12 +259,12 @@
  
     // need to create and assign to flat-field correction
-    GET_COLUMN(M,     "MAG",      float);
-    GET_COLUMN(dM,    "MAG_ERR",  float);
-    GET_COLUMN(Xm,    "MAG_CHI",  float);
-    GET_COLUMN(flags, "FLAGS",    int);
-    GET_COLUMN(Ncode, "NCODE",    short);
-    GET_COLUMN(Nused, "NUSED",    short);
-    GET_COLUMN(M_20,  "MAG_20",   short);
-    GET_COLUMN(M_80,  "MAG_80",   short);
+    GET_COLUMN(M,      "MAG",      float);
+    GET_COLUMN(dM,     "MAG_ERR",  float);
+    GET_COLUMN(Mchisq, "MAG_CHI",  float);
+    GET_COLUMN(flags,  "FLAGS",    int);
+    GET_COLUMN(Ncode,  "NCODE",    short);
+    GET_COLUMN(Nused,  "NUSED",    short);
+    GET_COLUMN(Mmin,   "MAG_MIN",  float);
+    GET_COLUMN(Mmax,   "MAG_MAX",  float);
     gfits_free_header (&theader);
     gfits_free_table  (&ftable);
@@ -270,12 +273,12 @@
     ALLOCATE (secfilt, SecFilt, Nrow);
     for (i = 0; i < Nrow; i++) {
-      secfilt[i].M     = M[i];         
-      secfilt[i].dM    = dM[i];
-      secfilt[i].Xm    = Xm[i];
-      secfilt[i].flags = flags[i];
-      secfilt[i].Ncode = Ncode[i];
-      secfilt[i].Nused = Nused[i];
-      secfilt[i].M_20  = M_20[i];
-      secfilt[i].M_80  = M_80[i];
+      secfilt[i].M      = M[i];         
+      secfilt[i].dM     = dM[i];
+      secfilt[i].Mchisq = Mchisq[i];
+      secfilt[i].flags  = flags[i];
+      secfilt[i].Ncode  = Ncode[i];
+      secfilt[i].Nused  = Nused[i];
+      secfilt[i].Mmin   = Mmin[i];
+      secfilt[i].Mmax   = Mmax[i];
     }
     fprintf (stderr, "loaded data for %lld averages\n", (long long) Nrow);
@@ -283,10 +286,10 @@
     free (M    );
     free (dM   );
-    free (Xm   );
+    free (Mchisq);
     free (flags);
     free (Ncode);
     free (Nused);
-    free (M_20 );
-    free (M_80 );
+    free (Mmin );
+    free (Mmax );
     catalog->secfilt = secfilt;
     // assert Nsecfilt * Naverage = Nrow?
@@ -351,11 +354,11 @@
     gfits_define_bintable_column (&theader, "E", "Y_FIX",    "ccd y fiex coord",       	   "pix",    1.0, 0.0);
     gfits_define_bintable_column (&theader, "E", "EXPTIME",  "-2.5 * log (exposure time)", "sec",    1.0, 0.0);
-    gfits_define_bintable_column (&theader, "J", "TIME",     "time of exp",                "sec",    1.0, 1.0*0x8000);
-    gfits_define_bintable_column (&theader, "J", "AVE_REF",  "pointer to average table",    NULL,    1.0, 1.0*0x8000);
-    gfits_define_bintable_column (&theader, "J", "IMAGE_ID", "image",                       NULL,    1.0, 1.0*0x8000);
-    gfits_define_bintable_column (&theader, "J", "DB_FLAGS", "flags",                       NULL,    1.0, 1.0*0x8000);
-    gfits_define_bintable_column (&theader, "J", "PHOT_FLAGS", "photflags",                 NULL,    1.0, 1.0*0x8000);
-    gfits_define_bintable_column (&theader, "J", "CAT_ID",   "catalog",                     NULL,    1.0, 1.0*0x8000);
-    gfits_define_bintable_column (&theader, "I", "PHOTCODE", "photcode",                    NULL,    1.0, 1.0*0x80);
+    gfits_define_bintable_column (&theader, "J", "TIME",     "time of exp",                "sec",    1.0, 0.0);
+    gfits_define_bintable_column (&theader, "J", "AVE_REF",  "pointer to average table",    NULL,    1.0, 0.0);
+    gfits_define_bintable_column (&theader, "J", "IMAGE_ID", "image",                       NULL,    1.0, 0.0);
+    gfits_define_bintable_column (&theader, "J", "DB_FLAGS", "flags",                       NULL,    1.0, 0.0);
+    gfits_define_bintable_column (&theader, "J", "PHOT_FLAGS", "photflags",                 NULL,    1.0, 0.0);
+    gfits_define_bintable_column (&theader, "J", "CAT_ID",   "catalog",                     NULL,    1.0, 0.0);
+    gfits_define_bintable_column (&theader, "I", "PHOTCODE", "photcode",                    NULL,    1.0, 0.0);
 
     // generate the output array that carries the data
@@ -363,28 +366,28 @@
 
     // create intermediate storage arrays
-    float *dR        ; ALLOCATE (dR       ,  float, catalog->Nmeasure);
-    float *dD        ; ALLOCATE (dD       ,  float, catalog->Nmeasure);
-    float *M         ; ALLOCATE (M        ,  float, catalog->Nmeasure);
-    float *Mcal      ; ALLOCATE (Mcal     ,  float, catalog->Nmeasure);
-    float *dM        ; ALLOCATE (dM       ,  float, catalog->Nmeasure);
-    float *airmass   ; ALLOCATE (airmass  ,  float, catalog->Nmeasure);
-    float *Xccd      ; ALLOCATE (Xccd     ,  float, catalog->Nmeasure);
-    float *Yccd      ; ALLOCATE (Yccd     ,  float, catalog->Nmeasure);
-    float *Xfix      ; ALLOCATE (Xfix     ,  float, catalog->Nmeasure);
-    float *Yfix      ; ALLOCATE (Yfix     ,  float, catalog->Nmeasure);
-    float *dt        ; ALLOCATE (dt       ,  float, catalog->Nmeasure);
-    int   *t         ; ALLOCATE (t        ,  int  , catalog->Nmeasure);
-    int   *averef    ; ALLOCATE (averef   ,  int  , catalog->Nmeasure);
-    int   *imageID   ; ALLOCATE (imageID  ,  int  , catalog->Nmeasure);
-    int   *dbFlags   ; ALLOCATE (dbFlags  ,  int  , catalog->Nmeasure);
-    int   *photFlags ; ALLOCATE (photFlags,  int  , catalog->Nmeasure);
-    int   *catID     ; ALLOCATE (catID    ,  int  , catalog->Nmeasure);
-    short *photcode  ; ALLOCATE (photcode ,  short, catalog->Nmeasure);
+    double *R         ; ALLOCATE (R        ,  double, catalog->Nmeasure);
+    double *D         ; ALLOCATE (D        ,  double, catalog->Nmeasure);
+    float  *M         ; ALLOCATE (M        ,  float,  catalog->Nmeasure);
+    float  *Mcal      ; ALLOCATE (Mcal     ,  float,  catalog->Nmeasure);
+    float  *dM        ; ALLOCATE (dM       ,  float,  catalog->Nmeasure);
+    float  *airmass   ; ALLOCATE (airmass  ,  float,  catalog->Nmeasure);
+    float  *Xccd      ; ALLOCATE (Xccd     ,  float,  catalog->Nmeasure);
+    float  *Yccd      ; ALLOCATE (Yccd     ,  float,  catalog->Nmeasure);
+    float  *Xfix      ; ALLOCATE (Xfix     ,  float,  catalog->Nmeasure);
+    float  *Yfix      ; ALLOCATE (Yfix     ,  float,  catalog->Nmeasure);
+    float  *dt        ; ALLOCATE (dt       ,  float,  catalog->Nmeasure);
+    int    *t         ; ALLOCATE (t        ,  int  ,  catalog->Nmeasure);
+    int    *averef    ; ALLOCATE (averef   ,  int  ,  catalog->Nmeasure);
+    int    *imageID   ; ALLOCATE (imageID  ,  int  ,  catalog->Nmeasure);
+    int    *dbFlags   ; ALLOCATE (dbFlags  ,  int  ,  catalog->Nmeasure);
+    int    *photFlags ; ALLOCATE (photFlags,  int  ,  catalog->Nmeasure);
+    int    *catID     ; ALLOCATE (catID    ,  int  ,  catalog->Nmeasure);
+    short  *photcode  ; ALLOCATE (photcode ,  short,  catalog->Nmeasure);
 
     // assign the storage arrays
     MeasureTiny *measure = catalog->measure;
     for (i = 0; i < catalog->Nmeasure; i++) {
-      dR[i]       = measure[i].dR       ;
-      dD[i]       = measure[i].dD       ;
+      R[i]        = measure[i].R        ;
+      D[i]        = measure[i].D        ;
       M[i]  	  = measure[i].M        ;
       Mcal[i]     = measure[i].Mcal     ;
@@ -406,6 +409,6 @@
 
     // add the columns to the output array
-    gfits_set_bintable_column (&theader, &ftable, "RA_OFF",   	dR,        catalog->Nmeasure);
-    gfits_set_bintable_column (&theader, &ftable, "DEC_OFF",  	dD,        catalog->Nmeasure);
+    gfits_set_bintable_column (&theader, &ftable, "RA",   	R,         catalog->Nmeasure);
+    gfits_set_bintable_column (&theader, &ftable, "DEC",  	D,         catalog->Nmeasure);
     gfits_set_bintable_column (&theader, &ftable, "MAG_SYS",  	M,         catalog->Nmeasure);
     gfits_set_bintable_column (&theader, &ftable, "MAG_CAL",  	Mcal,      catalog->Nmeasure);
@@ -425,6 +428,6 @@
     gfits_set_bintable_column (&theader, &ftable, "PHOTCODE",   photcode,  catalog->Nmeasure);
 
-    free (dR      );
-    free (dD      );
+    free (R       );
+    free (D       );
     free (M       );
     free (Mcal    );
@@ -454,33 +457,34 @@
     gfits_create_table_header (&theader, "BINTABLE", "AVERAGE");
 
-    gfits_define_bintable_column (&theader, "D", "RA",          "RA", 	         	  	         		  "", 1.0, 0.0);
-    gfits_define_bintable_column (&theader, "D", "DEC",         "DEC", 	         	 	         		  "", 1.0, 0.0);
-    gfits_define_bintable_column (&theader, "E", "RA_ERR",      "RA error", 	         	         		  "", 1.0, 0.0);
-    gfits_define_bintable_column (&theader, "E", "DEC_ERR",     "DEC error", 	         	         		  "", 1.0, 0.0);
-    gfits_define_bintable_column (&theader, "E", "U_RA",        "RA*cos(D) proper-motion", 	         		  "", 1.0, 0.0);
-    gfits_define_bintable_column (&theader, "E", "U_DEC",       "DEC proper-motion", 	         	 		  "", 1.0, 0.0);
-    gfits_define_bintable_column (&theader, "E", "V_RA_ERR",    "RA*cos(D) p-m error", 	         	 		  "", 1.0, 0.0);
-    gfits_define_bintable_column (&theader, "E", "V_DEC_ERR",   "DEC p-m error", 	         	 		  "", 1.0, 0.0);
-    gfits_define_bintable_column (&theader, "E", "PAR",         "parallax", 	                         		  "", 1.0, 0.0);
-    gfits_define_bintable_column (&theader, "E", "PAR_ERR",     "parallax error", 	                 		  "", 1.0, 0.0);
-    gfits_define_bintable_column (&theader, "E", "CHISQ_POS",   "astrometry analysis chisq", 	         		  "", 1.0, 0.0);
-    gfits_define_bintable_column (&theader, "E", "CHISQ_PM",    "astrometry analysis chisq", 	         		  "", 1.0, 0.0);
-    gfits_define_bintable_column (&theader, "E", "CHISQ_PAP",   "astrometry analysis chisq", 	         		  "", 1.0, 0.0);
-    gfits_define_bintable_column (&theader, "J", "MEAN_EPOCH",  "mean epoch (PM-PAR ref)", 	         		  "", 1.0, 1.0*0x8000);
-    gfits_define_bintable_column (&theader, "J", "TIME_RANGE",  "mean epoch (PM-PAR ref)", 	         		  "", 1.0, 1.0*0x8000);
-    gfits_define_bintable_column (&theader, "E", "STARGAL_SEP", "star/galaxy separator",                		  "", 1.0, 0.0);   
-    gfits_define_bintable_column (&theader, "I", "NUMBER_POS",  "number of detections used for astrometry", 	          "", 1.0, 1.0*0x80);
-    gfits_define_bintable_column (&theader, "I", "NMEASURE",    "number of psf measurements", 	                          "", 1.0, 1.0*0x80);
-    gfits_define_bintable_column (&theader, "I", "NMISSING",    "number of missings", 	          	                  "", 1.0, 1.0*0x80);
-    gfits_define_bintable_column (&theader, "I", "NEXTEND",     "number of extended measurements", 	                  "", 1.0, 1.0*0x80);
-    gfits_define_bintable_column (&theader, "J", "OFF_MEASURE", "offset to first psf measurement", 	 	          "", 1.0, 1.0*0x8000);
-    gfits_define_bintable_column (&theader, "J", "OFF_MISSING", "offset to first missing obs", 	         	          "", 1.0, 1.0*0x8000);
-    gfits_define_bintable_column (&theader, "E", "REF_COLOR",   "reference color", 	                                  "", 1.0, 0.0);
-    gfits_define_bintable_column (&theader, "J", "FLAGS",       "average object flags (star; ghost; etc)", 	          "", 1.0, 1.0*0x8000);
-    gfits_define_bintable_column (&theader, "J", "PHOTFLAGS_U", "upper bit of 2 bit summary of per-measure photflags", 	  "", 1.0, 1.0*0x8000);
-    gfits_define_bintable_column (&theader, "J", "PHOTFLAGS_L", "lower bit of 2 bit summary of per-measure photflags", 	  "", 1.0, 1.0*0x8000);
-    gfits_define_bintable_column (&theader, "J", "OBJ_ID",      "unique ID for object in table", 	                  "", 1.0, 1.0*0x8000);
-    gfits_define_bintable_column (&theader, "J", "CAT_ID",      "unique ID for table in which object was first realized", "", 1.0, 1.0*0x8000);
-    gfits_define_bintable_column (&theader, "K", "EXT_ID",      "external ID for object (eg PSPS objID)", 	          "", 1.0, 1.0*0x80000000);
+    gfits_define_bintable_column (&theader, "D", "RA",             "RA", 	         	  	         	  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "D", "DEC",            "DEC", 	         	 	         	  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "RA_ERR",         "RA error", 	         	         		  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "DEC_ERR",        "DEC error", 	         	         	  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "U_RA",           "RA*cos(D) proper-motion", 	         		  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "U_DEC",          "DEC proper-motion", 	         	 	  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "V_RA_ERR",       "RA*cos(D) p-m error", 	         	 	  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "V_DEC_ERR",      "DEC p-m error", 	         	 		  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "PAR",            "parallax", 	                         		  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "PAR_ERR",        "parallax error", 	                 		  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "CHISQ_POS",      "astrometry analysis chisq", 	         	  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "CHISQ_PM",       "astrometry analysis chisq", 	         	  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "CHISQ_PAP",      "astrometry analysis chisq", 	         	  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "J", "MEAN_EPOCH",     "mean epoch (PM-PAR ref)", 	         		  "", 1.0, 0.00);
+    gfits_define_bintable_column (&theader, "J", "TIME_RANGE",     "mean epoch (PM-PAR ref)", 	         		  "", 1.0, 0.00);
+    gfits_define_bintable_column (&theader, "E", "STARGAL_SEP",    "star/galaxy separator",                		  "", 1.0, 0.0);   
+    gfits_define_bintable_column (&theader, "I", "NUMBER_POS",     "number of detections used for astrometry", 	          "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "I", "NMEASURE",       "number of psf measurements", 	                  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "I", "NMISSING",       "number of missings", 	          	          "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "I", "NEXTEND",        "number of extended measurements", 	                  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "J", "OFF_MEASURE",    "offset to first psf measurement", 	 	          "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "J", "OFF_MISSING",    "offset to first missing obs", 	         	  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "REF_COLOR_BLUE", "reference color", 	                                  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "REF_COLOR_RED",  "reference color", 	                                  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "J", "FLAGS",          "average object flags (star; ghost; etc)", 	          "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "J", "PHOTFLAGS_U",    "upper bit of 2 bit summary of per-measure photflags", "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "J", "PHOTFLAGS_L",    "lower bit of 2 bit summary of per-measure photflags", "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "J", "OBJ_ID",         "unique ID for object in table", 	                  "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "J", "CAT_ID",         "unique ID for table in which object was first realized", "", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "K", "EXT_ID",         "external ID for object (eg PSPS objID)", 	          "", 1.0, 0.0);
 
     // generate the output array that carries the data
@@ -510,5 +514,6 @@
     int      *measureOffset ; ALLOCATE (measureOffset , int     , catalog->Naverage);
     int      *missingOffset ; ALLOCATE (missingOffset , int     , catalog->Naverage);
-    float    *refColor      ; ALLOCATE (refColor  , float     , catalog->Naverage);
+    float    *refColorBlue  ; ALLOCATE (refColorBlue  , float   , catalog->Naverage);
+    float    *refColorRed   ; ALLOCATE (refColorRed   , float   , catalog->Naverage);
     int      *flags         ; ALLOCATE (flags         , int     , catalog->Naverage);
     int      *photFlagsUpper; ALLOCATE (photFlagsUpper, int     , catalog->Naverage);
@@ -543,5 +548,6 @@
       measureOffset[i]   = average[i].measureOffset   ; 
       missingOffset[i]   = average[i].missingOffset   ; 
-      refColor[i]    = average[i].refColor    ;  
+      refColorBlue[i]    = average[i].refColorBlue    ;  
+      refColorRed[i]     = average[i].refColorRed     ;  
       flags[i]           = average[i].flags           ;
       photFlagsUpper[i]  = average[i].photFlagsUpper  ;
@@ -553,33 +559,34 @@
 
     // add the columns to the output array
-    gfits_set_bintable_column (&theader, &ftable, "RA",          R,               catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "DEC",         D,               catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "RA_ERR",      dR,              catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "DEC_ERR",     dD,              catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "U_RA",        uR,              catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "U_DEC",       uD,              catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "V_RA_ERR",    duR,             catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "V_DEC_ERR",   duD,             catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "PAR",         P,               catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "PAR_ERR",     dP,              catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "CHISQ_POS",   ChiSqAve,        catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "CHISQ_PM",    ChiSqPM,         catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "CHISQ_PAP",   ChiSqPar,        catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "MEAN_EPOCH",  Tmean,           catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "TIME_RANGE",  Trange,          catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "STARGAL_SEP", stargal,         catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "NUMBER_POS",  Npos,            catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "NMEASURE",    Nmeasure,        catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "NMISSING",    Nmissing,        catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "NEXTEND",     Nextend,         catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "OFF_MEASURE", measureOffset,   catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "OFF_MISSING", missingOffset,   catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "REF_COLOR",   refColor,        catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "FLAGS",       flags,           catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "PHOTFLAGS_U", photFlagsUpper,  catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "PHOTFLAGS_L", photFlagsLower,  catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "OBJ_ID",      objID,           catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "CAT_ID",      catID,           catalog->Naverage);
-    gfits_set_bintable_column (&theader, &ftable, "EXT_ID",      extID,           catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "RA",             R,               catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "DEC",            D,               catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "RA_ERR",         dR,              catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "DEC_ERR",        dD,              catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "U_RA",           uR,              catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "U_DEC",          uD,              catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "V_RA_ERR",       duR,             catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "V_DEC_ERR",      duD,             catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "PAR",            P,               catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "PAR_ERR",        dP,              catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "CHISQ_POS",      ChiSqAve,        catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "CHISQ_PM",       ChiSqPM,         catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "CHISQ_PAP",      ChiSqPar,        catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "MEAN_EPOCH",     Tmean,           catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "TIME_RANGE",     Trange,          catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "STARGAL_SEP",    stargal,         catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "NUMBER_POS",     Npos,            catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "NMEASURE",       Nmeasure,        catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "NMISSING",       Nmissing,        catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "NEXTEND",        Nextend,         catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "OFF_MEASURE",    measureOffset,   catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "OFF_MISSING",    missingOffset,   catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "REF_COLOR_BLUE", refColorBlue,    catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "REF_COLOR_RED",  refColorRed,     catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "FLAGS",          flags,           catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "PHOTFLAGS_U",    photFlagsUpper,  catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "PHOTFLAGS_L",    photFlagsLower,  catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "OBJ_ID",         objID,           catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "CAT_ID",         catID,           catalog->Naverage);
+    gfits_set_bintable_column (&theader, &ftable, "EXT_ID",         extID,           catalog->Naverage);
 
     free (R);
@@ -605,5 +612,6 @@
     free (measureOffset);
     free (missingOffset);
-    free (refColor);
+    free (refColorBlue);
+    free (refColorRed);
     free (flags);
     free (photFlagsUpper);
@@ -629,6 +637,6 @@
     gfits_define_bintable_column (&theader, "I", "NCODE",    "magnitude (err)",           NULL,    1.0, 0.0);
     gfits_define_bintable_column (&theader, "I", "NUSED",    "airmass",                   NULL,    1.0, 0.0);
-    gfits_define_bintable_column (&theader, "I", "MAG_20",   "ccd x coord",              "pix",    1.0, 0.0);
-    gfits_define_bintable_column (&theader, "I", "MAG_80",   "ccd y coord",              "pix",    1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "MAG_MIN",   "ccd x coord",              "pix",    1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "MAG_MAX",   "ccd y coord",              "pix",    1.0, 0.0);
 
     // generate the output array that carries the data
@@ -642,42 +650,42 @@
     float *M        ; ALLOCATE (M      ,  float, Nsec);
     float *dM       ; ALLOCATE (dM     ,  float, Nsec);
-    float *Xm       ; ALLOCATE (Xm     ,  float, Nsec);
+    float *Mchisq   ; ALLOCATE (Mchisq ,  float, Nsec);
     int   *flags    ; ALLOCATE (flags  ,  int,   Nsec);
     short *Ncode    ; ALLOCATE (Ncode  ,  short, Nsec);
     short *Nused    ; ALLOCATE (Nused  ,  short, Nsec);
-    short *M_20     ; ALLOCATE (M_20   ,  short, Nsec);
-    short *M_80     ; ALLOCATE (M_80   ,  short, Nsec);
+    float *Mmin     ; ALLOCATE (Mmin   ,  float, Nsec);
+    float *Mmax     ; ALLOCATE (Mmax   ,  float, Nsec);
 
     // assign the storage arrays
     SecFilt *secfilt = catalog->secfilt;
     for (i = 0; i < Nsec; i++) {
-      M     [i]       = secfilt[i]. M      ;
-      dM    [i]       = secfilt[i]. dM     ;
-      Xm    [i]       = secfilt[i]. Xm     ;
-      flags [i]       = secfilt[i]. flags  ;
-      Ncode [i]       = secfilt[i]. Ncode  ;
-      Nused [i]       = secfilt[i]. Nused  ;
-      M_20  [i]       = secfilt[i]. M_20   ;
-      M_80  [i]       = secfilt[i]. M_80   ;
+      M     [i]       = secfilt[i].M      ;
+      dM    [i]       = secfilt[i].dM     ;
+      Mchisq[i]       = secfilt[i].Mchisq ;
+      flags [i]       = secfilt[i].flags  ;
+      Ncode [i]       = secfilt[i].Ncode  ;
+      Nused [i]       = secfilt[i].Nused  ;
+      Mmin  [i]       = secfilt[i].Mmin   ;
+      Mmax  [i]       = secfilt[i].Mmax   ;
     }
 
     // add the columns to the output array
-    gfits_set_bintable_column (&theader, &ftable, "MAG",      M    , Nsec);
-    gfits_set_bintable_column (&theader, &ftable, "MAG_ERR",  dM   , Nsec);
-    gfits_set_bintable_column (&theader, &ftable, "MAG_CHI",  Xm   , Nsec);
-    gfits_set_bintable_column (&theader, &ftable, "FLAGS",    flags, Nsec);
-    gfits_set_bintable_column (&theader, &ftable, "NCODE",    Ncode, Nsec);
-    gfits_set_bintable_column (&theader, &ftable, "NUSED",    Nused, Nsec);
-    gfits_set_bintable_column (&theader, &ftable, "MAG_20",   M_20 , Nsec);
-    gfits_set_bintable_column (&theader, &ftable, "MAG_80",   M_80 , Nsec);
+    gfits_set_bintable_column (&theader, &ftable, "MAG",      M     , Nsec);
+    gfits_set_bintable_column (&theader, &ftable, "MAG_ERR",  dM    , Nsec);
+    gfits_set_bintable_column (&theader, &ftable, "MAG_CHI",  Mchisq, Nsec);
+    gfits_set_bintable_column (&theader, &ftable, "FLAGS",    flags , Nsec);
+    gfits_set_bintable_column (&theader, &ftable, "NCODE",    Ncode , Nsec);
+    gfits_set_bintable_column (&theader, &ftable, "NUSED",    Nused , Nsec);
+    gfits_set_bintable_column (&theader, &ftable, "MAG_MIN",  Mmin  , Nsec);
+    gfits_set_bintable_column (&theader, &ftable, "MAG_MAX",  Mmax  , Nsec);
 
     free (M      );
     free (dM     );
-    free (Xm     );
+    free (Mchisq );
     free (flags  );
     free (Ncode  );
     free (Nused  );
-    free (M_20   );
-    free (M_80   );
+    free (Mmin   );
+    free (Mmax   );
 
     gfits_fwrite_Theader (f, &theader);
Index: /trunk/Ohana/src/relastro/src/FitChip.c
===================================================================
--- /trunk/Ohana/src/relastro/src/FitChip.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/FitChip.c	(revision 37038)
@@ -112,18 +112,33 @@
   }
 
-  int Ncolor = 0;
+  int Ncolor;
+  float colorMedian;
   float *colorList = NULL;
   ALLOCATE (colorList, float, Nmatch);
 
+  // calculate the median blue color
+  Ncolor = 0;
   for (i = 0; i < Nmatch; i++) {
     if (!raw[i].mask) continue;
-    if (!isnan(ref[i].Color)) {
-      colorList[Ncolor] = ref[i].Color;
-      Ncolor ++;
-    }
+    if (isnan(ref[i].ColorBlue)) continue;
+    colorList[Ncolor] = ref[i].ColorBlue;
+    Ncolor ++;
   }
   fsort (colorList, Ncolor);
-  float colorMedian = (Ncolor > 0) ? colorList[(int)(0.5*Ncolor)] : NAN;
-  image[0].refColor = colorMedian;
+  colorMedian = (Ncolor > 0) ? colorList[(int)(0.5*Ncolor)] : NAN;
+  image[0].refColorBlue = colorMedian;
+
+  // calculate the median red color
+  Ncolor = 0;
+  for (i = 0; i < Nmatch; i++) {
+    if (!raw[i].mask) continue;
+    if (isnan(ref[i].ColorRed)) continue;
+    colorList[Ncolor] = ref[i].ColorRed;
+    Ncolor ++;
+  }
+  fsort (colorList, Ncolor);
+  colorMedian = (Ncolor > 0) ? colorList[(int)(0.5*Ncolor)] : NAN;
+  image[0].refColorRed = colorMedian;
+
   free (colorList);
 
Index: /trunk/Ohana/src/relastro/src/ImageOps.c
===================================================================
--- /trunk/Ohana/src/relastro/src/ImageOps.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/ImageOps.c	(revision 37038)
@@ -345,5 +345,5 @@
 */
 
-float getColor (off_t meas, int cat) {
+float getColorBlue (off_t meas, int cat) {
 
   off_t i;
@@ -351,5 +351,14 @@
   i = MeasureToImage[cat][meas];
   if (i == -1) return (NAN);
-  return (image[i].refColor);
+  return (image[i].refColorBlue);
+}
+
+float getColorRed (off_t meas, int cat) {
+
+  off_t i;
+
+  i = MeasureToImage[cat][meas];
+  if (i == -1) return (NAN);
+  return (image[i].refColorRed);
 }
 
@@ -406,5 +415,5 @@
   for (j = 0; j < average[0].Nmeasure; j++) {
     off = average[0].measureOffset + j;
-    fprintf (stderr, "dR, dD, mag, dMag: %f, %f, %f, %f\n", measure[off].dR, measure[off].dD, measure[off].M, measure[off].dM);
+    fprintf (stderr, "R, D, mag, dMag: %lf, %lf, %f, %f\n", measure[off].R, measure[off].D, measure[off].M, measure[off].dM);
   }
   return;
@@ -554,27 +563,28 @@
 
     // complain if the new location is far from the old location
-    if (fabs(csdec*(measure[0].dR - dR)) > DPOS_MAX_ASEC) {
+    if (fabs(csdec*(measure[0].R - R)) > DPOS_MAX_ASEC) {
       NoffRAori ++;
       if (VERBOSE2) {
-	fprintf (stderr, "measurement moves far from original location (R): %f %f (%f %f %f %f)\n", average[0].R, average[0].D, measure[0].dR, dR, csdec*(measure[0].dR - dR), dD);
+	fprintf (stderr, "measurement moves far from original location (R): %f %f (%f %f %f %f)\n", average[0].R, average[0].D, measure[0].R, dR, csdec*(measure[0].R - R), dD);
 	dump_measures (&average[0], catalog[c].measure);
       }
       // abort();
     }
-    if (fabs(measure[0].dD - dD) > DPOS_MAX_ASEC) {
+    if (fabs(measure[0].D - D) > DPOS_MAX_ASEC) {
       NoffDECori ++;
       if (VERBOSE2) {
-	fprintf (stderr, "measurement moves far from original location (D): %f %f (%f %f %f)\n", average[0].R, average[0].D, dR, measure[0].dD, dD);
+	fprintf (stderr, "measurement moves far from original location (D): %f %f (%f %f %f)\n", average[0].R, average[0].D, dR, measure[0].D, dD);
 	dump_measures (&average[0], catalog[c].measure);
       }      // abort();
     }
 
-    dPos += SQ(measure[0].dR - dR) + SQ(measure[0].dD - dD);
+    // XXX NOTE : apply csdec:
+    dPos += SQ(measure[0].R - R) + SQ(measure[0].D - D);
     nPos ++;
 
-    measure[0].dR = dR;
-    measure[0].dD = dD;
-    measureT[0].dR = dR;
-    measureT[0].dD = dD;
+    measure[0].R = R;
+    measure[0].D = D;
+    measureT[0].R = R;
+    measureT[0].D = D;
     
     // set the systematic error for this image:
@@ -601,5 +611,5 @@
 
   off_t i, m, c, n;
-  double X, Y, L, M, P, Q, R, D, dR, dD;
+  double X, Y, L, M, P, Q, R, D;
 
   Mosaic *mosaic;
@@ -649,5 +659,4 @@
     n = measure[0].averef;
 
-    dR = dD = 0.0;
     if (moscoords == NULL) {
       // this is a Simple image (not a mosaic)
@@ -660,17 +669,17 @@
       LM_to_RD (&R, &D, P, Q, moscoords);
     }
-
-    measure[0].dR = dR;
-    measure[0].dD = dD;
-
-    if (measure[0].dR > +180.0*3600.0) {
+    measure[0].R = R;
+    measure[0].D = D;
+
+    float dRoff = dvoOffsetR(measure, &catalog[c].average[n]);
+
+    if (dRoff > +180.0*3600.0) {
       // average on high end of boundary, move star up
-      R += 360.0;
-      measure[0].dR = 3600.0*(catalog[c].average[n].R - R);
-    }
-    if (measure[0].dR < -180.0*3600.0) {
-      // average on low end of boundary, move star down
-      R -= 360.0;
-      measure[0].dR = 3600.0*(catalog[c].average[n].R - R);
+      measure[0].R += 360.0;
+      dRoff -= 360.0*3600.0;
+    }
+    if (dRoff < -180.0*3600.0) {
+      measure[0].R -= 360.0;
+      dRoff += 360.0*3600.0;
     }
   }
@@ -734,5 +743,5 @@
       raw[i].mask |= MARK_TOO_FEW_MEAS;
     }
-    if (!finite(measure[0].dR) || !finite(measure[0].dD)) {
+    if (!finite(measure[0].R) || !finite(measure[0].D)) {
       raw[i].mask |= MARK_NAN_POS_ERROR;
     }
@@ -803,6 +812,9 @@
     ref[i].dPos = GetAstromErrorTiny (&measure[0], ERROR_MODE_POS);
 
-    if ((DCR_NSEC_POS >= 0) && (DCR_NSEC_NEG >= -1)) {
-      ref[i].Color = catalog[c].secfilt[n*Nsecfilt + DCR_NSEC_POS].M - catalog[c].secfilt[n*Nsecfilt + DCR_NSEC_NEG].M;
+    if ((DCR_BLUE_NSEC_POS >= 0) && (DCR_BLUE_NSEC_NEG >= -1)) {
+      ref[i].ColorBlue = catalog[c].secfilt[n*Nsecfilt + DCR_BLUE_NSEC_POS].M - catalog[c].secfilt[n*Nsecfilt + DCR_BLUE_NSEC_NEG].M;
+    }
+    if ((DCR_RED_NSEC_POS >= 0) && (DCR_RED_NSEC_NEG >= -1)) {
+      ref[i].ColorRed = catalog[c].secfilt[n*Nsecfilt + DCR_RED_NSEC_POS].M - catalog[c].secfilt[n*Nsecfilt + DCR_RED_NSEC_NEG].M;
     }
 
@@ -880,6 +892,6 @@
       // skip measurements based on user selected criteria
       if (!MeasFilterTest(&measure[k], FALSE)) continue;
-      R[N] = measure[k].dR;
-      D[N] = measure[k].dD;
+      R[N] = measure[k].R;
+      D[N] = measure[k].D;
       dR[N] = GetAstromError (&measure[k], ERROR_MODE_RA);
       dD[N] = GetAstromError (&measure[k], ERROR_MODE_DEC);
@@ -906,6 +918,6 @@
       if (!MeasFilterTest(&measure[k], FALSE)) continue;
       
-      x = measure[k].dR - statsR.median;
-      y = measure[k].dD - statsD.median;
+      x = measure[k].R - statsR.median;
+      y = measure[k].D - statsD.median;
       theta = atan2(y,x);
       if ((x*x + y*y) > (SQR(statsR.sigma * Ns * cos(theta)) + 
@@ -981,6 +993,6 @@
       // skip measurements based on user selected criteria
       if (!MeasFilterTest(&measure[k], FALSE)) continue;
-      R[N] = measure[k].dR;
-      D[N] = measure[k].dD;
+      R[N] = measure[k].R;
+      D[N] = measure[k].D;
       dR[N] = GetAstromError(&measure[k], ERROR_MODE_RA);
       dD[N] = GetAstromError(&measure[k], ERROR_MODE_DEC);
@@ -1002,6 +1014,6 @@
       // skip bad measurements
       if (!MeasFilterTest(&measure[k], FALSE)) continue;  
-      x = measure[k].dR - statsR.median;
-      y = measure[k].dD - statsD.median;
+      x = measure[k].R - statsR.median;
+      y = measure[k].D - statsD.median;
       theta = atan2(y,x);
       d2[N] = (x*x + y*y) / (SQR(statsR.sigma * Ns * cos(theta)) + 
@@ -1018,6 +1030,6 @@
     for (k = 0;  k < N; k++) {
       off_t ind = (off_t) index[k];
-      R[k] = measure[ind].dR;
-      D[k] = measure[ind].dD;
+      R[k] = measure[ind].R;
+      D[k] = measure[ind].D;
       dR[k] = GetAstromError(&measure[ind], ERROR_MODE_RA);
       dD[k] = GetAstromError(&measure[ind], ERROR_MODE_DEC);
@@ -1033,6 +1045,6 @@
       //skip bad measurements
       if (!MeasFilterTest(&measure[k], FALSE)) continue;  
-      x = measure[k].dR - statsR.median;
-      y = measure[k].dD - statsD.median;
+      x = measure[k].R - statsR.median;
+      y = measure[k].D - statsD.median;
       theta = atan2(y,x);
       d2[N] = (x*x + y*y) / (SQR(statsR.sigma * Ns * cos(theta)) + 
@@ -1068,5 +1080,5 @@
   float mag;
 
-  if (!finite(measure[0].dR) || !finite(measure[0].dD)) return FALSE;
+  if (!finite(measure[0].R) || !finite(measure[0].D)) return FALSE;
   if (!finite(measure[0].M)) return FALSE; //XXX is this necessary for all relastro tasks?
   if (!finite(measure[0].dM)) return FALSE; //XXX is this necessary for all relastro tasks?
@@ -1120,5 +1132,5 @@
   /* select measurements by mag limit */
   if (ImagSelect) {
-    mag = PhotInstTiny (measure);
+    mag = PhotInstTiny (measure, MAG_CLASS_PSF);
     if (mag < ImagMin || mag > ImagMax) return FALSE;
   }
@@ -1135,5 +1147,5 @@
   float mag;
 
-  if (!finite(measure[0].dR) || !finite(measure[0].dD)) return FALSE;
+  if (!finite(measure[0].R) || !finite(measure[0].D)) return FALSE;
   if (!finite(measure[0].M)) return FALSE; //XXX is this necessary for all relastro tasks?
   if (!finite(measure[0].dM)) return FALSE; //XXX is this necessary for all relastro tasks?
@@ -1187,5 +1199,5 @@
   /* select measurements by mag limit */
   if (ImagSelect) {
-    mag = PhotInst (measure);
+    mag = PhotInst (measure, MAG_CLASS_PSF);
     if (mag < ImagMin || mag > ImagMax) return FALSE;
   }
Index: /trunk/Ohana/src/relastro/src/MeanPosIO.c
===================================================================
--- /trunk/Ohana/src/relastro/src/MeanPosIO.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/MeanPosIO.c	(revision 37038)
@@ -111,6 +111,6 @@
   gfits_define_bintable_column (&theader, "D", "RA",        "mean position, ra",  "degrees", 1.0, 0.0);
   gfits_define_bintable_column (&theader, "D", "DEC",       "mean position, dec", "degrees", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "J", "OBJ_ID",    "object ID",          NULL,      1.0, 1.0*0x8000);
-  gfits_define_bintable_column (&theader, "J", "CAT_ID",    "catalog ID",         NULL,      1.0, 1.0*0x8000);
+  gfits_define_bintable_column (&theader, "J", "OBJ_ID",    "object ID",          NULL,      1.0, FT_BZERO_INT32);
+  gfits_define_bintable_column (&theader, "J", "CAT_ID",    "catalog ID",         NULL,      1.0, FT_BZERO_INT32);
 
   // generate the output array that carries the data
Index: /trunk/Ohana/src/relastro/src/MosaicOps.c
===================================================================
--- /trunk/Ohana/src/relastro/src/MosaicOps.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/MosaicOps.c	(revision 37038)
@@ -97,12 +97,12 @@
 
     /* a new mosaic, define ranges */
-    mosaic[Nmosaic].start = start;
-    mosaic[Nmosaic].stop  = stop;
-    mosaic[Nmosaic].Mcal  = 0.0;
-    mosaic[Nmosaic].dMcal = 0.0;
-    mosaic[Nmosaic].Xm    = 0.0;
-    mosaic[Nmosaic].flags  = image[i].flags;
-    mosaic[Nmosaic].secz  = image[i].secz;
-    mosaic[Nmosaic].coords = image[i].coords;
+    mosaic[Nmosaic].start   = start;
+    mosaic[Nmosaic].stop    = stop;
+    mosaic[Nmosaic].Mcal    = 0.0;
+    mosaic[Nmosaic].dMcal   = 0.0;
+    mosaic[Nmosaic].Xm      = 0.0;
+    mosaic[Nmosaic].flags   = image[i].flags;
+    mosaic[Nmosaic].secz    = image[i].secz;
+    mosaic[Nmosaic].coords  = image[i].coords;
     mosaic[Nmosaic].myImage = i;
 
Index: /trunk/Ohana/src/relastro/src/Shutdown.c
===================================================================
--- /trunk/Ohana/src/relastro/src/Shutdown.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/Shutdown.c	(revision 37038)
@@ -23,5 +23,5 @@
   SetProtect (TRUE);
   gfits_db_close (db);
-  fprintf (stderr, "ERROR: addstar halted\n");
+  fprintf (stderr, "ERROR: relastro halted\n");
   exit (1);
 }
Index: /trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c
===================================================================
--- /trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c	(revision 37038)
@@ -153,6 +153,9 @@
     // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
 
-    if (DCR_COLOR_POS && DCR_COLOR_NEG) {
-      strextend (command, "-dcr-color %s %s", DCR_COLOR_POS, DCR_COLOR_NEG); 
+    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
+      strextend (command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG); 
+    }
+    if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
+      strextend (command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG); 
     }
 
Index: /trunk/Ohana/src/relastro/src/UpdateObjects.c
===================================================================
--- /trunk/Ohana/src/relastro/src/UpdateObjects.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/UpdateObjects.c	(revision 37038)
@@ -10,5 +10,6 @@
 static double *T;
 static double *dT;
-static double *C;
+static double *C_blue;
+static double *C_red;
 
 void initObjectData (Catalog *catalog, int Ncatalog) {
@@ -38,5 +39,6 @@
   ALLOCATE (pY, double, MAX (1, Nmax));
 
-  ALLOCATE (C, double, MAX (1, Nmax));
+  ALLOCATE (C_blue, double, MAX (1, Nmax));
+  ALLOCATE (C_red,  double, MAX (1, Nmax));
 }  
 
@@ -58,5 +60,6 @@
   free (pY);
 
-  free (C);
+  free (C_blue);
+  free (C_red);
 }  
 
@@ -66,5 +69,5 @@
 
   off_t j, k, m;
-  int i, N, Nc, Nsecfilt, mode, result, status, XVERB;
+  int i, N, NcBlue, NcRed, Nsecfilt, mode, result, status, XVERB;
   StatType statsR, statsD;
   Coords coords;
@@ -130,5 +133,6 @@
       }
 
-      Nc = 0;
+      NcBlue = 0;
+      NcRed = 0;
       N = 0;
       m = catalog[i].average[j].measureOffset;
@@ -149,5 +153,5 @@
 	  char *date = ohana_sec_to_date (measure[k].t);
 	  int dbFlagsBig = measureBig ? measureBig[k].dbFlags : 0;
-	  fprintf (stderr, OFF_T_FMT" %f %f %s : 0x%08x : 0x%08x\n",  k, measure[k].dR, measure[k].dD, date, measure[k].dbFlags, dbFlagsBig);
+	  fprintf (stderr, OFF_T_FMT" %f %f %s : 0x%08x : 0x%08x\n",  k, measure[k].R, measure[k].D, date, measure[k].dbFlags, dbFlagsBig);
 	  free (date);
 	}
@@ -225,8 +229,13 @@
 
 	if (setRefColor) {
-	  float color = getColor (m+k, i);
-	  if (!isnan(color)) {
-	    C[Nc] = color;
-	    Nc++;
+	  float colorBlue = getColorBlue (m+k, i);
+	  if (!isnan(colorBlue)) {
+	    C_blue[NcBlue] = colorBlue;
+	    NcBlue++;
+	  }
+	  float colorRed = getColorRed (m+k, i);
+	  if (!isnan(colorRed)) {
+	    C_red[NcRed] = colorRed;
+	    NcRed++;
 	  }
 	}
@@ -360,7 +369,11 @@
 
       if (setRefColor) {
-	dsort (C, Nc);
-	float colorMedian = (Nc > 0) ? C[(int)(0.5*Nc)] : NAN;
-	catalog[i].average[j].refColor = colorMedian;
+	float colorMedian;
+	dsort (C_blue, NcBlue);
+	colorMedian = (NcBlue > 0) ? C_blue[(int)(0.5*NcBlue)] : NAN;
+	catalog[i].average[j].refColorBlue = colorMedian;
+	dsort (C_red, NcRed);
+	colorMedian = (NcRed > 0) ? C_red[(int)(0.5*NcRed)] : NAN;
+	catalog[i].average[j].refColorRed = colorMedian;
       }
 
Index: /trunk/Ohana/src/relastro/src/args.c
===================================================================
--- /trunk/Ohana/src/relastro/src/args.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/args.c	(revision 37038)
@@ -294,11 +294,23 @@
   }
 
-  DCR_COLOR_POS = NULL;
-  DCR_COLOR_NEG = NULL;
-  if ((N = get_argument (argc, argv, "-dcr-color"))) {
-    remove_argument (N, &argc, argv);
-    DCR_COLOR_POS = strcreate(argv[N]);
-    remove_argument (N, &argc, argv);
-    DCR_COLOR_NEG = strcreate(argv[N]);
+  // eg g - r or r - i
+  DCR_BLUE_COLOR_POS = NULL;
+  DCR_BLUE_COLOR_NEG = NULL;
+  if ((N = get_argument (argc, argv, "-dcr-blue-color"))) {
+    remove_argument (N, &argc, argv);
+    DCR_BLUE_COLOR_POS = strcreate(argv[N]);
+    remove_argument (N, &argc, argv);
+    DCR_BLUE_COLOR_NEG = strcreate(argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  // eg, z - y or i - z
+  DCR_RED_COLOR_POS = NULL;
+  DCR_RED_COLOR_NEG = NULL;
+  if ((N = get_argument (argc, argv, "-dcr-red-color"))) {
+    remove_argument (N, &argc, argv);
+    DCR_RED_COLOR_POS = strcreate(argv[N]);
+    remove_argument (N, &argc, argv);
+    DCR_RED_COLOR_NEG = strcreate(argv[N]);
     remove_argument (N, &argc, argv);
   }
@@ -696,11 +708,20 @@
   }
 
-  DCR_COLOR_POS = NULL;
-  DCR_COLOR_NEG = NULL;
-  if ((N = get_argument (argc, argv, "-dcr-color"))) {
-    remove_argument (N, &argc, argv);
-    DCR_COLOR_POS = strcreate(argv[N]);
-    remove_argument (N, &argc, argv);
-    DCR_COLOR_NEG = strcreate(argv[N]);
+  DCR_BLUE_COLOR_POS = NULL;
+  DCR_BLUE_COLOR_NEG = NULL;
+  if ((N = get_argument (argc, argv, "-dcr-blue-color"))) {
+    remove_argument (N, &argc, argv);
+    DCR_BLUE_COLOR_POS = strcreate(argv[N]);
+    remove_argument (N, &argc, argv);
+    DCR_BLUE_COLOR_NEG = strcreate(argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  DCR_RED_COLOR_POS = NULL;
+  DCR_RED_COLOR_NEG = NULL;
+  if ((N = get_argument (argc, argv, "-dcr-red-color"))) {
+    remove_argument (N, &argc, argv);
+    DCR_RED_COLOR_POS = strcreate(argv[N]);
+    remove_argument (N, &argc, argv);
+    DCR_RED_COLOR_NEG = strcreate(argv[N]);
     remove_argument (N, &argc, argv);
   }
Index: /trunk/Ohana/src/relastro/src/dvo_astrom_ops.c
===================================================================
--- /trunk/Ohana/src/relastro/src/dvo_astrom_ops.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/dvo_astrom_ops.c	(revision 37038)
@@ -1,3 +1,4 @@
 # include "relastro.h"
+/* the Measure carries the instantaneous mean position at the epoch t */ 
 
 double getMeanR (MeasureTiny *measure, Average *average, SecFilt *secfilt) {
@@ -5,6 +6,79 @@
   double ra;
 
-  /* the measure carries the instantaneous mean position at the epoch t */ 
-  ra = average[0].R - measure[0].dR / 3600.0;
+  // old: ra = average[0].R - measure[0].dR / 3600.0;
+  if (!measure) return NAN;
+  ra = measure[0].R;
+
+  return (ra);
+}
+
+double getMeanD (MeasureTiny *measure, Average *average, SecFilt *secfilt) {
+
+  double dec;
+
+  // old: dec = average[0].D - measure[0].dD / 3600.0;
+  if (!measure) return NAN;
+  dec = measure[0].D;
+
+  return (dec);
+}
+
+int setMeanR (double ra_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt) {
+
+  // old: measure[0].dR += (ra_fit - average[0].R) * 3600.0;
+  if (!measure) return FALSE;
+  measure[0].R = ra_fit;
+
+  return (TRUE);
+}
+
+int setMeanD (double dec_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt) {
+
+  // old: measure[0].dD += (dec_fit - average[0].D) * 3600.0;
+  if (!measure) return FALSE;
+  measure[0].D = dec_fit;
+
+  return (TRUE);
+}
+
+double getMeanR_Big (Measure *measure, Average *average, SecFilt *secfilt) {
+
+  double ra;
+
+  // old: ra = average[0].R - measure[0].dR / 3600.0;
+  if (!measure) return NAN;
+  ra = measure[0].R;
+
+  return (ra);
+}
+
+double getMeanD_Big (Measure *measure, Average *average, SecFilt *secfilt) {
+
+  double dec;
+
+  // old: dec = average[0].D - measure[0].dD / 3600.0;
+  if (!measure) return NAN;
+  dec = measure[0].D;
+
+  return (dec);
+}
+
+int setMeanR_Big (double ra_fit, Measure *measure, Average *average, SecFilt *secfilt) {
+
+  // old: measure[0].dR += (ra_fit - average[0].R) * 3600.0;
+  if (!measure) return TRUE;
+  measure[0].R = ra_fit;
+
+  return (TRUE);
+}
+
+int setMeanD_Big (double dec_fit, Measure *measure, Average *average, SecFilt *secfilt) {
+
+  // measure[0].dD += (dec_fit - average[0].D) * 3600.0;
+  if (!measure) return TRUE;
+  measure[0].D = dec_fit;
+
+  return (TRUE);
+}
 
   /* possible corrections to mean ra:
@@ -18,169 +92,2 @@
   */
 
-  return (ra);
-}
-
-double getMeanD (MeasureTiny *measure, Average *average, SecFilt *secfilt) {
-
-  double dec;
-
-  /* the measure carries the instantaneous mean position at the epoch t */ 
-  dec = average[0].D - measure[0].dD / 3600.0;
-
-  /* possible corrections to mean ra:
-
-  - proper-motion and parallax
-  - abberation
-  - precession and nutation, etc
-  - refraction
-  - DCR
-
-  */
-
-  return (dec);
-}
-
-int setMeanR (double ra_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt) {
-
-  /* math to get from new fitted position to new measure offset
-     ra_obs = average[0].R - measure[0].dR / 3600.0;
-     measure[0].dR = (ra_fit - ra_obs) * 3600.0;
-     measure[0].dR = (ra_fit - average[0].R + measure[0].dR/3600) * 3600.0
-     measure[0].dR = (ra_fit - average[0].R) * 3600.0 + measure[0].dR;
-  */
-
-  /* the measure carries the instantaneous mean position at the epoch t */ 
-  measure[0].dR += (ra_fit - average[0].R) * 3600.0;
-
-  /* possible corrections to mean ra:
-
-  - proper-motion and parallax
-  - abberation
-  - precession and nutation, etc
-  - refraction
-  - DCR
-
-  */
-
-  return (TRUE);
-}
-
-int setMeanD (double dec_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt) {
-
-  /* math to get from new fitted position to new measure offset
-     dec_obs = average[0].D - measure[0].dD / 3600.0;
-     measure[0].dD = (dec_fit - dec_obs) * 3600.0;
-     measure[0].dD = (dec_fit - average[0].D + measure[0].dD/3600) * 3600.0
-     measure[0].dD = (dec_fit - average[0].D) * 3600.0 + measure[0].dD;
-  */
-
-  /* the measure carries the instantaneous mean position at the epoch t */ 
-  measure[0].dD += (dec_fit - average[0].D) * 3600.0;
-
-  /* possible corrections to mean ra:
-
-  - proper-motion and parallax
-  - abberation
-  - precession and nutation, etc
-  - refraction
-  - DCR
-
-  */
-
-  return (TRUE);
-}
-
-double getMeanR_Big (Measure *measure, Average *average, SecFilt *secfilt) {
-
-  double ra;
-
-  /* the measure carries the instantaneous mean position at the epoch t */ 
-  ra = average[0].R - measure[0].dR / 3600.0;
-
-  /* possible corrections to mean ra:
-
-  - proper-motion and parallax
-  - abberation
-  - precession and nutation, etc
-  - refraction
-  - DCR
-
-  */
-
-  return (ra);
-}
-
-double getMeanD_Big (Measure *measure, Average *average, SecFilt *secfilt) {
-
-  double dec;
-
-  /* the measure carries the instantaneous mean position at the epoch t */ 
-  dec = average[0].D - measure[0].dD / 3600.0;
-
-  /* possible corrections to mean ra:
-
-  - proper-motion and parallax
-  - abberation
-  - precession and nutation, etc
-  - refraction
-  - DCR
-
-  */
-
-  return (dec);
-}
-
-int setMeanR_Big (double ra_fit, Measure *measure, Average *average, SecFilt *secfilt) {
-
-  if (!measure) return TRUE;
-
-  /* math to get from new fitted position to new measure offset
-     ra_obs = average[0].R - measure[0].dR / 3600.0;
-     measure[0].dR = (ra_fit - ra_obs) * 3600.0;
-     measure[0].dR = (ra_fit - average[0].R + measure[0].dR/3600) * 3600.0
-     measure[0].dR = (ra_fit - average[0].R) * 3600.0 + measure[0].dR;
-  */
-
-  /* the measure carries the instantaneous mean position at the epoch t */ 
-  measure[0].dR += (ra_fit - average[0].R) * 3600.0;
-
-  /* possible corrections to mean ra:
-
-  - proper-motion and parallax
-  - abberation
-  - precession and nutation, etc
-  - refraction
-  - DCR
-
-  */
-
-  return (TRUE);
-}
-
-int setMeanD_Big (double dec_fit, Measure *measure, Average *average, SecFilt *secfilt) {
-
-  if (!measure) return TRUE;
-
-  /* math to get from new fitted position to new measure offset
-     dec_obs = average[0].D - measure[0].dD / 3600.0;
-     measure[0].dD = (dec_fit - dec_obs) * 3600.0;
-     measure[0].dD = (dec_fit - average[0].D + measure[0].dD/3600) * 3600.0
-     measure[0].dD = (dec_fit - average[0].D) * 3600.0 + measure[0].dD;
-  */
-
-  /* the measure carries the instantaneous mean position at the epoch t */ 
-  measure[0].dD += (dec_fit - average[0].D) * 3600.0;
-
-  /* possible corrections to mean ra:
-
-  - proper-motion and parallax
-  - abberation
-  - precession and nutation, etc
-  - refraction
-  - DCR
-
-  */
-
-  return (TRUE);
-}
-
Index: /trunk/Ohana/src/relastro/src/high_speed_objects.c
===================================================================
--- /trunk/Ohana/src/relastro/src/high_speed_objects.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/high_speed_objects.c	(revision 37038)
@@ -241,7 +241,7 @@
 	  for(i1=0;i1<catalog[0].average[nv[l]].Nmeasure;i1++) {
 	      catalogOut.measure[Nmatchmeas]=catalog[0].measure[m+i1];
-	      /*Set offset RA and Dec wrt correct average value*/
-	      catalogOut.measure[Nmatchmeas].dR=catalog[0].measure[m+i1].dR+3600.0*(catalog[0].average[nv[0]].R-catalog[0].average[nv[l]].R);
-	      catalogOut.measure[Nmatchmeas].dD=catalog[0].measure[m+i1].dD+3600.0*(catalog[0].average[nv[0]].D-catalog[0].average[nv[l]].D);
+	      // DROP no longer necessary to repoint R,D
+	      // catalogOut.measure[Nmatchmeas].dR=catalog[0].measure[m+i1].dR+3600.0*(catalog[0].average[nv[0]].R-catalog[0].average[nv[l]].R);
+	      // catalogOut.measure[Nmatchmeas].dD=catalog[0].measure[m+i1].dD+3600.0*(catalog[0].average[nv[0]].D-catalog[0].average[nv[l]].D);
 	      catalogOut.measure[Nmatchmeas].averef = Nmatch;
 	      Nmatchmeasobj++;
@@ -297,7 +297,7 @@
   // XXX require a set or not?  assert (Nset > 0);
 
-  if (!finite(measure[0].dR)) return FALSE;
-  if (!finite(measure[0].dD)) return FALSE;
-  if (!finite(measure[0].M))  return FALSE;
+  if (!finite(measure[0].R)) return FALSE;
+  if (!finite(measure[0].D)) return FALSE;
+  if (!finite(measure[0].M)) return FALSE;
   
   float dX = GetAstromError (measure, ERROR_MODE_RA);
Index: /trunk/Ohana/src/relastro/src/hpm_objects.c
===================================================================
--- /trunk/Ohana/src/relastro/src/hpm_objects.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/hpm_objects.c	(revision 37038)
@@ -240,7 +240,7 @@
       for (k = 0; k < catalog[0].average[nj].Nmeasure; k++) {
 	testcat.measure[Nmatchmeas] = catalog[0].measure[m+k];
-	/* Set offset RA and Dec wrt correct average value*/
-	testcat.measure[Nmatchmeas].dR = catalog[0].measure[m+k].dR + 3600.0*(catalog[0].average[ni].R - catalog[0].average[nj].R);
-	testcat.measure[Nmatchmeas].dD = catalog[0].measure[m+k].dD + 3600.0*(catalog[0].average[ni].D - catalog[0].average[nj].D);
+	// DROP: was needed when dR,dD were relative to average.R,D
+	// testcat.measure[Nmatchmeas].R = catalog[0].measure[m+k].R;
+	// testcat.measure[Nmatchmeas].D = catalog[0].measure[m+k].D;
 	testcat.measure[Nmatchmeas].averef = 0;
 	Nmatchmeas++;
Index: /trunk/Ohana/src/relastro/src/initialize.c
===================================================================
--- /trunk/Ohana/src/relastro/src/initialize.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/initialize.c	(revision 37038)
@@ -8,6 +8,6 @@
   if (RELASTRO_OP == OP_MERGE_SOURCE) return;
 
-  if (DCR_COLOR_POS)  fprintf (stderr, "DCR_COLOR_POS:  %s\n", DCR_COLOR_POS);
-  if (DCR_COLOR_NEG)  fprintf (stderr, "DCR_COLOR_NEG:  %s\n", DCR_COLOR_NEG);
+  if (DCR_BLUE_COLOR_POS)  fprintf (stderr, "DCR_BLUE_COLOR_POS:  %s - %s\n", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
+  if (DCR_BLUE_COLOR_POS)  fprintf (stderr, "DCR_BLUE_COLOR_POS:  %s - %s\n", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
 
   if (PHOTCODE_KEEP_LIST)  fprintf (stderr, "PHOTCODE_KEEP_LIST:  %s\n", PHOTCODE_KEEP_LIST);
@@ -23,20 +23,40 @@
   photcodesGroupB = ParsePhotcodeList (PHOTCODE_B_LIST,     &NphotcodesGroupB, TRUE);
 
-  DCR_NSEC_POS = DCR_NSEC_NEG = -1;
-  if (DCR_COLOR_POS) {
-    DCR_PHOTCODE_POS = GetPhotcodebyName (DCR_COLOR_POS);
-    if (!DCR_PHOTCODE_POS) {
-      fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", DCR_COLOR_POS);
+  // blue color elements
+  DCR_BLUE_NSEC_POS = DCR_BLUE_NSEC_NEG = -1;
+  if (DCR_BLUE_COLOR_POS) {
+    DCR_BLUE_PHOTCODE_POS = GetPhotcodebyName (DCR_BLUE_COLOR_POS);
+    if (!DCR_BLUE_PHOTCODE_POS) {
+      fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", DCR_BLUE_COLOR_POS);
       exit (1);
     }
-    DCR_NSEC_POS = GetPhotcodeNsec (DCR_PHOTCODE_POS[0].code);
+    DCR_BLUE_NSEC_POS = GetPhotcodeNsec (DCR_BLUE_PHOTCODE_POS[0].code);
   }
-  if (DCR_COLOR_NEG) {
-    DCR_PHOTCODE_NEG = GetPhotcodebyName (DCR_COLOR_NEG);
-    if (!DCR_PHOTCODE_NEG) {
-      fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", DCR_COLOR_NEG);
+  if (DCR_BLUE_COLOR_NEG) {
+    DCR_BLUE_PHOTCODE_NEG = GetPhotcodebyName (DCR_BLUE_COLOR_NEG);
+    if (!DCR_BLUE_PHOTCODE_NEG) {
+      fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", DCR_BLUE_COLOR_NEG);
       exit (1);
     }
-    DCR_NSEC_NEG = GetPhotcodeNsec (DCR_PHOTCODE_NEG[0].code);
+    DCR_BLUE_NSEC_NEG = GetPhotcodeNsec (DCR_BLUE_PHOTCODE_NEG[0].code);
+  }
+
+  // red color elements
+  DCR_RED_NSEC_POS = DCR_RED_NSEC_NEG = -1;
+  if (DCR_RED_COLOR_POS) {
+    DCR_RED_PHOTCODE_POS = GetPhotcodebyName (DCR_RED_COLOR_POS);
+    if (!DCR_RED_PHOTCODE_POS) {
+      fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", DCR_RED_COLOR_POS);
+      exit (1);
+    }
+    DCR_RED_NSEC_POS = GetPhotcodeNsec (DCR_RED_PHOTCODE_POS[0].code);
+  }
+  if (DCR_RED_COLOR_NEG) {
+    DCR_RED_PHOTCODE_NEG = GetPhotcodebyName (DCR_RED_COLOR_NEG);
+    if (!DCR_RED_PHOTCODE_NEG) {
+      fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", DCR_RED_COLOR_NEG);
+      exit (1);
+    }
+    DCR_RED_NSEC_NEG = GetPhotcodeNsec (DCR_RED_PHOTCODE_NEG[0].code);
   }
 
Index: /trunk/Ohana/src/relastro/src/launch_region_hosts.c
===================================================================
--- /trunk/Ohana/src/relastro/src/launch_region_hosts.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/launch_region_hosts.c	(revision 37038)
@@ -81,6 +81,9 @@
     if (ExcludeBogus)       strextend (command, "-exclude-bogus %f", ExcludeBogusRadius);
 
-    if (DCR_COLOR_POS && DCR_COLOR_NEG) {
-      strextend (command, "-dcr-color %s %s", DCR_COLOR_POS, DCR_COLOR_NEG); 
+    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
+      strextend (command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG); 
+    }
+    if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
+      strextend (command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG); 
     }
 
Index: /trunk/Ohana/src/relastro/src/load_catalogs.c
===================================================================
--- /trunk/Ohana/src/relastro/src/load_catalogs.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/load_catalogs.c	(revision 37038)
@@ -102,4 +102,10 @@
   }
 
+  // if we are running with parallel_images but not a parallel database, we need to
+  // release the lock so the next image host can proceed
+  if (!hostID && syncfile) {
+    update_sync_file (syncfile, 1);
+  }
+
   // only return the populated catalogs
   REALLOCATE (catalog, Catalog, Ncat);
@@ -165,6 +171,9 @@
     if (ExcludeBogus)  strextend (command, "-exclude-bogus %f", ExcludeBogusRadius);
     
-    if (DCR_COLOR_POS && DCR_COLOR_NEG) {
-      strextend (command, "-dcr-color %s %s", DCR_COLOR_POS, DCR_COLOR_NEG); 
+    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
+      strextend (command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG); 
+    }
+    if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
+      strextend (command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG); 
     }
 
@@ -215,5 +224,9 @@
   }
 
-  // update syncfile here (save lots of I/O time)
+  // update syncfile here (save lots of I/O time):
+
+  // at this point, the remote relastro_client jobs are done loading their data.  in a
+  // parallel_images mode, the next image host can be launched while this image host now
+  // reads that
 
   // NOTE: if I let all hosts load blindly, I saturate the data clients with too many
Index: /trunk/Ohana/src/relastro/src/markObjects.c
===================================================================
--- /trunk/Ohana/src/relastro/src/markObjects.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/markObjects.c	(revision 37038)
@@ -8,6 +8,6 @@
   // How strongly do I own this object?
   for (i = 0; i < Ncatalog; i++) {
-    ALLOCATE (catalog[i].nOwn, int, catalog[i].Naverage);
-    memset (catalog[i].nOwn, 0, catalog[i].Naverage*sizeof(int));
+    ALLOCATE (catalog[i].nOwn_t, int, catalog[i].Naverage);
+    memset (catalog[i].nOwn_t, 0, catalog[i].Naverage*sizeof(int));
     for (j = 0; j < catalog[i].Naverage; j++) {
       int nOwn = 0;
@@ -17,5 +17,5 @@
 	nOwn ++;
       }
-      catalog[i].nOwn[j] = nOwn;
+      catalog[i].nOwn_t[j] = nOwn;
     }
   }
Index: /trunk/Ohana/src/relastro/src/relastroVisual.c
===================================================================
--- /trunk/Ohana/src/relastro/src/relastroVisual.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/relastroVisual.c	(revision 37038)
@@ -431,6 +431,6 @@
   
   // populate vectors
-  ALLOCATE(Din, float, Nmeasure);
-  ALLOCATE(Rin, float, Nmeasure);
+  ALLOCATE(Din,  float, Nmeasure);
+  ALLOCATE(Rin,  float, Nmeasure);
   ALLOCATE(Dout, float, Nmeasure);
   ALLOCATE(Rout, float, Nmeasure);
@@ -451,17 +451,17 @@
     meas = catalog[0].measure[m];
     if (!MeasFilterTest(&meas, FALSE)) continue;
-    xmin = MIN(xmin, meas.dR);
-    xmax = MAX(xmax, meas.dR);
-    ymin = MIN(ymin, meas.dD);
-    ymax = MAX(ymax, meas.dD);
+    xmin = MIN(xmin, meas.R);
+    xmax = MAX(xmax, meas.R);
+    ymin = MIN(ymin, meas.D);
+    ymax = MAX(ymax, meas.D);
     
     if (meas.dbFlags & ID_MEAS_POOR_ASTROM) {
-      Rout[Nout] = (float)(meas.dR);
-      Dout[Nout] = (float)(meas.dD);
+      Rout[Nout] = (meas.R);
+      Dout[Nout] = (meas.D);
       fprintf(stderr, "r: %f\td: %f\t outlier: 1\n", Rout[Nout], Dout[Nout]);
       Nout++;
     } else {
-      Rin[Nin] = (float)(meas.dR);
-      Din[Nin] = (float)(meas.dD);
+      Rin[Nin] = (meas.R);
+      Din[Nin] = (meas.D);
       fprintf(stderr, "r: %f\td: %f\t outlier: 0\n", Rin[Nin], Din[Nin]);
       Nin++;
Index: /trunk/Ohana/src/relastro/src/relastro_merge_source.c
===================================================================
--- /trunk/Ohana/src/relastro/src/relastro_merge_source.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/relastro_merge_source.c	(revision 37038)
@@ -100,11 +100,12 @@
       catalog_src.measure[m].averef = index_dst;
 
+      // OLD CODE: when measure.dR,dD were relative to average.R,D it was necessary to modify them
       // get the instantaneous positions:
-      double R = catalog_src.average[index_src].R - catalog_src.measure[m].dR / 3600.0;
-      double D = catalog_src.average[index_src].D - catalog_src.measure[m].dD / 3600.0;
+      // DROP double R = catalog_src.average[index_src].R - catalog_src.measure[m].dR / 3600.0;
+      // DROP double D = catalog_src.average[index_src].D - catalog_src.measure[m].dD / 3600.0;
 
       // update the offset coordinates to match the new source
-      catalog_src.measure[m].dR = 3600.0*(catalog_src.average[index_dst].R - R);
-      catalog_src.measure[m].dD = 3600.0*(catalog_src.average[index_dst].D - D);
+      // DROP catalog_src.measure[m].dR = 3600.0*(catalog_src.average[index_dst].R - R);
+      // DROP catalog_src.measure[m].dD = 3600.0*(catalog_src.average[index_dst].D - D);
     }
 
Index: /trunk/Ohana/src/relastro/src/share_mean_pos.c
===================================================================
--- /trunk/Ohana/src/relastro/src/share_mean_pos.c	(revision 37037)
+++ /trunk/Ohana/src/relastro/src/share_mean_pos.c	(revision 37038)
@@ -33,5 +33,5 @@
       // XXX : sky objects without missing detections
       // XXX watch out for detections which are not associated with an image (REF)
-      if (catalog[i].nOwn[j] == catalog[i].average[j].Nmeasure) continue;
+      if (catalog[i].nOwn_t[j] == catalog[i].average[j].Nmeasure) continue;
 
       set_mean_pos (&meanpos[Nmeanpos], &catalog[i].average[j]);
