Index: trunk/Ohana/src/addstar/include/addstar.h
===================================================================
--- trunk/Ohana/src/addstar/include/addstar.h	(revision 3347)
+++ trunk/Ohana/src/addstar/include/addstar.h	(revision 3361)
@@ -2,4 +2,18 @@
 # include <loneos.h>
 # include <signal.h>
+# include <sys/time.h>
+# include <time.h>
+
+/* used in find_matches, find_matches_refstars */
+# define IN_CATALOG(R,D) ( \
+((D) >= region[0].DEC[0]) && ((D) < region[0].DEC[1]) && \
+((R) >= region[0].RA[0])  && ((R) < region[0].RA[1]))
+
+/* grab named photcode */
+# define NAMED_PHOTCODE(CODE,NAME) \
+  CODE = GetPhotcodebyName (NAME); \
+  if (!CODE) { \
+    fprintf (stderr, "ERROR:  photcode %s not found in photcode table\n", NAME); \
+    exit (0); }
 
 typedef struct {
@@ -14,5 +28,14 @@
   double Mgal, Map;
   int found;
+  short int code;
+  e_time t;
 } Stars;
+
+/* structure for data on a catalog region */
+typedef struct {
+  char filename[256];
+  double RA[2];
+  int Nrec;
+} TM_Region;
 
 enum {M_IMAGE, M_REFLIST, M_REFCAT};
@@ -34,4 +57,5 @@
 
 PhotCode *thiscode;
+GSCRegion patch;
 
 char DateKeyword[64];
@@ -57,4 +81,6 @@
 int ONLY_MATCH;
 
+int MODE;
+
 time_t TIMEREF;
 
@@ -70,19 +96,13 @@
 void gregion_star (Stars *star, GSCRegion *region);
 GSCRegion *gregion_image (Image *image, int *Nregions);
-Image *gimages (FILE *f, Image *image, int *Npimage);
 int edge_check (double *x1, double *y1, double *x2, double *y2);
 double opening_angle (double x1, double y1, double x2, double y2, double x3, double y3);
-void wimage (FILE *f, int dbstate, Image *image, int Nstars);
 Stars *gstars (char *file, int *NSTARS, Image *image);
-void find_matches_refstars (GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog);
-void find_matches (GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *pimage, int Nimage);
 int in_image (double r, double d, Image *image);
 void wcatalog (Catalog *catalog);
 void ConfigInit (int *argc, char **argv);
 void aregion (GSCRegion *region, FILE *f, double ra, double dec);
-void wimage (FILE *f, int dbstate, Image *image, int Nstars);
-double airmass (double ra, double dec, double st, double latitude);
+short airmass (short secz_image, double ra, double dec, double st, double latitude);
 void InitCalibration ();
-void SaveCalibration (float M, float dM, float Mr, float dMr, float Mc, float A, int N, float ra, float dec, float x, float y);
 void FindCalibration (Image *image);
 double get_subpix (double x, double y);
@@ -91,5 +111,5 @@
 void mkcatalog (GSCRegion *region, Catalog *catalog);
 Stars *grefstars (char *file, int *Nstars);
-Stars *find_subset (GSCRegion *region, Stars *stars, int Nstars, int *NSTARS);
+Stars **find_subset (GSCRegion *region, Stars *stars, int Nstars, int *NSTARS);
 int match_refstars (Stars *stars, int Nstars);
 int parse_time (Header *header);
@@ -113,4 +133,6 @@
 time_t jd_to_sec (double jd);
 time_t date_to_sec (char *date);
+time_t short_date_to_sec (char *date);
+
 
 /** 
@@ -122,2 +144,47 @@
   e_time pointer from one of these functions)
 **/
+
+Stars *get2mass (GSCRegion *patch, int *NSTARS);
+TM_Region *get2mass_acc (GSCRegion *patch, int *nfiles);
+Stars *get2mass_data (char *filename, GSCRegion *patch, int *nstars);
+GSCRegion *gregion_stars (Stars *stars, int Nstars, int *Nregion);
+Stars *grefstars (char *file, int *Nstars);
+GSCRegion *LoadRegions (int *nregions);
+int FindRegionByPoint (GSCRegion *regions, double ra, double dec, GSCRegion *gsc, int Ngsc);
+int FindRegionDecBandStart (GSCRegion *region, int Nregion, double dec);
+int FindRegionDecBandStop (GSCRegion *region, int Nregion, double dec);
+int hms_to_deg (double *h0, double *h1, double *d0, double *d1, char *string);
+void find_matches_refstars (GSCRegion *region, Stars **stars, int Nstars, Catalog *catalog);
+Stars *gstars (char *file, int *NSTARS, Image *image);
+void find_matches (GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap);
+Stars *getusno (GSCRegion *catstats, int *Nstars);
+Stars *rd_gsc (char *filename, int *nstars);
+Stars *getgsc (GSCRegion *patch, int *NSTARS);
+Stars *grefcat (char *Refcat, GSCRegion *catstats, int *nstars);
+void load_subpix ();
+double get_subpix (double x, double y);
+double scat_subpix (double x, double y);
+void help ();
+int args (int argc, char **argv);
+void InitCalibration ();
+void SaveCalibration (float M, float dM, float Mr, float dMr, float Mc, float A, int N);
+void AddToCalibration (Average *average, Measure *measure, Measure *new, int Nstar);
+void FindCalibration (Image *image);
+int load_pt_catalog (Catalog *catalog, GSCRegion *region);  /*** choose new name ***/
+void save_pt_catalog (Catalog *catalog);  /*** choose new name ***/
+void wcatalog (Catalog *catalog);
+GSCRegion *gregions (Image *image, int *Nregions);
+int gcatalog (Catalog *catalog);
+GSCRegion *gregion_image (Image *image, int *Nregions);
+void update_coords (Average *average, Measure *measure, int *next);
+int replace_match (Average *average, Measure *measure, Stars *star);
+FILE *GetDB (int *state);
+int Shutdown ();
+void lock_image_db ();
+void unlock_image_db (Image *image);
+void wimage (Image *image);
+Image *gimages (Image *image, int *Npimage);
+double opening_angle (double x1, double y1, double x2, double y2, double x3, double y3);
+int edge_check (double *x1, double *y1, double *x2, double *y2);
+GSCRegion *gregion_match (GSCRegion *regions, int *nregions);
+GSCRegion *gregion_patch (GSCRegion *patch, int *nregions);
