Index: trunk/Ohana/src/libdvo/include/dvo.h
===================================================================
--- trunk/Ohana/src/libdvo/include/dvo.h	(revision 37729)
+++ trunk/Ohana/src/libdvo/include/dvo.h	(revision 37807)
@@ -24,4 +24,5 @@
   DVO_FORMAT_PS1_DEV_3,
   DVO_FORMAT_PS1_REF,
+  DVO_FORMAT_PS1_SIM,
   DVO_FORMAT_PS1_V1,
   DVO_FORMAT_PS1_V2,
@@ -36,29 +37,4 @@
 
 typedef enum {DVO_CAT_OPEN_FAIL, DVO_CAT_OPEN_OK, DVO_CAT_OPEN_EMPTY} DVOCatalogOpenModes;
-
-typedef enum {
-  PROJ_NONE, // undefined
-  PROJ_ZEA, // zenithal
-  PROJ_ZPL, // zenithal
-  PROJ_ARC, // zenithal
-  PROJ_STG, // zenithal
-  PROJ_SIN, // zenithal
-  PROJ_TAN, // zenithal
-  PROJ_TNX, // zenithal
-  PROJ_DIS, // zenithal (TAN + polyterms)
-  PROJ_LIN, // cartesian
-  PROJ_PLY, // cartesian
-  PROJ_WRP, // cartesian
-  PROJ_AIT, // pseudocyl
-  PROJ_GLS, // pseudocyl
-  PROJ_PAR, // pseudocyl
-} OhanaProjection;
-
-typedef enum {
-  PROJ_MODE_NONE,
-  PROJ_MODE_CARTESIAN,
-  PROJ_MODE_ZENITHAL,
-  PROJ_MODE_PSEUDOCYL,
-} OhanaProjectionMode;
 
 // these are used as NAN for types of int values
@@ -79,17 +55,19 @@
 
 /* catalog values to be loaded */
-# define LOAD_NONE 	0x000
-# define LOAD_AVES 	0x001
-# define LOAD_MEAS 	0x002
-# define LOAD_MISS 	0x004
-# define LOAD_SECF 	0x008 
-# define SKIP_AVES 	0x010
-# define SKIP_MEAS 	0x020
-# define SKIP_MISS 	0x040
-# define SKIP_SECF 	0x080
-# define LOAD_LENSING 	0x100
-# define LOAD_LENSOBJ 	0x200
-# define SKIP_LENSING 	0x400
-# define SKIP_LENSOBJ 	0x800
+# define LOAD_NONE 	0x0000
+# define LOAD_AVES 	0x0001
+# define LOAD_MEAS 	0x0002
+# define LOAD_MISS 	0x0004
+# define LOAD_SECF 	0x0008 
+# define SKIP_AVES 	0x0010
+# define SKIP_MEAS 	0x0020
+# define SKIP_MISS 	0x0040
+# define SKIP_SECF 	0x0080
+# define LOAD_LENSING 	0x0100
+# define LOAD_LENSOBJ 	0x0200
+# define SKIP_LENSING 	0x0400
+# define SKIP_LENSOBJ 	0x0800
+# define LOAD_STARPAR 	0x1000
+# define SKIP_STARPAR 	0x2000
 
 /* photometry code types */
@@ -114,4 +92,5 @@
   ID_IMAGE_ASTROM_FEW     = 0x00000100,  /* currently too few measurements for astrometry */
   ID_IMAGE_PHOTOM_UBERCAL = 0x00000200,  /* externally-supplied photometry zero point from ubercal analysis */
+  ID_IMAGE_ASTROM_GMM     = 0x00000400,  /* image was fitted to positions corrected by the galaxy motion model */
 } DVOImageFlags;
 
@@ -136,4 +115,6 @@
   ID_MEAS_STACK_PRIMARY  = 0x00010000,  // this stack measurement is in the primary skycell
   ID_MEAS_STACK_PHOT_SRC = 0x00020000,  // this measurement supplied the stack photometry
+  ID_MEAS_ICRF_QSO       = 0x00040000,  // this measurement is an ICRF reference position
+  ID_MEAS_IMAGE_EPOCH    = 0x00080000,  // this measurement is registered to the image epoch (not tied to ref catalog epoch)
 } DVOMeasureFlags;
 
@@ -152,34 +133,40 @@
 */
 
+/** these names were previously used for Average flags in old (LONEOS-era) dvo versions
+  ID_BAD_OBJECT        = 0x00004000, // if all measurements are bad, set this bit
+  ID_MOVING            = 0x00008000, // is a moving object
+  ID_ROCK              = 0x0000a000, // 0x8000 + 0x2000
+  ID_GHOST             = 0x0000c001, // 0x8000 + 0x4000 + 0x0001
+  ID_TRAIL             = 0x0000c002, // 0x8000 + 0x4000 + 0x0002
+  ID_BLEED             = 0x0000c003, // 0x8000 + 0x4000 + 0x0003
+  ID_COSMIC            = 0x0000c004, // 0x8000 + 0x4000 + 0x0004
+**/
+
 /* Average.flags values -- these values are 32 bit (as of PS1_V1) */
 typedef enum {
-  ID_STAR_FEW       = 0x00000001, // used within relphot: skip star
-  ID_STAR_POOR      = 0x00000002, // used within relphot: skip star
-  ID_PROPER         = 0x00000400, // star with large proper motion
-  ID_TRANSIENT      = 0x00001000, // is this mutually exclusive with USNO?
-  ID_VARIABLE       = 0x00002000, // not currently set?
-  ID_ASTEROID       = 0x00002000, // identified with an asteroid
-  ID_BAD_OBJECT     = 0x00004000, // if all measurements are bad, set this bit
-  ID_MOVING         = 0x00008000, // is a moving object
-  ID_ROCK           = 0x0000a000, // 0x8000 + 0x2000
-  ID_GHOST          = 0x0000c001, // 0x8000 + 0x4000 + 0x0001
-  ID_TRAIL          = 0x0000c002, // 0x8000 + 0x4000 + 0x0002
-  ID_BLEED          = 0x0000c003, // 0x8000 + 0x4000 + 0x0003
-  ID_COSMIC         = 0x0000c004, // 0x8000 + 0x4000 + 0x0004
-  ID_STAR_FIT_AVE   = 0x00010000, // average position fitted
-  ID_STAR_FIT_PM    = 0x00020000, // proper motion fitted
-  ID_STAR_FIT_PAR   = 0x00040000, // parallax fitted
-  ID_STAR_USE_AVE   = 0x00080000, // average position used (not PM or PAR)
-  ID_STAR_USE_PM    = 0x00100000, // proper motion used (not AVE or PAR)
-  ID_STAR_USE_PAR   = 0x00200000, // parallax used (not AVE or PM)
-  ID_STAR_NO_ASTROM = 0x00400000, // mean astrometry could not be measured
-  ID_STAR_BAD_PM    = 0x00800000, // mean astrometry could not be measured
-  ID_OBJ_EXT        = 0x01000000, // extended in our data (eg, PS)
-  ID_OBJ_EXT_ALT    = 0x02000000, // extended in external data (eg, 2MASS)
-  ID_OBJ_GOOD       = 0x04000000, // good-quality measurement in our data (eg,PS)
-  ID_OBJ_GOOD_ALT   = 0x08000000, // good-quality measurement in  external data (eg, 2MASS)
-  ID_OBJ_GOOD_STACK = 0x10000000, // good-quality object in the stack (> 1 good stack)
+  ID_STAR_FEW          = 0x00000001, // used within relphot: skip star
+  ID_STAR_POOR         = 0x00000002, // used within relphot: skip star
+  ID_ICRF_QSO          = 0x00000004, // object IDed with known ICRF quasar (may have ICRF position measurement)
+  ID_OTHEF_QSO         = 0x00000008, // object IDed with known or suspected quasar, without ICRF reference data
+  ID_PROPER            = 0x00000010, // star with large proper motion
+  ID_TRANSIENT         = 0x00000020, // identified as a non-periodic (stationary) transient
+  ID_VARIABLE          = 0x00000040, // identified as a period variable
+  ID_ASTEROID          = 0x00000080, // identified with a known solar-system object (asteroid or other)
+  // bits 0x00000100 - 0x00008000 are currently unused
+  ID_STAR_FIT_AVE      = 0x00010000, // average position fitted
+  ID_STAR_FIT_PM       = 0x00020000, // proper motion fitted
+  ID_STAR_FIT_PAR      = 0x00040000, // parallax fitted
+  ID_STAR_USE_AVE      = 0x00080000, // average position used (not PM or PAR)
+  ID_STAR_USE_PM       = 0x00100000, // proper motion used (not AVE or PAR)
+  ID_STAR_USE_PAR      = 0x00200000, // parallax used (not AVE or PM)
+  ID_STAR_NO_ASTROM    = 0x00400000, // mean astrometry could not be measured
+  ID_STAR_BAD_PM       = 0x00800000, // mean astrometry could not be measured
+  ID_OBJ_EXT           = 0x01000000, // extended in our data (eg, PS)
+  ID_OBJ_EXT_ALT       = 0x02000000, // extended in external data (eg, 2MASS)
+  ID_OBJ_GOOD          = 0x04000000, // good-quality measurement in our data (eg,PS)
+  ID_OBJ_GOOD_ALT      = 0x08000000, // good-quality measurement in  external data (eg, 2MASS)
+  ID_OBJ_GOOD_STACK    = 0x10000000, // good-quality object in the stack (> 1 good stack)
   ID_OBJ_SUSPECT_STACK = 0x20000000, // suspect object in the stack (> 1 good or suspect stack, < 2 good)
-  ID_OBJ_BAD_STACK  = 0x40000000, // good-quality object in the stack (> 1 good stack)
+  ID_OBJ_BAD_STACK     = 0x40000000, // good-quality object in the stack (> 1 good stack)
 } DVOAverageFlags;
 
@@ -202,4 +189,22 @@
 } DVOSecfiltFlags;
 
+/* definitions for parallel dvo host information 
+   XXX : need better names (safer namespace)
+*/
+
+typedef enum {
+  DATA_ON_TGT  = 0x01,
+  DATA_ON_BCK  = 0x02,
+  DATA_USE_BCK = 0x04,
+
+  DATA_COPY_FAILURE = 0x80,
+} SkyTableDataFlags;
+
+typedef enum {
+  HOST_STDIN = 0,
+  HOST_STDOUT = 1,
+  HOST_STDERR = 2,
+} HostInfoIOfd;
+
 /*** general dvo structures (internal use only / not IO) ***/
 
@@ -253,22 +258,4 @@
 } FlatCorrectionTable;
 
-/* definitions for parallel dvo host information 
-   XXX : need better names (safer namespace)
-*/
-
-typedef enum {
-  DATA_ON_TGT  = 0x01,
-  DATA_ON_BCK  = 0x02,
-  DATA_USE_BCK = 0x04,
-
-  DATA_COPY_FAILURE = 0x80,
-} SkyTableDataFlags;
-
-typedef enum {
-  HOST_STDIN = 0,
-  HOST_STDOUT = 1,
-  HOST_STDERR = 2,
-} HostInfoIOfd;
-
 typedef struct {
   char *hostname;	      // name of remote machine
@@ -289,4 +276,9 @@
 } HostTable;
 
+typedef struct {
+  int Nhosts;
+  HostInfo **hosts;
+} HostTableGroup;
+
 // A RegionHost processes data for some region in parallel with other regions
 typedef struct RegionHostInfo {
@@ -314,4 +306,6 @@
   Image *image;
   off_t *imseq;
+
+  AstromOffsetTable *astromTable;
 
   int *neighbors;	      // list of neighbor index values
@@ -444,4 +438,6 @@
   double         R;
   double         D;
+  float          RoffGAL;
+  float          DoffGAL;
   float          M;
   float          Mcal;
@@ -645,5 +641,5 @@
   int              lensobjOffset;        // offset to mean lensing data
   int              extendOffset;         // offset to extended object entry
-  int              paramsOffset;         // offset to stellar parameter data
+  int              starparOffset;        // offset to stellar parameter data
   float            refColorBlue;         // color of astrometry ref stars
   float            refColorRed;          // color of astrometry ref stars
@@ -679,9 +675,10 @@
   Lensing *lensing;
   Lensobj *lensobj;
+  StarPar *starpar;
 
   int Nsecfilt;  /* number of secfilt entries for each average entry */
-  off_t Naverage,   Nmeasure,   Nmissing,   Nlensing,      Nlensobj,      Nsecf_mem;  /* current number of each component in memory */
-  off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nlensing_disk, Nlensobj_disk, Nsecf_disk; /* current number of each component on disk */
-  off_t Naves_off,  Nmeas_off,  Nmiss_off,  Nlensing_off,  Nlensobj_off,  Nsecf_off;  /* index of first loaded data value */
+  off_t Naverage,   Nmeasure,   Nmissing,   Nlensing,      Nlensobj,      Nstarpar,      Nsecf_mem;  /* current number of each component in memory */
+  off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nlensing_disk, Nlensobj_disk, Nstarpar_disk, Nsecf_disk; /* current number of each component on disk */
+  off_t Naves_off,  Nmeas_off,  Nmiss_off,  Nlensing_off,  Nlensobj_off,  Nstarpar_off,  Nsecf_off;  /* index of first loaded data value */
 
   // note that we use these for the full-sky relphot analysis
@@ -704,4 +701,5 @@
   struct Catalog *lensing_catalog;		/* lensing catalog data (split) */
   struct Catalog *lensobj_catalog;		/* lensobj catalog data (split) */
+  struct Catalog *starpar_catalog;		/* starpar catalog data (split) */
 
   unsigned int objID;
@@ -739,21 +737,4 @@
 int   gfits_db_close               PROTO((FITS_DB *db));
 int   gfits_db_free                PROTO((FITS_DB *db));
-
-/* in coords.c, using libautocode/def/coords.d */
-int  XY_to_LM (double *L, double *M, double x,  double y,   Coords *coords);
-int  LM_to_XY (double *x,  double *y,   double L, double M, Coords *coords);
-int  RD_to_LM (double *L, double *M, double ra,  double dec,   Coords *coords);
-int  LM_to_RD (double *ra, double *dec,   double L, double M, Coords *coords);
-int  XY_to_RD (double *ra, double *dec, double x,  double y,   Coords *coords);
-int  RD_to_XY (double *x,  double *y,   double ra, double dec, Coords *coords);
-int  fXY_to_RD (float *ra, float *dec, double x,  double y,   Coords *coords);
-int  fRD_to_XY (float *x,  float *y,   double ra, double dec, Coords *coords);
-int  GetCoords (Coords *coords, Header *header);
-int  PutCoords (Coords *coords, Header *header);
-void RegisterMosaic (Coords *coords);
-void coords_precess (double *ra, double *dec, double in_epoch, double out_epoch);
-OhanaProjection GetProjection (char *ctype);
-int SetProjection (char *ctype, OhanaProjection proj);
-OhanaProjectionMode GetProjectionMode (OhanaProjection proj);
 
 char *libdvo_version (void);
@@ -913,4 +894,5 @@
 Lensing *FtableToLensing (FTable *ftable, off_t *Nlensing, char *format);
 Lensobj *FtableToLensobj (FTable *ftable, off_t *Nlensobj, char *format);
+StarPar *FtableToStarPar (FTable *ftable, off_t *Nstarpar, char *format);
 int      FtableToImage   (FTable *ftable, Header *theader, char *format);
 
@@ -920,4 +902,5 @@
 int LensingToFtable (FTable *ftable, Lensing *lensing, off_t Nlensing, char format);
 int LensobjToFtable (FTable *ftable, Lensobj *lensobj, off_t Nlensobj, char format);
+int StarParToFtable (FTable *ftable, StarPar *starpar, off_t Nstarpar, char format);
 int ImageToFtable (FTable *ftable, Header *theader, char format);
 int ImageToVtable (VTable *vtable, Header *theader, char format);
@@ -936,4 +919,5 @@
 # include "ps1_v5_defs.h"
 # include "ps1_ref_defs.h"
+# include "ps1_sim_defs.h"
 
 /*** DVO image db I/O Functions ***/
@@ -950,4 +934,8 @@
 void dvo_image_create (FITS_DB *db, double ZeroPoint);
 
+int gfits_table_set_Image (FTable *ftable);
+int gfits_table_mkheader_Image (Header *header);
+Image *gfits_table_get_Image (FTable *ftable, off_t *Ndata, char *swapped);
+
 /* flatcorr APIs */
 FlatCorrectionTable *FlatCorrectionLoad (char *filename, int VERBOSE);
@@ -963,4 +951,5 @@
 SkyTable  *SkyTableLoadOptimal 	   PROTO((char *catdir, char *SKYFILE, char *GSCFILE, int readwrite, int depth, int VERBOSE));
 int        SkyTableSetDepth    	   PROTO((SkyTable *sky, int depth));
+SkyList   *SkyRegionByIndex        PROTO((SkyTable *table, int index));
 SkyList   *SkyRegionByCPT          PROTO((SkyTable *table, char *filename));
 SkyList   *SkyRegionByPoint    	   PROTO((SkyTable *table, int depth, double ra, double dec));
@@ -1009,4 +998,9 @@
 int HostTableTestHost (SkyRegion *region, int hostID);
 
+void InitHost (HostInfo *host);
+
+HostTableGroup *HostTableGroups (HostTable *table, int *ngroups);
+int HostTableGroupWaitJobsGetIO (HostTableGroup *table, char *file, int lineno, int VERBOSE);
+
 // functions to support tiny versions of Average and Measure
 void CopyAverageToTiny (AverageTiny *averageT, Average *average);
@@ -1042,4 +1036,5 @@
 void dvo_lensing_init (Lensing *lensing);
 void dvo_lensobj_init (Lensobj *lensobj, int toZero);
+void dvo_starpar_init (StarPar *starpar);
 
 void InitRegionHosts (RegionHostInfo *hosts, int Nhosts, int NHOSTS);
@@ -1051,3 +1046,40 @@
 int RegionHostFindNeighbors (RegionHostTable *table, int Nhost);
 
+// 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 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);
+int GalaxyMotionModel_radians (double *uL_gal, double *uB_gal, double Lrad, double Brad);
+int GalaxyMotionModel (double *uL_gal, double *uB_gal, double L, double B);
+int InitGalaxyModel (char *version);
+
+# define LENSFIELD(NAME) float LensValue_##NAME (PhotCode *code, Lensobj *lensobj);
+
+LENSFIELD(X11_sm_obj)
+LENSFIELD(X12_sm_obj)
+LENSFIELD(X22_sm_obj)
+LENSFIELD(E1_sm_obj)
+LENSFIELD(E2_sm_obj)
+
+LENSFIELD(X11_sh_obj)
+LENSFIELD(X12_sh_obj)
+LENSFIELD(X22_sh_obj)
+LENSFIELD(E1_sh_obj)
+LENSFIELD(E2_sh_obj)
+
+LENSFIELD(X11_sm_psf)
+LENSFIELD(X12_sm_psf)
+LENSFIELD(X22_sm_psf)
+LENSFIELD(E1_sm_psf)
+LENSFIELD(E2_sm_psf)
+
+LENSFIELD(X11_sh_psf)
+LENSFIELD(X12_sh_psf)
+LENSFIELD(X22_sh_psf)
+LENSFIELD(E1_sh_psf)
+LENSFIELD(E2_sh_psf)
+
+# undef LENSFIELD
+
 # endif // DVO_H
