Index: trunk/Ohana/src/libdvo/include/dvo.h
===================================================================
--- trunk/Ohana/src/libdvo/include/dvo.h	(revision 39587)
+++ trunk/Ohana/src/libdvo/include/dvo.h	(revision 39588)
@@ -205,5 +205,5 @@
   ID_OBJ_GOOD            = 0x02000000, // good-quality measurement in our data (eg,PS)
   ID_OBJ_GOOD_ALT        = 0x04000000, // good-quality measurement in  external data (eg, 2MASS)
-  ID_OBJ_GOOD_STACK      = 0x08000000, // good-quality object in the stack (>= 1 good stack)
+  ID_OBJ_GOOD_STACK      = 0x08000000, // good-quality object in the stack (> 1 good stack)
   ID_OBJ_BEST_STACK      = 0x10000000, // the primary stack measurement are the best measurements
   ID_OBJ_SUSPECT_STACK   = 0x20000000, // suspect object in the stack (> 1 good or suspect stack, < 2 good)
@@ -226,5 +226,5 @@
   ID_SECF_RANK_3    	= 0x00000800, // average magnitude uses rank 3 values
   ID_SECF_RANK_4    	= 0x00001000, // average magnitude uses rank 4 values
-  ID_SECF_OBJ_EXT_PSPS  = 0x00002000, // In PSPS ID_SECF_OBJ_EXT is moved here so it fits within 16 bits
+  ID_SECF_OBJ_EXT_PSPS  = 0x00002000, // In PSPS ID_SECF_OBJ_EXT is moved here so it fits within 16 bits 
   ID_SECF_STACK_PRIMARY = 0x00004000, // PS1 stack photometry comes from primary skycell
   ID_SECF_OBJ_EXT       = 0x01000000, // extended in this band
@@ -1192,5 +1192,6 @@
 // galaxy_model:
 int TransformProperMotion_radians (double *uR, double *uD, double uL, double uB, double Rrad, double Drad, CoordTransform *transform);
-int TransformProperMotion (double *uR, double *uD, double uL, double uB, double R, double D, CoordTransform *transform);
+int TransformProperMotionForewards (double *uL, double *uB, double uR, double uD, double R, double D, CoordTransform *transform);
+int TransformProperMotionBackwards (double *uR, double *uD, double uL, double uB, double R, double D, CoordTransform *transform);
 int SolarMotionModel_radians (double *uL_sol, double *uB_sol, double Lrad, double Brad, double distance);
 int SolarMotionModel (double *uL_sol, double *uB_sol, double L, double B, double distance);
Index: trunk/Ohana/src/libdvo/src/galaxy_model.c
===================================================================
--- trunk/Ohana/src/libdvo/src/galaxy_model.c	(revision 39587)
+++ trunk/Ohana/src/libdvo/src/galaxy_model.c	(revision 39588)
@@ -61,6 +61,31 @@
 }
 
-// Use the inverse transform: CELESTIAL->GALACTIC for uL,uB -> uR,uD
-int TransformProperMotion (double *uR, double *uD, double uL, double uB, double R, double D, CoordTransform *transform) {
+// Use with the forward transformation: CELESTIAL->GALACTIC for uR,uD -> uL,uB
+int TransformProperMotionForewards (double *uL, double *uB, double uR, double uD, double R, double D, CoordTransform *transform) {
+
+  double Rrad = R*RAD_DEG;
+  double Drad = D*RAD_DEG;
+
+  // C1, C2 are from http://arxiv.org/pdf/1306.2945v2.pdf
+  double C1 = 
+    cos(Drad)*transform->cos_phi +
+    sin(Drad)*cos(Rrad)*transform->sin_phi_sin_Xo - 
+    sin(Drad)*sin(Rrad)*transform->sin_phi_cos_Xo;
+
+  double C2 =
+    - cos(Rrad)*transform->sin_phi_cos_Xo
+    - sin(Rrad)*transform->sin_phi_sin_Xo;
+
+  double cosBinv = 1.0 / sqrt(C1*C1 + C2*C2);
+
+  // XXX add errors : I need to be able to choose the stars based on the error distribution
+  *uL = cosBinv * (C1 * uR + C2 * uD);
+  *uB = cosBinv * (C1 * uD - C2 * uR);
+
+  return TRUE;
+}
+
+// Use with the forward transformation: CELESTIAL->GALACTIC for uL,uB -> uR,uD
+int TransformProperMotionBackwards (double *uR, double *uD, double uL, double uB, double R, double D, CoordTransform *transform) {
 
   double Rrad = R*RAD_DEG;
@@ -85,4 +110,5 @@
   return TRUE;
 }
+
 int TransformProperMotion_radians (double *uR, double *uD, double uL, double uB, double Rrad, double Drad, CoordTransform *transform) {
 
