Index: trunk/Ohana/src/relastro/include/relastro.h
===================================================================
--- trunk/Ohana/src/relastro/include/relastro.h	(revision 32740)
+++ trunk/Ohana/src/relastro/include/relastro.h	(revision 33652)
@@ -4,4 +4,9 @@
 # include <signal.h>
 # include <assert.h>
+# include <pthread.h>
+
+// choose off_t or int depending on full-scale relphot analysis resources
+// # define IDX_T off_t
+# define IDX_T int 
 
 typedef enum {
@@ -15,5 +20,34 @@
 typedef enum {FIT_NONE, FIT_AVERAGE, FIT_PM_ONLY, FIT_PAR_ONLY, FIT_PM_AND_PAR} FitMode;
 
-typedef enum {TARGET_NONE, TARGET_OBJECTS, TARGET_SIMPLE, TARGET_CHIPS, TARGET_MOSAICS, TARGET_HIGH_SPEED, TARGET_MERGE_SOURCE} FitTarget;
+typedef enum {TARGET_NONE, TARGET_SIMPLE, TARGET_CHIPS, TARGET_MOSAICS, TARGET_HIGH_SPEED, TARGET_MERGE_SOURCE, TARGET_UPDATE_OBJECTS, TARGET_UPDATE_OFFSETS, TARGET_LOAD_OBJECTS} FitTarget;
+
+typedef enum {
+  MARK_MEAS_DEFAULT  = 0x0000,
+  MARK_TOO_FEW_MEAS  = 0x0001,
+  MARK_NAN_POS_ERROR = 0x0002,
+  MARK_NAN_MAG_ERROR = 0x0004,
+  MARK_BIG_MAG_ERROR = 0x0008,
+  MARK_BIG_OFFSET    = 0x0010,
+} MeasurementMask;
+
+typedef struct {
+  Average     *average;	      // array of (minimal) average data
+  MeasureTiny *measure;	      // array of (minimal) measure data 
+  SecFilt     *secfilt;	      // array of secfilt data (matched to average by Nsecfilt)
+  off_t       Naverage;
+  off_t       Nmeasure;
+} BrightCatalog;
+
+typedef struct {
+  Catalog *catalog;	      // array of catalogs generated
+  int NCATALOG;		      // number of catalogs allocated
+  int Ncatalog;		      // number of catalogs generated
+  int Nsecfilt;		      // number of catalogs generated
+  off_t *NAVERAGE; 	      // allocated Averages per catalog
+  off_t *NMEASURE;	      // allocated Measures per catalog
+  int   *index;		      // lookup table catID -> catalog[i]
+  int   *catIDs;	      // lookup table catID <- catalog[i]
+  int    maxID;		      // max catID value to date
+} CatalogSplitter;
 
 typedef struct {
@@ -86,12 +120,17 @@
 
 /* global variables set in parameter file */
-char   ImageCat[256];
-char   GSCFILE[256];
-char   CATDIR[256];
+# define MAX_PATH_LENGTH 1024
+char   ImageCat[MAX_PATH_LENGTH];
+char   GSCFILE[MAX_PATH_LENGTH];
+char   CATDIR[MAX_PATH_LENGTH];
 char   *HIGH_SPEED_DIR;
 char   CATMODE[16];    /* raw, mef, split, mysql */
 char   CATFORMAT[16];  /* internal, elixir, loneos, panstarrs */
-char   SKY_TABLE[256];
+char   SKY_TABLE[MAX_PATH_LENGTH];
 int    SKY_DEPTH;  /** XXX EAM : depth of catalog tables, fix usage */
+
+int          HOST_ID;
+char        *HOSTDIR;
+char        *BCATALOG;
 
 unsigned int OBJ_ID_SRC;
@@ -110,4 +149,10 @@
 double RADIUS; // match radius for high-speed objects
 
+int    PARALLEL;
+int    PARALLEL_MANUAL;
+int    PARALLEL_SERIAL;
+
+int    PARALLEL_OUTPUT;
+
 int    VERBOSE;
 int    VERBOSE2;
@@ -115,4 +160,5 @@
 int    RESET;
 int    NLOOP;
+int    NTHREADS;
 int    UPDATE;
 int    PLOTSTUFF;
@@ -123,4 +169,5 @@
 int    PM_TOOFEW;
 double PM_DT_MIN;
+double PAR_FACTOR_MIN;
 int    PLOTDELAY;
 int    CHIPORDER;
@@ -128,7 +175,4 @@
 int MaxDensityUse;
 double MaxDensityValue;
-
-int UserCatalog;
-double UserCatalogRA, UserCatalogDEC;
 
 char          *PHOTCODE_KEEP_LIST, *PHOTCODE_SKIP_LIST;
@@ -142,12 +186,9 @@
 SkyRegionSelection SELECTION;
 
-int AreaSelect;
-double AreaXmin, AreaXmax, AreaYmin, AreaYmax;
-
-int ImagSelect, ImagMin, ImagMax;
+int ImagSelect;
+double ImagMin, ImagMax;
 
 double  PlotMmin, PlotMmax, PlotdMmin, PlotdMmax;
 
-int DophotSelect, DophotValue;
 int PhotFlagSelect, PhotFlagPoor, PhotFlagBad;
 
@@ -181,6 +222,7 @@
 char         *GetPhotnamebyCode   PROTO((PhotCodeData *photcodes, int code));
 void          InterpolateGrid     PROTO((float *buffer, int Nx, int Ny, Coords *ccd, Coords *gcoords));
-off_t          *SelectRefMosaic     PROTO((Mosaic **refmosaic, off_t *Nimage));
+off_t        *SelectRefMosaic     PROTO((Mosaic **refmosaic, off_t *Nimage));
 int           args                PROTO((int argc, char **argv));
+int           args_client         PROTO((int argc, char **argv));
 int           bcatalog            PROTO((Catalog *subcatalog, Catalog *catalog));
 void          clean_images        PROTO((void));
@@ -226,8 +268,9 @@
 void          initMrel            PROTO((Catalog *catalog, int Ncatalog));
 void          initialize          PROTO((int argc, char **argv));
+void          initialize_client   PROTO((int argc, char **argv));
 void          initstats           PROTO((char *mode));
 int           liststats           PROTO((double *value, double *dvalue, int N, StatType *stats));
-Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog, int subselect));
-SkyList      *load_images         PROTO((FITS_DB *db, SkyRegion *region));
+Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog, int subselect, int hostID, char *hostpath));
+int           load_images         PROTO((FITS_DB *db, SkyList *skylist));
 Image        *select_images       PROTO((SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage));
 
@@ -314,4 +357,5 @@
 void FlagOutliers(Catalog *catalog);
 int MeasFilterTest(Measure *measure, int applySigmaLim);
+int MeasFilterTestTiny(MeasureTiny *measure, int applySigmaLim);
 
 int sun_ecliptic (double jd, double *lambda, double *beta, double *epsilon, double *Radius);
@@ -333,12 +377,16 @@
 Mosaic *getMosaicForImage (off_t im);
 
-double getMeanR (Measure *measure, Average *average, SecFilt *secfilt);
-double getMeanD (Measure *measure, Average *average, SecFilt *secfilt);
-int setMeanR (double ra_fit, Measure *measure, Average *average, SecFilt *secfilt);
-int setMeanD (double dec_fit, Measure *measure, Average *average, SecFilt *secfilt);
+double getMeanR (MeasureTiny *measure, Average *average, SecFilt *secfilt);
+double getMeanD (MeasureTiny *measure, Average *average, SecFilt *secfilt);
+int setMeanR (double ra_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt);
+int setMeanD (double dec_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt);
+int setMeanR_Big (double ra_fit, Measure *measure, Average *average, SecFilt *secfilt);
+int setMeanD_Big (double dec_fit, Measure *measure, Average *average, SecFilt *secfilt);
 
 float GetAstromError (Measure *measure, int mode);
-int relastro_objects (void);
-int UpdateObjectOffsets (SkyList *skylist);
+float GetAstromErrorTiny (MeasureTiny *measure, int mode);
+int relastro_objects (SkyList *skylist, int hostID, char *hostpath);
+int relastro_images (SkyList *skylist);
+int UpdateObjectOffsets (SkyList *skylist, int hostID, char *hostpath);
 
 int relastroVisualPlotChipFit(StarData *raw, StarData *ref, double dRmax, int numObj);
@@ -361,5 +409,5 @@
 void resetImageRaw (Catalog *catalog, int Ncatalog, off_t im);
 
-int high_speed_catalogs ();
+int high_speed_catalogs (SkyTable *sky, SkyList *skylist, int hostID, char *hostpath);
 int high_speed_objects (SkyRegion *region, Catalog *catalog);
 int MeasMatchesPhotcode(Measure *measure, PhotCode **photcodeSet, int Nset);
@@ -369,7 +417,9 @@
 int createStarMapPoints();
 int checkStarMap(int N);
+int createStarMap (Catalog *catalog, int Ncatalog);
 
 int GetScatterRawRef(float *dLsig, float *dMsig, float *dRsig, int *nKeep, StarData *raw, StarData *ref, int Nstars, float SigmaLimit);
-int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog);
+int LimitDensityCatalog_ByNmeasure (Catalog *subcatalog, Catalog *catalog);
+int LimitDensityCatalog_RandomSample (Catalog *subcatalog, Catalog *catalog);
 
 int initializeConstraints();
@@ -378,4 +428,13 @@
 void setupAreaSelection(SkyRegion *region);
 
-int relastro_merge_source ();
+int relastro_merge_source (SkyTable *sky);
 void resort_catalog (Catalog *catalog);
+
+BrightCatalog *BrightCatalogLoad(char *filename);
+int BrightCatalogSave(char *filename, BrightCatalog *catalog);
+BrightCatalog *BrightCatalogMerge (Catalog *catalog, int Ncatalog);
+CatalogSplitter *BrightCatalogSplitInit (int Nsecfilt);
+int BrightCatalogSplit (CatalogSplitter *catalogs, BrightCatalog *bcatalog);
+int BrightCatalogSplitFree (CatalogSplitter *catalogs);
+
+PhotCode **ParsePhotcodeList (char *rawlist, int *nphotcodes, int needAve);
