Index: /trunk/Ohana/src/addstar/include/addstar.h
===================================================================
--- /trunk/Ohana/src/addstar/include/addstar.h	(revision 3346)
+++ /trunk/Ohana/src/addstar/include/addstar.h	(revision 3347)
@@ -15,4 +15,6 @@
   int found;
 } Stars;
+
+enum {M_IMAGE, M_REFLIST, M_REFCAT};
 
 /* global variables set in parameter file */
Index: /trunk/Ohana/src/addstar/src/RegionOps.c
===================================================================
--- /trunk/Ohana/src/addstar/src/RegionOps.c	(revision 3346)
+++ /trunk/Ohana/src/addstar/src/RegionOps.c	(revision 3347)
@@ -100,5 +100,5 @@
 }
 
-FindRegionByPoint (double ra, double dec, GSCRegion *gsc, int Ngsc) {
+int FindRegionByPoint (GSCRegion *regions, double ra, double dec, GSCRegion *gsc, int Ngsc) {
 
   Ns = FindRegionDecBandStart (gsc, Ngsc, dec);
@@ -109,9 +109,8 @@
     if (gsc[i].DEC[0] >= dec) continue;
     if (gsc[i].DEC[1] <  dec) continue;
-    return (value);
-  }
-
- error:
-  return (-1);
+    region[0] = gsc[i];
+    return (TRUE);
+  }
+  return (FALSE);
 }
 
Index: /trunk/Ohana/src/addstar/src/addstar.c
===================================================================
--- /trunk/Ohana/src/addstar/src/addstar.c	(revision 3346)
+++ /trunk/Ohana/src/addstar/src/addstar.c	(revision 3347)
@@ -14,21 +14,23 @@
   args (argc, argv);
 
+  if (SKYPROBE) load_subpix ();
+
   lock_image_db ();
 
   switch (mode) {
-  case IMAGE:
+  case M_IMAGE:
     stars = gstars (argv[1], &Nstars, &image);
     region = gregion_image (&image, &Nregions);
-    image_db = gimages (&image, &Nimage_db);
+    overlap = gimages (&image, &Noverlap);
     break;
-  case REFLIST:
+  case M_REFLIST:
     stars = grefstars (argv[1], &Nstars);
     region = gregion_stars (stars, &Nregion);
     break;
-  case PATCH :
+  case M_REFCAT:
     regions = gregion_patch (patch, &Nregions);
-    break;
-  case MATCH:
-    regions = gregion_match (&Nregions);
+    if (ONLY_MATCH) {
+      regions = gregion_match (regions, &Nregions);
+    }
     break;
   }
@@ -38,11 +40,10 @@
 
     switch (mode) {
-    case IMAGE:
-      find_matches (&region[i], stars, Nstars, &catalog, &image, pimage, Nimage);
+    case M_IMAGE:
+      find_matches (&region[i], stars, Nstars, &catalog, &image, overlap, Noverlap);
       break;
-    case PATCH:
-    case MATCH:
-      stars = grefcat (region, &Nstars);
-    case REFLIST:
+    case M_REFCAT:
+      stars = grefcat (argv[1], region, &Nstars);
+    case M_REFLIST:
       subset = find_subset (&region, stars, Nstars, &subref, &Nsubset);
       find_matches_refstars (&region, subset, Nsubset, &catalog);
Index: /trunk/Ohana/src/addstar/src/args.c
===================================================================
--- /trunk/Ohana/src/addstar/src/args.c	(revision 3346)
+++ /trunk/Ohana/src/addstar/src/args.c	(revision 3347)
@@ -23,21 +23,49 @@
   }
 
-  /* check for command line options */
-  VERBOSE = FALSE;
-  if ((N = get_argument (argc, argv, "-v"))) {
-    VERBOSE = TRUE;
+  /*** check for command line options ***/
+
+  /* basic mode: image, list, refcat */
+  mode = M_IMAGE;
+  if ((N = get_argument (argc, argv, "-ref"))) {
+    mode = M_REFLIST;
     remove_argument (N, &argc, argv);
   }
-  ACCEPT_ASTROM = FALSE;
-  if ((N = get_argument (argc, argv, "-accept"))) {
-    ACCEPT_ASTROM = TRUE;
+  if ((N = get_argument (argc, argv, "-cat"))) {
+    mode = M_REFCAT;
     remove_argument (N, &argc, argv);
   }
-  thiscode = NULL;
-  if ((N = get_argument (argc, argv, "-p"))) {
+
+  /* restrict to a portion of the sky? (REFCAT only) */
+  patch.RA[0] = 0;
+  patch.RA[1] = 360;
+  patch.DEC[0] = -90;
+  patch.DEC[1] = +90;
+  if ((N = get_argument (argc, argv, "-region"))) {
     remove_argument (N, &argc, argv);
-    thiscode = GetPhotcodebyName (argv[N]);
+    patch.RA[0] = atof (argv[N]);
+    patch.RA[1] = atof (argv[N]);
+    patch.DEC[0] = atof (argv[N]);
+    patch.DEC[1] = atof (argv[N]);
+  }
+  
+  /* only add to existing objects (REFCAT only) */
+  ONLY_MATCH = FALSE;
+  if ((i = get_argument (argc, argv, "-only-match"))) {
+    ONLY_MATCH = TRUE;
+    remove_argument (i, &argc, argv);
+  }
+  /* don't add missed pts to Missed table */
+  SKIP_MISSED = FALSE;
+  if ((N = get_argument (argc, argv, "-missed"))) {
+    SKIP_MISSED = TRUE;
     remove_argument (N, &argc, argv);
   }
+  /* replace measurement, don't duplicate */
+  REPLACE = FALSE;
+  if ((i = get_argument (argc, argv, "-replace"))) {
+    REPLACE = TRUE;
+    remove_argument (i, &argc, argv);
+  }
+  /* only add image potion to image table */
   ONLY_IMAGES = FALSE;
   if ((N = get_argument (argc, argv, "-image"))) {
@@ -45,48 +73,5 @@
     remove_argument (N, &argc, argv);
   }
-  DUMP_MATCHES = FALSE;
-  if ((N = get_argument (argc, argv, "-dump"))) {
-    DUMP_MATCHES = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  FORCE_READ = FALSE;
-  if ((N = get_argument (argc, argv, "-force"))) {
-    FORCE_READ = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  SKIP_MISSED = FALSE;
-  if ((N = get_argument (argc, argv, "-missed"))) {
-    SKIP_MISSED = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  SKYPROBE = FALSE;
-  if ((N = get_argument (argc, argv, "-skyprobe"))) {
-    SKYPROBE = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  ADDREFS = FALSE;
-  if ((N = get_argument (argc, argv, "-addrefs"))) {
-    ADDREFS = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-  REPLACE = FALSE;
-  if ((i = get_argument (argc, argv, "-replace"))) {
-    REPLACE = TRUE;
-    remove_argument (i, &argc, argv);
-  }
-  TIMEREF = 0; 
-  if ((i = get_argument (argc, argv, "-time"))) {
-    remove_argument (i, &argc, argv);
-    if (!str_to_time (argv[i], &TIMEREF)) { 
-      fprintf (stderr, "syntax error in time\n");
-      exit (1);
-    }
-    remove_argument (i, &argc, argv);
-  }
-  ONLY_MATCH = FALSE;
-  if ((i = get_argument (argc, argv, "-only-match"))) {
-    ONLY_MATCH = TRUE;
-    remove_argument (i, &argc, argv);
-  }
+  /* apply average zpt offset calibration */
   CALIBRATE = FALSE;
   if ((N = get_argument (argc, argv, "-cal"))) {
@@ -106,10 +91,51 @@
     remove_argument (N, &argc, argv);
   }
+
+  /* treat data specially for skyprobe (calibration, subpix) */ 
+  SKYPROBE = FALSE;
+  if ((N = get_argument (argc, argv, "-skyprobe"))) {
+    SKYPROBE = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  ACCEPT_ASTROM = FALSE;
+  if ((N = get_argument (argc, argv, "-accept"))) {
+    ACCEPT_ASTROM = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  DUMP_MATCHES = FALSE;
+  if ((N = get_argument (argc, argv, "-dump"))) {
+    DUMP_MATCHES = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  FORCE_READ = FALSE;
+  if ((N = get_argument (argc, argv, "-force"))) {
+    FORCE_READ = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
+  VERBOSE = FALSE;
+  if ((N = get_argument (argc, argv, "-v"))) {
+    VERBOSE = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  thiscode = NULL;
+  if ((N = get_argument (argc, argv, "-p"))) {
+    remove_argument (N, &argc, argv);
+    thiscode = GetPhotcodebyName (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  TIMEREF = 0; 
+  if ((i = get_argument (argc, argv, "-time"))) {
+    remove_argument (i, &argc, argv);
+    if (!str_to_time (argv[i], &TIMEREF)) { 
+      fprintf (stderr, "syntax error in time\n");
+      exit (1);
+    }
+    remove_argument (i, &argc, argv);
+  }
   if (DUMP_MATCHES && !CALIBRATE) {
     fprintf (stderr, "-dump only valid -with -cal\n");
     exit (1);
   }
-
-  if (SKYPROBE) load_subpix ();
 
   if (argc != 2) {
@@ -132,4 +158,6 @@
     ASCII - RA,DEC,M,dM in a table
 
+    addstar 
+
 **/
 
Index: /trunk/Ohana/src/addstar/src/calibrate.c
===================================================================
--- /trunk/Ohana/src/addstar/src/calibrate.c	(revision 3346)
+++ /trunk/Ohana/src/addstar/src/calibrate.c	(revision 3347)
@@ -75,5 +75,5 @@
   }
   /* create a hash array from Nstar[] entries */
-  ALLOCATE (Nlist, int, MAX (1, MaxN + 1));
+  ALLOCATE (Nlist, int, MaxN + 1);
   bzero (Nlist, MAX (0, MaxN*sizeof(int)));
   for (i = 0; i < Ncal; i++) {
Index: /trunk/Ohana/src/addstar/src/find_matches.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches.c	(revision 3346)
+++ /trunk/Ohana/src/addstar/src/find_matches.c	(revision 3347)
@@ -5,5 +5,5 @@
 ((R) >= region[0].RA[0])  && ((R) < region[0].RA[1]))
 
-void find_matches (GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *pimage, int Nimage) {
+void find_matches (GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap) {
 
   double secz;
@@ -360,6 +360,6 @@
 
       /** now add references from all previous non-detection observations of this spot on the sky */
-      for (j = 0; (j < Nimage) && !SKIP_MISSED; j++) {
-	if (in_image (catalog[0].average[Nave].R, catalog[0].average[Nave].D, &pimage[j])) {
+      for (j = 0; (j < Noverlap) && !SKIP_MISSED; j++) {
+	if (in_image (catalog[0].average[Nave].R, catalog[0].average[Nave].D, &overlap[j])) {
 	  if (catalog[0].average[Nave].Nn < 1) {
 	    catalog[0].average[Nave].missing = Nmiss;
@@ -369,6 +369,6 @@
 	  last_miss = Nmiss;
 	  /* this can now be done exactly */
-	  RD_to_XY (&X, &Y, catalog[0].average[Nave].R, catalog[0].average[Nave].D, &pimage[j].coords);	  
-	  catalog[0].missing[Nmiss].t  = pimage[j].tzero + 1e-4*Y*pimage[j].trate;  /* rough guess at time */
+	  RD_to_XY (&X, &Y, catalog[0].average[Nave].R, catalog[0].average[Nave].D, &overlap[j].coords);	  
+	  catalog[0].missing[Nmiss].t  = overlap[j].tzero + 1e-4*Y*overlap[j].trate;  /* rough guess at time */
 	  catalog[0].average[Nave].Nn ++;
 	  Nmiss ++;
Index: /trunk/Ohana/src/addstar/src/find_matches_refstars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 3346)
+++ /trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 3347)
@@ -18,5 +18,5 @@
   int Nsecfilt, Nsec;
 
-  /* photcode data */
+  /* photcode data -- should not have to modify secfilt / average */
   Nsecfilt = GetPhotcodeNsecfilt ();
   Nsec     = GetPhotcodeNsec (thiscode[0].code);
Index: /trunk/Ohana/src/addstar/src/get2mass.c
===================================================================
--- /trunk/Ohana/src/addstar/src/get2mass.c	(revision 3346)
+++ /trunk/Ohana/src/addstar/src/get2mass.c	(revision 3347)
@@ -21,5 +21,5 @@
     Nstars += Ngsc;
 
-    REALLOCATE (stars, StarData, MAX (1, Nstars));
+    REALLOCATE (stars, StarData, Nstars);
     for (k = Ns, j = 0; j < Ngsc; k++, j++) {
       stars[k].R = gsc[j].R;
Index: /trunk/Ohana/src/addstar/src/getgsc.c
===================================================================
--- /trunk/Ohana/src/addstar/src/getgsc.c	(revision 3346)
+++ /trunk/Ohana/src/addstar/src/getgsc.c	(revision 3347)
@@ -21,5 +21,5 @@
     Nstars += Ngsc;
 
-    REALLOCATE (stars, StarData, MAX (1, Nstars));
+    REALLOCATE (stars, StarData, Nstars);
     for (k = Ns, j = 0; j < Ngsc; k++, j++) {
       stars[k].R   = gsc[j].R;
Index: /trunk/Ohana/src/addstar/src/getusno.c
===================================================================
--- /trunk/Ohana/src/addstar/src/getusno.c	(revision 3346)
+++ /trunk/Ohana/src/addstar/src/getusno.c	(revision 3347)
@@ -9,5 +9,5 @@
   1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10};
 
-StarData *getusno (CatStats *catstats, int *Nstars) {
+Stars *getusno (CatStats *catstats, int *Nstars) {
 
   long int offset;
@@ -21,5 +21,5 @@
   int spd, spd_start, spd_end, disk;
   int NUSNO, Nusno;
-  StarData *stars;
+  Stars *stars;
 
   /** USNO-specific things **/
@@ -57,5 +57,5 @@
   Nusno = 0;
   NUSNO = 5000;
-  ALLOCATE (stars, StarData, NUSNO);
+  ALLOCATE (stars, Stars, NUSNO);
 
   for (spd = spd_start; spd < spd_end; spd += 75) {
@@ -125,14 +125,18 @@
 	if ((buf[0] > iRA0) && (buf[0] < iRA1) &&
 	    (buf[1] > iDEC0) && (buf[1] < iDEC1)) {
-	  bzero (&stars[Nusno], sizeof(StarData));
+	  bzero (&stars[Nusno], sizeof(Stars));
 	  stars[Nusno].R = buf[0]/360000.0;
 	  stars[Nusno].D = buf[1]/360000.0 - 90.0;
 	  stars[Nusno].Mag = fabs (0.1*(buf[2] - 1000*((int)(buf[2]/1000))));
-	  /* b = 0.1*((int)(buf[2] - 1000000*((int)(buf[2]/1000000))) / 1000); */
+	  stars[Nusno].code = USNO_RED;
+	  /* r data */
 	  Nusno ++;
-	  if (Nusno == NUSNO) {
-	    NUSNO += 5000;
-	    REALLOCATE (stars, StarData, NUSNO);
-	  }	  
+	  stars[Nusno].R = buf[0]/360000.0;
+	  stars[Nusno].D = buf[1]/360000.0 - 90.0;
+	  stars[Nusno].Mag = fabs (0.1*((int)(buf[2] - 1000000*((int)(buf[2]/1000000))) / 1000));
+	  stars[Nusno].code = USNO_BLUE;
+	  /* b data */
+	  Nusno ++;
+	  CHECK_REALLOCATE (stars, Stars, NUSNO, Nusno-1, 5000);
 	}
       }
Index: /trunk/Ohana/src/addstar/src/greference.c
===================================================================
--- /trunk/Ohana/src/addstar/src/greference.c	(revision 3346)
+++ /trunk/Ohana/src/addstar/src/greference.c	(revision 3347)
@@ -1,10 +1,10 @@
 # include "addstar.h"
 
-Stars *grefcat (CatStats *catstats, int *Nrefcat) {
+Stars *grefcat (char *Refcat, CatStats *catstats, int *Nrefcat) {
 
   int Nstars;
   Stars *stars;
 
-  if (VERBOSE) fprintf (stderr, "loading astrometric reference data from %s\n", REFCAT); 
+  if (VERBOSE) fprintf (stderr, "loading reference catalog data from %s\n", Refcat); 
 
   Nstars = 0;
@@ -12,20 +12,20 @@
 
   /* get stars from USNO for the given region */
-  if (!strcmp (REFCAT, "USNO")) {
+  if (!strcmp (Refcat, "USNO")) {
     stars = getusno (catstats, &Nstars);
   }
 
   /* get stars from HST GSC for the given region */
-  if (!strcmp (REFCAT, "GSC")) {
+  if (!strcmp (Refcat, "GSC")) {
     stars = getgsc (catstats, &Nstars);
   }
   
   /* get stars from 2MASS for the given region */
-  if (!strcmp (REFCAT, "2MASS")) {
+  if (!strcmp (Refcat, "2MASS")) {
     stars = get2mass (catstats, &Nstars);
   }
   
   if (Nstars == 0) {
-    fprintf (stderr, "no ref objs: %s\n", REFCAT);
+    fprintf (stderr, "no ref objs: %s\n", Refcat);
     exit (1);
   }
Index: /trunk/Ohana/src/addstar/src/grefstars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/grefstars.c	(revision 3346)
+++ /trunk/Ohana/src/addstar/src/grefstars.c	(revision 3347)
@@ -21,4 +21,10 @@
   ALLOCATE (stars, Stars, NSTARS);
 
+  /* require photcode */
+  if (thiscode == NULL) {
+    fprintf (stderr, "error: photcode not specified\n");
+    exit (2);
+  }
+
   /* read in stars line-by-line */
   for (N = 0; scan_line (f, line) != EOF; N++) {
@@ -34,8 +40,6 @@
     stars[N].dophot = 0;
     stars[N].found = -1;
-    if (N == NSTARS - 1) {
-      NSTARS += 100;
-      REALLOCATE (stars, Stars, NSTARS);
-    }
+    stars[N].code = thiscode[0].code;;
+    CHECK_REALLOCATE (stars, Stars, NSTARS, N+1, 100);
   }
   *Nstars = N;
@@ -43,2 +47,3 @@
 }
 
+/* add the photcode here */
Index: /trunk/Ohana/src/addstar/src/gregion_image.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gregion_image.c	(revision 3346)
+++ /trunk/Ohana/src/addstar/src/gregion_image.c	(revision 3347)
@@ -17,5 +17,5 @@
   
   /* find regions at image corners */
-  NREGION = 10;
+  NREGION = 100;
   ALLOCATE (region, GSCRegion, NREGION);
   nregion = 0;
@@ -35,8 +35,5 @@
       }
       nregion ++;
-      if (nregion == NREGION) {
-	NREGION += 10;
-	REALLOCATE (region, GSCRegion, NREGION);
-      }
+      CHECK_REALLOCATE (region, GSCRegion, NREGION, nregion, 100);
     }
   }
Index: /trunk/Ohana/src/addstar/src/gregion_match.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gregion_match.c	(revision 3346)
+++ /trunk/Ohana/src/addstar/src/gregion_match.c	(revision 3347)
@@ -1,51 +1,30 @@
 # include "addstar.h"
-# include <glob.h>
 
-GSCRegion *gregion_match (int *nregions) {
+GSCRegion *gregion_match (GSCRegion *regions, int *nregions) {
   
   int i;
-  int    Ngsc, Nregions;
-  glob_t pglob;
+  int       Nsubset;
+  GSCRegion *subset;
+  struct stat filestats;
+  
+  Nregions = *nregions;
 
-  GSCRegion *gsc, *regions;
-  
-  gsc = LoadRegions (&Ngsc);
-
-  sprintf (globline, "%s/[nsNS]????/*.cpt", CATDIR);
-  pglob.gl_offs = 0;
-  glob (globline, 0, NULL, &pglob);
-
-  Nregions = 0;
-  ALLOCATE (regions, GSCRegions, MAX (1, pglob.gl_pathc));
+  Nsubset = 0;
+  NSUBSET = 100;
+  ALLOCATE (subset, GSCRegions, NSUBSET);
 
   /* match the basename against the GSCRegion file names */
-  for (i = 0; i < pglob.gl_pathc; i++) {
-    found = FALSE;
-    for (j = 0; !found && (j < Ngsc); j++) {
-      if (strcasecmp (pglob.gl_pathv, gsc[j].filename)) continue;
-      regions[Nregions] = gsc[j];
-      found = TRUE;
-    }
+  for (i = 0; i < Nregions; i++) {
+    status = stat (regions[i].filename, &filestats);
+    if ((status == -1) && (errno == ENOENT)) continue;
+    /* give an error for other conditions? */
+
+    subset[Nsubset] = regions[i];
+    Nsubset ++;
+    CHECK_ALLOCATE (subset, GSCRegion, NSUBSET, Nsubset, 100);
   }
-  *nregions = Nregions;
-  return (regions);
-  
-  /* should free things up here */
+  free (regions);
+
+  *nregions = Nsubset;
+  return (subset);
 }
-
-/* given a ra,dec bounded region, find all region files which overlap it
-
-   - split region into two if overlapping 0,360 boundary 
-
-*/
-
-/* the goal here is to return a list of the existing region files
-   this means either: 
-
-      grabbing all files that are on disk and converting 
-      them to GSCRegion files
-
-      trying all GSCRegion files to see if they exist 
-      (and are populated?)
-      
-*/
Index: /trunk/Ohana/src/addstar/src/gregion_match_glob.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gregion_match_glob.c	(revision 3347)
+++ /trunk/Ohana/src/addstar/src/gregion_match_glob.c	(revision 3347)
@@ -0,0 +1,51 @@
+# include "addstar.h"
+# include <glob.h>
+
+GSCRegion *gregion_match (int *nregions) {
+  
+  int i;
+  int    Ngsc, Nregions;
+  glob_t pglob;
+
+  GSCRegion *gsc, *regions;
+  
+  gsc = LoadRegions (&Ngsc);
+
+  sprintf (globline, "%s/[nsNS]????/*.cpt", CATDIR);
+  pglob.gl_offs = 0;
+  glob (globline, 0, NULL, &pglob);
+
+  Nregions = 0;
+  ALLOCATE (regions, GSCRegions, MAX (1, pglob.gl_pathc));
+
+  /* match the basename against the GSCRegion file names */
+  for (i = 0; i < pglob.gl_pathc; i++) {
+    found = FALSE;
+    for (j = 0; !found && (j < Ngsc); j++) {
+      if (strcasecmp (pglob.gl_pathv, gsc[j].filename)) continue;
+      regions[Nregions] = gsc[j];
+      found = TRUE;
+    }
+  }
+  *nregions = Nregions;
+  return (regions);
+  
+  /* should free things up here */
+}
+
+/* given a ra,dec bounded region, find all region files which overlap it
+
+   - split region into two if overlapping 0,360 boundary 
+
+*/
+
+/* the goal here is to return a list of the existing region files
+   this means either: 
+
+      grabbing all files that are on disk and converting 
+      them to GSCRegion files
+
+      trying all GSCRegion files to see if they exist 
+      (and are populated?)
+      
+*/
Index: /trunk/Ohana/src/addstar/src/gregion_patch.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gregion_patch.c	(revision 3346)
+++ /trunk/Ohana/src/addstar/src/gregion_patch.c	(revision 3347)
@@ -14,5 +14,5 @@
   
   Nregions = 0;
-  ALLOCATE (regions, GSCRegions, MAX (1, (Ne - Ns)));
+  ALLOCATE (regions, GSCRegions, (Ne - Ns));
 
   /* find all regions in range within ra range */
Index: /trunk/Ohana/src/addstar/src/gregion_star.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gregion_star.c	(revision 3346)
+++ /trunk/Ohana/src/addstar/src/gregion_star.c	(revision 3347)
@@ -4,25 +4,30 @@
   
   int i;
-  int       Ngsc;
-  GSCRegion *gsc;
+  int       Ngsc, Nregions, NREGIONS;
+  GSCRegion *gsc, regions;
   
   gsc = LoadRegions (&Ngsc);
+
+  Nregions = 0;
+  NREGIONS = 100;
+  ALLOCATE (region, GSCRegion, NREGIONS);
 
   sort_stars (stars, Nstars);
   for (i = 0; i < Nstars; i++) {
     if (stars[0].found) continue;
-    region = FindRegionByPoint (star[0].R, star[0].D, gsc, Ngsc);
+    FindRegionByPoint (&regions[Nregions], star[0].R, star[0].D, gsc, Ngsc);
     stars[0].found = TRUE;
     /* search forward for all contained stars */
     for (j = i; j < Nstars; j++) {
-      if (stars[j].R >= region.RA[1]) break;
-      if (stars[j].D <  region.DEC[0]) continue;
-      if (stars[j].D >= region.DEC[1]) continue;
+      if (stars[j].R >= regions.RA[1]) break;
+      if (stars[j].D <  regions.DEC[0]) continue;
+      if (stars[j].D >= regions.DEC[1]) continue;
       stars[j].found = TRUE;
     }
+    Nregions ++;
+    CHECK_REALLOCATE (regions, GSCRegion, Nregions, NREGIONS, 100);
   }
 
 }
-
 
 /* given a list of stars, find all region files which contain them 
@@ -40,4 +45,2 @@
 
 */
-
-   
Index: /trunk/Ohana/src/addstar/src/gstars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gstars.c	(revision 3346)
+++ /trunk/Ohana/src/addstar/src/gstars.c	(revision 3347)
@@ -244,59 +244,2 @@
   return (stars);
 }
-
-# if (0)
-  /* left over fraction of a block */
-  nbytes = Fread (buffer, 1, (Nbytes % (BLOCK*BYTES_STAR)), f, "char");
-  if (nbytes != (Nbytes % (BLOCK*BYTES_STAR))) {
-    fprintf (stderr, "ERROR: failed to read in stars (2)\n");
-    exit (1);
-  }
-  /* check line-by-line integrity */
-  Nnew = 0;
-  c = buffer;
-  done = FALSE;
-  while ((c < buffer + nbytes) && (!done)) { 
-    for (c2 = c; *c2 == '\n'; c2++);
-    if (c2 > c) { /* extra return chars */
-      memmove (c, c2, (int)(buffer + nbytes - c2));
-      Nnew += c2 - c;
-      fprintf (stderr, "deleting %d extra return chars\n", (int)(c2-c));
-    }
-    c2 = strchr (c, '\n');
-    if (c2 == (char *) NULL) {
-      if (Nnew > 0) {
-	nnew = Fread (&buffer[nbytes-Nnew], 1, Nnew, f, "char");
-	if (nnew != Nnew) {
-	  fprintf (stderr, "ERROR: failed to read in stars (1)\n");
-	  exit (1);
-	}
-      } else {
-	done = TRUE;	
-      }
-      continue;
-    }
-    c2++;
-    if ((c2 - c) != BYTES_STAR) {
-      /* this is a bad line, delete it, adjust data in buffer, 
-	 and be ready to read the rest of the last line */
-      memmove (c, c2, (int)(buffer + nbytes - c2));
-      Nnew += c2 - c;
-      fprintf (stderr, "deleting bad line with %d chars\n", (int)(c2-c));
-    } else {
-      c = c2;
-    }
-  }
-  for (j = 0; j < nbytes / BYTES_STAR; j++, nstar++, N++) {
-    dparse (&stars[N].X, 1, &buffer[j*BYTES_STAR]);
-    dparse (&stars[N].Y, 2, &buffer[j*BYTES_STAR]);
-    dparse (&stars[N].M, 3, &buffer[j*BYTES_STAR]);
-    dparse (&stars[N].dM, 4, &buffer[j*BYTES_STAR]);
-    XY_to_RD (&stars[N].R, &stars[N].D, stars[N].X, stars[N].Y, &image[0].coords);
-    while (stars[N].R < 0.0) stars[N].R += 360.0;
-    while (stars[N].R >= 360.0) stars[N].R -= 360.0;
-    dparse (&tmp, 5, &buffer[j*BYTES_STAR]);
-    stars[N].dophot = tmp;
-    stars[N].found = -1;
-  }
-
-# endif
