Index: trunk/Ohana/src/relphot/include/relphot.h
===================================================================
--- trunk/Ohana/src/relphot/include/relphot.h	(revision 41428)
+++ trunk/Ohana/src/relphot/include/relphot.h	(revision 41453)
@@ -91,6 +91,4 @@
 
 typedef struct {
-  unsigned int start;
-  unsigned int stop;
   short photcode;
   float McalPSF;
@@ -110,9 +108,16 @@
   off_t NMEASURE;
   off_t *measure;
-
-  off_t Ncatalog; // XX not needed
-  off_t NCATALOG; // XX not needed
   off_t *catalog;
+
+  void *parent;
 } TGroup; 
+
+// we have an array of TGroup times, each pointing to N sets of data values
+typedef struct {
+  unsigned int start;
+  unsigned int stop;
+  TGroup *byCode; // each of these contains the collection of images for the time and photcode
+  int      nCode;
+} TGTimes;
 
 typedef enum {
@@ -163,4 +168,53 @@
 
 } StatDataSet;
+
+typedef struct {
+  double *xVector;	      // complete list of values in independent variable (optional)
+  double *yVector;	      // complete list of values available
+  double *dyVector;	      // complete list of errors available
+} FitDataType;
+  
+// this structure carries the data and pre-allocated arrays for
+// 1D fitting with arbitrary order for data with external weights,
+// optional priors, irls iterations, and bootstrap resampling
+typedef struct {
+  int     order;	      // order of fit (e.g., y = C0 + C1*x has order = 1)
+  int     nterm;	      // number of fitted parameters (order + 1)
+  int     mterm;	      // number of summations needed for OLS (2*order + 1)
+
+  int     Nlist;	      // total number of measurements in list (may be more than the number to use)
+  int     Nbootstrap;	      // number of bootstrap iterations
+
+  // input data & parameters: 
+  FitDataType *alldata;	      // full data set
+
+  double *bPriorValue; 	      // prior value
+  double *bPriorSigma;	      // prior sigma
+
+  // internal / temporary arrays:
+  FitDataType *keepdata;      // unclipped data for bootstrap analysis
+  FitDataType *sample;	      // sample for a bootstrap iteration
+
+  double *yOffVector;	      // difference between yFit and yObs
+
+  double *tmpVector;	      // internal copy of values to use in, e.g., calculation of median
+  double *wtIRLS; 	      // IRLS weights (distance from model value weighted by standard error)
+
+  double **cArray;
+  double  *sumVector;	      // pre-allocated to mterm (2*order + 1)
+
+  double **bArray;
+  double **bSaveArray;
+  double **bBootArray;	      // values generated by the bootstrap resampling 
+
+  // output results:
+  double *bSigma;	      // 1 sigma range of parameters
+
+  double  min;		      // min of bSigma[0] values
+  double  max;		      // max of bSigma[0] values
+  double  sigma;	      // (sample) standard deviation of bSigma[0] values
+  double  chisq;	      // chisq of fit (unmasked values only)
+  int     Nmeas;	      // number of unmasked values used in fit
+} FitDataSet;
 
 typedef struct {
@@ -311,4 +365,6 @@
 double IMAGE_SCATTER;
 double IMAGE_OFFSET;
+double NIGHT_SCATTER;
+double NIGHT_OFFSET;
 double STAR_SCATTER;
 double STAR_CHISQ;
@@ -497,4 +553,12 @@
 int           liststats_irls      PROTO((StatDataSet *dataset, int Npoints, StatType *stats));
 int           liststats_fit1d     PROTO((double *value, double *err, double *x, int Npts, StatType *stats, double *dk));
+double        weight_cauchy       PROTO((double x));
+double        VectorFractionInterpolate PROTO((double *values, float fraction, int Npoints));
+
+// fit1d_irls:
+int           fit1d_irls          PROTO((FitDataSet *dataset, int Npoints));
+void          FitDataSetFree      PROTO((FitDataSet *dataset));
+void          FitDataSetAlloc     PROTO((FitDataSet *dataset, int Nmax, int order, int Nbootstrap));
+void          FitDataSetAddPriors PROTO((FitDataSet *dataset));
 
 unsigned int *ReadTGroupFile      PROTO((FILE *f, int *nelem));
@@ -502,5 +566,5 @@
 void          initTGroupsMcal     PROTO((void));
 TGroup       *getTGroupForImage   PROTO((off_t im));
-off_t         findTGroup          PROTO((unsigned int start, int photcode));
+TGroup       *findTGroup          PROTO((unsigned int start, int photcode));
 
 Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog, int hostID, char *hostpath, char *syncfile));
@@ -527,4 +591,5 @@
 void          plot_star_coords    PROTO((Catalog *catalog, int Ncatalog));
 void          plot_stars          PROTO((Catalog *catalog, int Ncatalog));
+void          plot_setMcal        PROTO((double *list, int Npts));
 
 void          plot_list_add       PROTO((Graphdata *graphdata, double *xlist, double *ylist, int N));
