Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/FilterStars.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/FilterStars.c	(revision 16647)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/FilterStars.c	(revision 16648)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-Stars *FilterStars (Stars *instars, Image *image) {
+Stars *FilterStars (Stars *instars, Image *image, unsigned int imageID) {
 
   int j, N;
@@ -72,4 +72,9 @@
     }
     
+    // XXX currently, this ID is internal only; 
+    // should we use the psphot / other external ID, if available?
+    stars[N].detID = N; // sequence number within image
+    stars[N].imageID = imageID; // does this need to be updated?
+
     N ++;
   }
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/LoadStars.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/LoadStars.c	(revision 16647)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/LoadStars.c	(revision 16648)
@@ -1,8 +1,8 @@
 # include "addstar.h"
 
-Stars *LoadStars (char *filename, int *Nstars, Image **images, int *Nimages, int photcode) {
-
-  int i, Nfile, Nheaders, NheaderSets, mode, *extsize;
-  char **file;
+Stars *LoadStars (char *filename, int *Nstars, Image **images, int *Nimages, AddstarClientOptions *options) {
+
+  int i, Nfile, NFILE, Nheaders, NheaderSets, mode, *extsize;
+  char **file, line[1024];
   FILE *f;
   glob_t globList;
@@ -11,19 +11,36 @@
   HeaderSet *headerSets;
 
-  // parse the filename as a glob
-  globList.gl_offs = 0;
-  glob (filename, 0, NULL, &globList);
-
-  // if the glob does not match, save the literal word:
-  // otherwise save all glob matches
-  if (globList.gl_pathc == 0) {
-    Nfile = 1;
-    ALLOCATE (file, char *, Nfile);
-    file[0] = strcreate (filename);
+  if (options[0].filelist) {
+    // read the list of input files from the supplied file
+    f = fopen (filename, "r");
+    if (f == NULL) {
+      fprintf (stderr, "can't read input list %s, giving up\n", filename);
+      exit (1);
+    }
+
+    NFILE = 10;
+    ALLOCATE (file, char *, NFILE);
+    for (i = 0; (fscanf (f, "%s", line) != EOF); i++) {
+      // filename limited to 1024 chars
+      file[i] = strcreate (line);
+    }
+    Nfile = i;
   } else {
-    Nfile = globList.gl_pathc;
-    ALLOCATE (file, char *, Nfile);
-    for (i = 0; i < Nfile; i++) {
-      file[i] = strcreate (globList.gl_pathv[i]);
+    // parse the filename as a glob
+    globList.gl_offs = 0;
+    glob (filename, 0, NULL, &globList);
+
+    // if the glob does not match, save the literal word:
+    // otherwise save all glob matches
+    if (globList.gl_pathc == 0) {
+      Nfile = 1;
+      ALLOCATE (file, char *, Nfile);
+      file[0] = strcreate (filename);
+    } else {
+      Nfile = globList.gl_pathc;
+      ALLOCATE (file, char *, Nfile);
+      for (i = 0; i < Nfile; i++) {
+	file[i] = strcreate (globList.gl_pathv[i]);
+      }
     }
   }
@@ -54,5 +71,5 @@
 
     /* supplied photcode is incompatible with multi-chip images */
-    if ((NheaderSets > 1) && photcode) {
+    if ((NheaderSets > 1) && options[0].photcode) {
       fprintf (stderr, "ERROR: photcode cannot be supplied to multi-chip images -- manually adjust the headers\n");
       exit (1);
@@ -227,4 +244,7 @@
       continue;
     }
+    images[0][Nvalid].imageID = Nvalid;
+    images[0][Nvalid].externID = 0;
+    images[0][Nvalid].sourceID = 0;
 
     // XXX use something to set the chip name? EXTNAME?
@@ -254,5 +274,5 @@
 	 
     inStars = ReadStarsFITS (f, headers[Nhead], headers[Ndata], &images[0][Nvalid].nstar);
-    inStars = FilterStars (inStars, &images[0][Nvalid]);
+    inStars = FilterStars (inStars, &images[0][Nvalid], Nvalid);
     *stars = MergeStars (*stars, Nstars, inStars, images[0][Nvalid].nstar);
     Nvalid++;
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/addstar.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/addstar.c	(revision 16647)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/addstar.c	(revision 16648)
@@ -37,5 +37,9 @@
   switch (options.mode) {
     case M_IMAGE:
-      stars = LoadStars (argv[1], &Nstars, &images, &Nimages, options.photcode);
+      stars = LoadStars (argv[1], &Nstars, &images, &Nimages, &options);
+
+      // set and update the imageID sequence
+      UpdateImageIDs (stars, Nstars, images, Nimages);
+
       if ((DUMP != NULL) && !strcmp (DUMP, "rawstars")) dump_rawstars (stars, Nstars);
       for (i = 0; i < Nimages; i++) {
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/args.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/args.c	(revision 16647)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/args.c	(revision 16648)
@@ -37,4 +37,10 @@
   if ((N = get_argument (argc, argv, "-resort"))) {
     options.mode = M_RESORT;
+    remove_argument (N, &argc, argv);
+  }
+
+  options.filelist = FALSE;
+  if ((N = get_argument (argc, argv, "-list"))) {
+    options.filelist = TRUE;
     remove_argument (N, &argc, argv);
   }
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/fakeimage.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/fakeimage.c	(revision 16647)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/fakeimage.c	(revision 16648)
@@ -193,4 +193,6 @@
   image[0].Myyyy = 0;
 
+  // XXX need to set the imageID here
+
   *Nimage = Nchips + 1;
   return (image);
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches.c	(revision 16647)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches.c	(revision 16648)
@@ -37,4 +37,8 @@
   NMEAS = Nmeas = catalog[0].Nmeasure;
   
+  // current max obj ID for this catalog
+  objID = catalog[0].objID;
+  catID = catalog[0].catID;
+
   /* project onto rectilinear grid with 1 arcsec pixels. the choice of ZEA projection has the
    * advantage that every point in R,D has a mapping to a unique X,Y.  However, note that not all
@@ -280,4 +284,8 @@
     catalog[0].average[Nave].P         = 0;
     catalog[0].average[Nave].dP        = 0;
+
+    catalog[0].average[Nave].objID     = objID;
+    catalog[0].average[Nave].catID     = catID;
+    objID ++;
 
     for (j = 0; j < Nsecfilt; j++) {
@@ -314,5 +322,5 @@
 
     catalog[0].measure[Nmeas].detID     = stars[N].detID;
-    catalog[0].measure[Nmeas].imageID   = options.imageID;
+    catalog[0].measure[Nmeas].imageID   = stars[N].imageID;
 
     catalog[0].measure[Nmeas].dXccd     = stars[N].dX;
@@ -359,4 +367,5 @@
 
   /* check if the catalog has changed?  if no change, no need to write */
+  catalog[0].objID    = objID; // new max value, save on catalog close
   catalog[0].Naverage = Nave;
   catalog[0].Nmeasure = Nmeas;
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches_closest.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches_closest.c	(revision 16647)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches_closest.c	(revision 16648)
@@ -37,4 +37,8 @@
   NMEAS = Nmeas = catalog[0].Nmeasure;
   NMISS = Nmiss = catalog[0].Nmissing;
+
+  // current max obj ID for this catalog
+  objID = catalog[0].objID;
+  catID = catalog[0].catID;
 
   /* project onto rectilinear grid with 1 arcsec pixels. the choice of ZEA projection has the
@@ -283,4 +287,8 @@
     catalog[0].average[Nave].dP        = 0;
 
+    catalog[0].average[Nave].objID     = objID;
+    catalog[0].average[Nave].catID     = catID;
+    objID ++;
+
     for (j = 0; j < Nsecfilt; j++) {
       catalog[0].secfilt[Nave*Nsecfilt+j].M  = NAN;
@@ -360,4 +368,5 @@
 
   /* check if the catalog has changed?  if no change, no need to write */
+  catalog[0].objID    = objID; // new max value, save on catalog close
   catalog[0].Naverage = Nave;
   catalog[0].Nmeasure = Nmeas;
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches_refstars.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches_refstars.c	(revision 16647)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/find_matches_refstars.c	(revision 16648)
@@ -47,4 +47,8 @@
   REALLOCATE (catalog[0].missing, Missing, NMISS);
   
+  // current max obj ID for this catalog
+  objID = catalog[0].objID;
+  catID = catalog[0].catID;
+
   /* project onto rectilinear grid with 1 arcsec pixels, sort by X */
   /* reference for coords is catalog center */
@@ -253,4 +257,8 @@
     }
 
+    catalog[0].average[Nave].objID     = objID;
+    catalog[0].average[Nave].catID     = catID;
+    objID ++;
+
     for (j = 0; j < Nsecfilt; j++) {
       catalog[0].secfilt[Nave*Nsecfilt+j].M  = NAN;
@@ -369,4 +377,5 @@
   free (next_miss);
 
+  catalog[0].objID    = objID; // new max value, save on catalog close
   catalog[0].Naverage = Nave;
   catalog[0].Nmeasure = Nmeas;
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/get2mass_dr2.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/get2mass_dr2.c	(revision 16647)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/get2mass_dr2.c	(revision 16648)
@@ -62,4 +62,6 @@
       stars[Nstars].t  	  = short_date_to_sec (&buffer[NBYTE*i + 164]);
       stars[Nstars].found = -1;
+      stars[Nstars].detID   = 0;
+      stars[Nstars].imageID = 0;
 
       if (photcode == TM_J) {
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/get2mass_ops.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/get2mass_ops.c	(revision 16647)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/get2mass_ops.c	(revision 16648)
@@ -57,9 +57,11 @@
   }
 
-  star[0].M     = M;
-  star[0].dM    = dM;
-  star[0].code  = Photcode;
-  star[0].t     = time;
-  star[0].found = -1;
+  star[0].M       = M;
+  star[0].dM      = dM;
+  star[0].code    = Photcode;
+  star[0].t       = time;
+  star[0].found   = -1;
+  star[0].detID   = 0;
+  star[0].imageID = 0;
 
   return TRUE;
@@ -108,4 +110,6 @@
   star[0].t     = time;
   star[0].found = -1;
+  star[0].detID   = 0;
+  star[0].imageID = 0;
 
   star[1].M     = H;
@@ -114,4 +118,6 @@
   star[1].t     = time;
   star[1].found = -1;
+  star[1].detID   = 0;
+  star[1].imageID = 0;
 
   star[2].M     = K;
@@ -120,4 +126,6 @@
   star[2].t     = time;
   star[2].found = -1;
+  star[2].detID   = 0;
+  star[2].imageID = 0;
 
   return TRUE;
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/getgsc.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/getgsc.c	(revision 16647)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/getgsc.c	(revision 16648)
@@ -75,4 +75,8 @@
       stars[Nstars].code  = GSC_M;
       stars[Nstars].found = -1;
+
+      stars[Nstars].detID   = 0;
+      stars[Nstars].imageID = 0;
+
       Nstars ++;
       CHECK_REALLOCATE (stars, Stars, NSTARS, Nstars, 1000);
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/gettycho.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/gettycho.c	(revision 16647)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/gettycho.c	(revision 16648)
@@ -96,4 +96,7 @@
 	stars[Ntycho].dP  = 0;
 
+	stars[Ntycho].detID   = 0;
+	stars[Ntycho].imageID = 0;
+
 	/* Tycho uses J2000 equinox and 1991.25 epoch for coordinates */
 	/* the magnitudes have no temporal information */ 
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/getusno.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/getusno.c	(revision 16647)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/getusno.c	(revision 16648)
@@ -117,4 +117,7 @@
       stars[Nusno].found = -1;
 
+      stars[Nusno].detID   = 0;
+      stars[Nusno].imageID = 0;
+
       /* one pass of addstar does either r or b */
       if (photcode == USNO_RED) {
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/getusnob.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/getusnob.c	(revision 16647)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/getusnob.c	(revision 16648)
@@ -141,4 +141,7 @@
       stars[Nusno].found = -1;
       
+      stars[Nusno].detID   = 0;
+      stars[Nusno].imageID = 0;
+
       /* USNO-B uses J2000 equinox and 2000.0 epoch for coordinates */
       /* the magnitudes have no temporal information */ 
Index: /branches/eam_branch_20080223/Ohana/src/addstar/src/grefstars.c
===================================================================
--- /branches/eam_branch_20080223/Ohana/src/addstar/src/grefstars.c	(revision 16647)
+++ /branches/eam_branch_20080223/Ohana/src/addstar/src/grefstars.c	(revision 16648)
@@ -30,4 +30,6 @@
     stars[N].code = photcode;
     stars[N].found = FALSE;
+    stars[N].detID   = 0;
+    stars[N].imageID = 0;
     CHECK_REALLOCATE (stars, Stars, NSTARS, N+1, 100);
   }
