Index: trunk/Ohana/src/relphot/include/relphot.h
===================================================================
--- trunk/Ohana/src/relphot/include/relphot.h	(revision 40386)
+++ trunk/Ohana/src/relphot/include/relphot.h	(revision 41390)
@@ -90,4 +90,30 @@
 } Mosaic; 
 
+typedef struct {
+  unsigned int start;
+  unsigned int stop;
+  short photcode;
+  float McalPSF;
+  float McalAPER;
+  float dKlam;
+  float dMcal;
+  float dMsys;
+  float McalChiSq;
+  unsigned short nFitPhotom;
+  unsigned int flags;
+
+  off_t Nimage;
+  off_t NIMAGE;
+  off_t *image;
+
+  off_t Nmeasure;
+  off_t NMEASURE;
+  off_t *measure;
+
+  off_t Ncatalog; // XX not needed
+  off_t NCATALOG; // XX not needed
+  off_t *catalog;
+} TGroup; 
+
 typedef enum {
   STATS_NONE, 
@@ -145,4 +171,5 @@
   int Ncal;
   int Nmos;
+  int Ngrp;
   int Ngrid;
 
@@ -305,4 +332,6 @@
 int    VERBOSE_IMAGE;
 int    MOSAIC_ZEROPT;
+int    TGROUP_ZEROPT;
+int    TGROUP_FIT_AIRMASS;
 
 int    TEST_IMAGE1;
@@ -403,4 +432,5 @@
 void          clean_measures      PROTO((Catalog *catalog, int Ncatalog, int final, FlatCorrectionTable *flatcorr));
 void          clean_mosaics       PROTO((void));
+void          clean_tgroups       PROTO((void));
 void          clean_stars         PROTO((Catalog *catalog, int Ncatalog));
 int           corner_check        PROTO((double *x1, double *y1, double *x2, double *y2));
@@ -410,4 +440,5 @@
 void          findImages          PROTO((Catalog *catalog, int Ncatalog, int doImageList));
 int           findMosaics         PROTO((Catalog *catalog, int Ncatalog, int doMosaicList));
+int           findTGroups         PROTO((Catalog *catalog, int Ncatalog));
 
 void clearImages (void);
@@ -428,4 +459,6 @@
 void          freeImageBins       PROTO((int Ncatalog, int doImageList));
 void          freeMosaicBins      PROTO((int Ncatalog, int doMosaicList));
+void          freeTGroupBins      PROTO((int Ncatalog));
+
 void          free_catalogs       PROTO((Catalog *catalog, int Ncatalog));
 int           gcatalog            PROTO((Catalog *catalog, int FINAL));
@@ -437,4 +470,5 @@
 float         getMgrid            PROTO((off_t meas, int cat));
 float         getMmos             PROTO((off_t meas, int cat));
+float         getMgrp             PROTO((off_t meas, int cat, float airmass));
 float         getMrel             PROTO((Catalog *catalog, off_t meas, int cat, dvoMagClassType class, dvoMagSourceType source));
 short         getUbercalDist      PROTO((off_t meas, int cat));
@@ -452,4 +486,7 @@
 void          initMosaicGrid      PROTO((Image *image, off_t Nimage));
 void          initMosaics         PROTO((Image *subset, off_t Nsubset, Image *image, char *inSubset, off_t Nimage));
+void          initTGroups         PROTO((Image *subset, off_t *LineNumber, off_t Nsubset));
+void          freeTGroups         PROTO((void));
+void          initTGroupBins      PROTO((Catalog *catalog, int Ncatalog));
 void          initMrel            PROTO((Catalog *catalog, int Ncatalog));
 RelphotMode   initialize          PROTO((int argc, char **argv));
@@ -459,4 +496,11 @@
 int           liststats_init      PROTO((StatType *stats));
 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));
+
+unsigned int *ReadTGroupFile      PROTO((FILE *f, int *nelem));
+void          loadTGroups         PROTO((char *filename));
+void          initTGroupsMcal     PROTO((void));
+TGroup       *getTGroupForImage   PROTO((off_t im));
+off_t         findTGroup          PROTO((unsigned int start, int photcode));
 
 Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog, int hostID, char *hostpath, char *syncfile));
@@ -470,4 +514,6 @@
 void          matchImage          PROTO((Catalog *catalog, off_t meas, int cat, int doImageList));
 void          matchMosaics        PROTO((Catalog *catalog, off_t meas, int cat, int doMosaicList));
+void          matchTGroups        PROTO((Catalog *catalog, off_t meas, int cat));
+
 double        opening_angle       PROTO((double x1, double y1, double x2, double y2, double x3, double y3));
 void          plot_chisq          PROTO((Catalog *catalog, int Ncatalog));
@@ -491,8 +537,10 @@
 int           setExclusions       PROTO((Catalog *catalog, int Ncatalog, int verbose));
 void          setMcal             PROTO((Catalog *catalog, int Poor, FlatCorrectionTable *flatcorr));
-void          setMcalFinal        PROTO((void));
+void          setMcalFromMosaics  PROTO((void));
+void          setMcalFromTGroups  PROTO((void));
 int           setMcalOutput       PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr));
 void          setMgrid            PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr));
 int           setMmos             PROTO((Catalog *catalog, int Poor, FlatCorrectionTable *flatcorr));
+int           setMgrp             PROTO((Catalog *catalog, int Poor, FlatCorrectionTable *flatcorr));
 int           setMrel             PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr));
 void          setMrelFinal        PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr, int simpleAverage));
@@ -677,2 +725,4 @@
 void RepairWarpMeasuresOpenLogfile ();
 void RepairWarpMeasuresCloseLogfile ();
+
+int save_images_backup (FITS_DB *db);
