Index: trunk/Ohana/src/libdvo/include/dvo.h
===================================================================
--- trunk/Ohana/src/libdvo/include/dvo.h	(revision 31663)
+++ trunk/Ohana/src/libdvo/include/dvo.h	(revision 33649)
@@ -26,4 +26,5 @@
   DVO_FORMAT_PS1_V1,
   DVO_FORMAT_PS1_V2,
+  DVO_FORMAT_PS1_V3,
 } DVOTableFormat;
 
@@ -95,34 +96,35 @@
 /* Image.code values -- these values are 32 bit (as of PS1_V1) */
 typedef enum {
-  ID_IMAGE_NEW          = 0x00000000,  /* no calibrations yet attempted */
-  ID_IMAGE_PHOTOM_NOCAL = 0x00000001,  /* user-set value used within relphot: ignore */
-  ID_IMAGE_PHOTOM_POOR  = 0x00000002,  /* relphot says image is bad (dMcal > limit) */
-  ID_IMAGE_PHOTOM_SKIP  = 0x00000004,  /* user-set value: assert that this image has bad photometry */
-  ID_IMAGE_PHOTOM_FEW   = 0x00000008,  /* currently too few measurements for photometry */
-  ID_IMAGE_ASTROM_NOCAL = 0x00000010,  /* user-set value used within relastro: ignore */
-  ID_IMAGE_ASTROM_POOR  = 0x00000020,  /* relastro says image is bad (dR,dD > limit) */
-  ID_IMAGE_ASTROM_FAIL  = 0x00000040,  /* relastro fit diverged, fit not applied */
-  ID_IMAGE_ASTROM_SKIP  = 0x00000080,  /* user-set value: assert that this image has bad astrometry */
-  ID_IMAGE_ASTROM_FEW   = 0x00000100,  /* currently too few measurements for astrometry */
+  ID_IMAGE_NEW            = 0x00000000,  /* no calibrations yet attempted */
+  ID_IMAGE_PHOTOM_NOCAL   = 0x00000001,  /* user-set value used within relphot: ignore */
+  ID_IMAGE_PHOTOM_POOR    = 0x00000002,  /* relphot says image is bad (dMcal > limit) */
+  ID_IMAGE_PHOTOM_SKIP    = 0x00000004,  /* user-set value: assert that this image has bad photometry */
+  ID_IMAGE_PHOTOM_FEW     = 0x00000008,  /* currently too few measurements for photometry */
+  ID_IMAGE_ASTROM_NOCAL   = 0x00000010,  /* user-set value used within relastro: ignore */
+  ID_IMAGE_ASTROM_POOR    = 0x00000020,  /* relastro says image is bad (dR,dD > limit) */
+  ID_IMAGE_ASTROM_FAIL    = 0x00000040,  /* relastro fit diverged, fit not applied */
+  ID_IMAGE_ASTROM_SKIP    = 0x00000080,  /* user-set value: assert that this image has bad astrometry */
+  ID_IMAGE_ASTROM_FEW     = 0x00000100,  /* currently too few measurements for astrometry */
+  ID_IMAGE_PHOTOM_UBERCAL = 0x00000200,  /* externally-supplied photometry zero point from ubercal analysis */
 } DVOImageFlags;
 
 /* Measure.flags values -- these values are 32 bit (as of PS1_V1) */
 typedef enum {
-  ID_MEAS_NOCAL        = 0x00000001,  // detection ignored for this analysis (photcode, time range) -- internal only 
-  ID_MEAS_POOR_PHOTOM  = 0x00000002,  // detection is photometry outlier					     	  
-  ID_MEAS_SKIP_PHOTOM  = 0x00000004,  // detection was ignored for photometry measurement			     	  
-  ID_MEAS_AREA         = 0x00000008,  // detection near image edge						     
-  ID_MEAS_POOR_ASTROM  = 0x00000010,  // detection is astrometry outlier					     	  
-  ID_MEAS_SKIP_ASTROM  = 0x00000020,  // detection was ignored for astrometry measurement			     	  
-  ID_MEAS_USED_OBJ     = 0x00000040,  // detection was used during opdate objects				     
-  ID_MEAS_USED_CHIP    = 0x00000080,  // detection was used during update chips					     
-  ID_MEAS_BLEND_MEAS   = 0x00000100,  // detection is within radius of multiple objects				     
-  ID_MEAS_BLEND_OBJ    = 0x00000200,  // multiple detections within radius of object				     
-  ID_MEAS_UNDEF_3      = 0x00000400,  // unused									     
-  ID_MEAS_UNDEF_4      = 0x00000800,  // unused									     
-  ID_MEAS_BLEND_MEAS_X = 0x00001000,  // detection is within radius of multiple objects across catalogs		     
-  ID_MEAS_ARTIFACT     = 0x00002000,  // detection is thought to be non-astronomical				     
-  ID_MEAS_UNDEF_5      = 0x00004000,  // unused									     
-  ID_MEAS_UNDEF_6      = 0x00008000,  // unused									     
+  ID_MEAS_NOCAL          = 0x00000001,  // detection ignored for this analysis (photcode, time range) -- internal only 
+  ID_MEAS_POOR_PHOTOM    = 0x00000002,  // detection is photometry outlier					     	  
+  ID_MEAS_SKIP_PHOTOM    = 0x00000004,  // detection was ignored for photometry measurement			     	  
+  ID_MEAS_AREA           = 0x00000008,  // detection near image edge						     
+  ID_MEAS_POOR_ASTROM    = 0x00000010,  // detection is astrometry outlier					     	  
+  ID_MEAS_SKIP_ASTROM    = 0x00000020,  // detection was ignored for astrometry measurement			     	  
+  ID_MEAS_USED_OBJ       = 0x00000040,  // detection was used during update objects  
+  ID_MEAS_USED_CHIP      = 0x00000080,  // detection was used during update chips (XXX this probably does not make it into the db)
+  ID_MEAS_BLEND_MEAS     = 0x00000100,  // detection is within radius of multiple objects 
+  ID_MEAS_BLEND_OBJ      = 0x00000200,  // multiple detections within radius of object 
+  ID_MEAS_UNDEF_3        = 0x00000400,  // unused 
+  ID_MEAS_UNDEF_4        = 0x00000800,  // unused 
+  ID_MEAS_BLEND_MEAS_X   = 0x00001000,  // detection is within radius of multiple objects across catalogs		     
+  ID_MEAS_ARTIFACT       = 0x00002000,  // detection is thought to be non-astronomical				     
+  ID_MEAS_UNDEF_5        = 0x00004000,  // unused 
+  ID_MEAS_PHOTOM_UBERCAL = 0x00008000,  // externally-supplied zero point from ubercal analysis
 } DVOMeasureFlags;
 
@@ -141,5 +143,5 @@
 */
 
-/* Average.code values -- these values are 32 bit (as of PS1_V1) */
+/* Average.flags values -- these values are 32 bit (as of PS1_V1) */
 typedef enum {
   ID_STAR_FEW     = 0x00000001, // used within relphot: skip star
@@ -168,4 +170,18 @@
 } DVOAverageFlags;
 
+/* Secfilt.flags values -- these values are 32 bit (as of PS1_V1) */
+typedef enum {
+  ID_SECF_STAR_FEW    = 0x00000001, // used within relphot: skip star
+  ID_SECF_STAR_POOR   = 0x00000002, // used within relphot: skip star
+  ID_SECF_USE_SYNTH   = 0x00000004, // synthetic photometry used in average measurement
+  ID_SECF_USE_UBERCAL = 0x00000008, // synthetic photometry used in average measurement
+  ID_PHOTOM_PASS_0    = 0x00000100, // average magnitude calculated in 0th pass
+  ID_PHOTOM_PASS_1    = 0x00000200, // average magnitude calculated in 1th pass
+  ID_PHOTOM_PASS_2    = 0x00000400, // average magnitude calculated in 2th pass
+  ID_PHOTOM_PASS_3    = 0x00000800, // average magnitude calculated in 3th pass
+  ID_PHOTOM_PASS_4    = 0x00001000, // average magnitude calculated in 4th pass
+  ID_SECF_OBJ_EXT     = 0x01000000, // extended in this band
+} DVOSecfiltFlags;
+
 /*** general dvo structures (internal use only / not IO) ***/
 
@@ -196,4 +212,5 @@
   char **filename;
   SkyRegion *regions;
+  char hosts[80];
 } SkyTable;
 
@@ -203,5 +220,54 @@
   char **filename;
   SkyRegion **regions;
+  char hosts[80];
 } SkyList;
+
+typedef struct {
+  off_t Nimage;
+  FlatCorrectionImage *image;
+  off_t Ncorr;
+  int *IDtoSeq;
+  FlatCorrection *corr;
+  float ***offset; // the correction images represented as a set of arrays (same sequence as *image)
+  int Nseason;
+  e_time *tstart;
+  e_time *tstop;
+} 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
+  char *pathname;	      // name of directory for this machine's data
+  char *results;	      // name of file machine's result data
+  int hostID;		      // remove machine ID in SkyTable
+  int stdio[3]; 	      // fd's for communication with the remote host
+  int pid;		      // remote process ID
+  int status;		      // job exit status
+  IOBuffer stdout;
+  IOBuffer stderr;
+} HostInfo;
+
+typedef struct {
+  int Nhosts;
+  HostInfo *hosts;
+  unsigned short *index;
+} HostTable;
 
 // special-case function:
@@ -218,4 +284,19 @@
 } PhotCodeData;
 
+typedef enum {
+  DVO_TV_MEASURE = 0x01,
+  DVO_TV_AVERAGE = 0x02,
+} DVOTinyValueMode;
+
+// XXX DROP? // a reduced-subset structure for relastro
+// XXX DROP? typedef struct {
+// XXX DROP?   double         R;
+// XXX DROP?   double         D;
+// XXX DROP?   unsigned short Nmeasure;
+// XXX DROP?   int            measureOffset;
+// XXX DROP?   uint32_t       flags;
+// XXX DROP?   int            catID;
+// XXX DROP? } AverageTinyAstro;
+
 // a reduced-subset structure for relphot
 typedef struct {
@@ -225,7 +306,8 @@
   int            measureOffset;
   uint32_t       flags;
+  int            catID;
 } AverageTiny;
 
-// a reduced-subset structure for relphot
+// a reduced-subset structure for relphot & relastro
 typedef struct {
   float          dR;
@@ -242,5 +324,10 @@
   unsigned int   imageID;
   unsigned int   dbFlags;
+  unsigned int   photFlags;
+  int            catID; // unsigned int?
   unsigned short photcode;
+  short          dXccd;
+  short          dYccd;
+  short          dRsys;
 } MeasureTiny;
 
@@ -383,9 +470,9 @@
 int PhotColorTiny (AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, int c1, int c2, double *color);
 
-
 PhotCodeData *GetPhotcodeTable (void);
 void SetPhotcodeTable (PhotCodeData *);
 
 int *GetSecFiltMap(PhotCodeData *ouput, PhotCodeData* input);
+PhotCode **ParsePhotcodeList (char *rawlist, int *nphotcodes, int needAve);
 
 int LoadPhotcodes (char *catdir_file, char *master_file, int readwrite);
@@ -450,4 +537,6 @@
 int WriteRawSecFilt (FILE *f, SecFilt *secfilt, off_t Nsecfilt, char format);
 
+DVOTableFormat FtableGetFormat (FTable *ftable);
+
 Average *FtableToAverage (FTable *ftable, off_t *Naverage, char *format, SecFilt **primary);
 Measure *FtableToMeasure (FTable *ftable, off_t *Nmeasure, char *format);
@@ -470,4 +559,5 @@
 # include "ps1_v1_defs.h"
 # include "ps1_v2_defs.h"
+# include "ps1_v3_defs.h"
 # include "ps1_ref_defs.h"
 
@@ -484,7 +574,14 @@
 void dvo_image_create (FITS_DB *db, double ZeroPoint);
 
+/* flatcorr APIs */
+FlatCorrectionTable *FlatCorrectionLoad (char *filename, int VERBOSE);
+int FlatCorrectionInternal(FlatCorrectionTable *flatcorrTable);
+int FlatCorrectionSave (FlatCorrectionTable *flatcorrTable, char *filename);
+float FlatCorrectionOffset (FlatCorrectionTable *flatcorr, int ID, int X, int Y);
+
 /* skyregion APIs */
 int        SkyTableSave        	   PROTO((SkyTable *table, char *filename));
 SkyTable  *SkyTableLoad        	   PROTO((char *filename, int VERBOSE));
+char      *SkyTableFilename        PROTO((char *catdir));
 SkyTable  *SkyTableFromGSC     	   PROTO((char *filename, int depth, int VERBOSE));
 SkyTable  *SkyTableLoadOptimal 	   PROTO((char *catdir, char *SKYFILE, char *GSCFILE, int readwrite, int depth, int VERBOSE));
@@ -528,3 +625,16 @@
 #endif
 
-# endif
+// functions for parallel DVO
+HostTable    *HostTableLoad (char *catdir, char *rootname);
+int HostTableWaitJobs (HostTable *table, char *file, int lineno);
+int HostTableWaitJobsGetIO (HostTable *table, char *file, int lineno, int VERBOSE);
+int HostTableTestHost (SkyRegion *region, int hostID);
+
+// functions to support tiny versions of Average and Measure
+void CopyAverageToTiny (AverageTiny *averageT, Average *average);
+void CopyMeasureToTiny (MeasureTiny *measureT, Measure *measure);
+int populate_tiny_values (Catalog *catalog, DVOTinyValueMode mode);
+int free_tiny_values (Catalog *catalog);
+
+# endif // DVO_H
+
