Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/Makefile
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/Makefile	(revision 38521)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/Makefile	(revision 38522)
@@ -71,4 +71,5 @@
 $(SRC)/grefstars.$(ARCH).o \
 $(SRC)/GetZeroPointExposure.$(ARCH).o \
+$(SRC)/LoadFilenames.$(ARCH).o \
 $(SRC)/LoadStars.$(ARCH).o \
 $(SRC)/LoadHeaders.$(ARCH).o \
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/include/addstar.h
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/include/addstar.h	(revision 38521)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/include/addstar.h	(revision 38522)
@@ -33,4 +33,10 @@
 
 # define myAbortF(FORMAT,...) { fprintf (stderr, FORMAT, __VA_ARGS__); abort(); }
+
+// things that are needed for a single file
+typedef struct {
+  char *filename;  // name of the file on disk (full path)
+  char *imagename; // name of the image for user reference (eg, base of neb path, full path, etc)
+} AddstarFile;
 
 typedef struct {
@@ -232,5 +238,5 @@
 HeaderSet *MatchHeaders           PROTO((off_t **extsize, off_t *nimage, int mode, Header **headers, int Nheaders));
 void       HeaderSetFree          PROTO((HeaderSet *headerSets, off_t NheaderSets));
-int        LoadData               PROTO((FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, int NheaderSets, AddstarClientOptions *options));
+int        LoadData               PROTO((FILE *f, AddstarFile *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, int NheaderSets, AddstarClientOptions *options));
 int        GetZeroPointExposure   PROTO((Header **headers, HeaderSet *headerSets, off_t Nimages));
 
@@ -336,4 +342,7 @@
 int LoadDataUKIRT (FILE *f, char *file, Image **images, off_t *nimages, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t NheaderSets);
 
+AddstarFile *LoadFilenames (int *nfile, char *filename, AddstarClientOptions *options);
+void AddstarFileFree (AddstarFile *file, int Nfile);
+
 /** 
     there is an inconsistency to be resolved: fixed structures (like Image)
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ImageIndex.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ImageIndex.c	(revision 38521)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ImageIndex.c	(revision 38522)
@@ -199,4 +199,5 @@
   
   // extend the storage arrays
+  // no reason to extend 'found'
   REALLOCATE (index->imageID,  IDTYPE, index->Nimage + Nimages);
   REALLOCATE (index->externID, IDTYPE, index->Nimage + Nimages);
@@ -226,4 +227,5 @@
   ALLOCATE (index->imageID,  IDTYPE, 1);
   ALLOCATE (index->externID, IDTYPE, 1);
+  ALLOCATE (index->found, char, 1);
   index->Nimage = 0;
 
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadData.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadData.c	(revision 38521)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadData.c	(revision 38522)
@@ -5,7 +5,6 @@
 
 // examine the header sets and set the Image entries for the the valid images
-int LoadData (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, int Nimages, AddstarClientOptions *options) {
+int LoadData (FILE *f, AddstarFile *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, int Nimages, AddstarClientOptions *options) {
 
-  char *name;
   off_t Nskip, Nvalid, NVALID;
   int i, j, Nhead, Ndata;
@@ -22,11 +21,4 @@
     REALLOCATE (images[0], Image, NVALID);
   }    
-
-  // find image rootname
-  if (USE_NAME) {
-      name = filebasename (USE_NAME);
-  } else {
-      name = filebasename (file);
-  }
 
   // if zero points are calculated for the full exposure using more than just the matched chip header,
@@ -58,7 +50,7 @@
     // XXX use something to set the chip name? EXTNAME?
     if (!strcmp(headerSets[i].exthead, "PHU") && (Nimages == 1)) {
-      snprintf (images[0][Nvalid].name, DVO_IMAGE_NAME_LEN, "%s", name);
+      snprintf (images[0][Nvalid].name, DVO_IMAGE_NAME_LEN, "%s", file->imagename);
     } else {
-      snprintf (images[0][Nvalid].name, DVO_IMAGE_NAME_LEN, "%s[%s]", name, headerSets[i].exthead);
+      snprintf (images[0][Nvalid].name, DVO_IMAGE_NAME_LEN, "%s[%s]", file->imagename, headerSets[i].exthead);
     }
 
@@ -117,8 +109,6 @@
       stars[0][i].measure.Map += OFFSET_ZPT;
     }
-
   }
 
-  free (name);
   *nvalid = Nvalid;
   return (TRUE);
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataPMM.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataPMM.c	(revision 38521)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataPMM.c	(revision 38522)
@@ -15,8 +15,8 @@
 # define MAG_INDEX_ASC 22
 
-int LoadDataPMM (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars) {
+int LoadDataPMM (FILE *f, char *imagename, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars) {
 
   off_t Nvalid, NVALID;
-  char *name, *buffer;
+  char *buffer;
   int i, fd, Nbyte, Nline, code;
   double ra, dec, mag, airmass, az, ZeroPoint, ZeroPt;
@@ -38,14 +38,11 @@
   }    
 
-  // find image rootname
-  name = filebasename (file);
-
   // there is only one PMM image per file
-  if (VERBOSE) fprintf (stderr, "reading data for %s\n", file);
+  if (VERBOSE) fprintf (stderr, "reading data for %s\n", imagename);
 
   ZeroPt = GetZeroPoint();
 
   // need to get the metadata from the PMM_CCD_TABLE
-  photcode = LoadMetadataPMM (name, &images[0][Nvalid]);
+  photcode = LoadMetadataPMM (imagename, &images[0][Nvalid]);
   code = photcode[0].code;
   ZeroPoint = 0.001*photcode[0].C;
@@ -121,5 +118,4 @@
 
   free (inStars);
-  free (name);
   *nvalid = Nvalid + 1;
 
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataSDSS.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataSDSS.c	(revision 38521)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataSDSS.c	(revision 38522)
@@ -4,8 +4,7 @@
 // there should only be a single data set (phu + table) in this file
 // each SDSS data set corresponds to 5 images (ugriz)
-int LoadDataSDSS (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t Nimages) {
+int LoadDataSDSS (FILE *f, char *imagename, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t Nimages) {
 
   off_t Nskip, Nvalid, NVALID;
-  char *name;
   int j, Nhead, Ndata;
   unsigned int Ninstars;
@@ -21,7 +20,4 @@
     REALLOCATE (images[0], Image, NVALID);
   }    
-
-  // find image rootname
-  name = filebasename (file);
 
   // there is only one SDSS image per file (TRUE?)
@@ -40,8 +36,7 @@
 	 
   // XXX I think this is an error?  should this be &images[0][Nvalid] ??
-  inStars = ReadStarsSDSS (f, name, headers[Nhead], headers[Ndata], images[0], &Nvalid, &Ninstars);
+  inStars = ReadStarsSDSS (f, imagename, headers[Nhead], headers[Ndata], images[0], &Nvalid, &Ninstars);
   *stars = MergeStars (*stars, Nstars, inStars, Ninstars);
 
-  free (name);
   *nvalid = Nvalid;
   return (TRUE);
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataUKIRT.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataUKIRT.c	(revision 38521)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataUKIRT.c	(revision 38522)
@@ -3,8 +3,8 @@
 // examine the header sets and set the Image entries for the the valid images
 // UKIRT data has the WCS/image metadata header intermixed with the bintable header
-int LoadDataUKIRT (FILE *f, char *file, Image **images, off_t *nimages, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t NheaderSets) {
+
+int LoadDataUKIRT (FILE *f, char *imagename, Image **images, off_t *nimages, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t NheaderSets) {
 
   off_t Nskip, Nvalid, NVALID;
-  char *name;
   int i, j, Nhead, Ndata;
   unsigned int Ninstars;
@@ -22,7 +22,4 @@
   }    
 
-  // find image rootname
-  name = filebasename (file);
-
   // validate the number of headers sets == 4
   for (i = 0; i < NheaderSets; i++) {
@@ -38,5 +35,5 @@
     fseeko (f, Nskip, SEEK_SET); 
 
-    inStars = ReadStarsUKIRT (f, name, headers[Nhead], images[0], &Nvalid, &Ninstars);
+    inStars = ReadStarsUKIRT (f, imagename, headers[Nhead], images[0], &Nvalid, &Ninstars);
     *stars = MergeStars (*stars, Nstars, inStars, Ninstars);
 
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadFilenames.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadFilenames.c	(revision 38522)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadFilenames.c	(revision 38522)
@@ -0,0 +1,91 @@
+# include "addstar.h"
+
+AddstarFile *LoadFilenames (int *nfile, char *filename, AddstarClientOptions *options) {
+
+  int i, Nfile, NFILE;
+  glob_t globList;
+  AddstarFile *file;
+  char line[4096], word1[4096], word2[4096], sep[4096];
+
+  if (options[0].filelist) {
+    // read the list of input files from the supplied file
+    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, AddstarFile, NFILE);
+    for (i = 0; (scan_line (f, line) != EOF); i++) {
+      // find first non-whitespace char & skip commented lines
+      for (i = 0; OHANA_WHITESPACE (line[i]); i++);
+      if (line[i] == '#') continue;
+      if (line[i] == 0) continue;
+
+      // file lines may have:
+      // filename
+      // filename = nebname
+      // filename limited to 4096 chars
+      int Nfield = sscanf (line, "%s %s %s", word1, sep, word2);
+      if ((Nfield != 1) && (Nfield != 3)) {
+	fprintf (stderr, "invalid line: %s\n", line);
+	exit (3);
+      }
+
+      if (Nfield == 3) {
+	if (strcmp(sep, "=") && strcmp (sep, ":")) {
+	  fprintf (stderr, "ERROR: unexpected filename separator in list: %s\n", sep);
+	  exit (3);
+	}
+	file[i].filename  = strcreate (word1);
+	file[i].imagename = filebasename (word2);
+      } else {
+	file[i].filename  = strcreate (word1);
+	file[i].imagename = filebasename (word1);
+      }
+      CHECK_REALLOCATE (file, AddstarFile, NFILE, i, 10);
+    }
+    fclose (f);
+    Nfile = i;
+  } else {
+    // 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, AddstarFile, Nfile);
+      file->filename  = strcreate (filename);
+      file->imagename = USE_NAME ? filebasename (USE_NAME) : filebasename (filename);
+    } else {
+      Nfile = globList.gl_pathc;
+      if ((Nfile > 1) && USE_NAME) {
+	fprintf (stderr, "ERROR: -use-name supplied but more than one file matches glob\n");
+	exit (3);
+      }
+      ALLOCATE (file, AddstarFile, Nfile);
+      for (i = 0; i < Nfile; i++) {
+	file[i].filename  = strcreate (globList.gl_pathv[i]);
+	file[i].imagename = filebasename (file[i].filename);
+      }
+    }
+  }
+  *nfile = Nfile;
+  return (file);
+}
+
+void AddstarFileFree (AddstarFile *file, int Nfile) {
+
+  if (!file) return;
+
+  int i;
+  for (i = 0; i < Nfile; i++) {
+    free (file[i].filename);
+    free (file[i].imagename);
+  }
+  FREE (file);
+}
+
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadStars.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadStars.c	(revision 38521)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadStars.c	(revision 38522)
@@ -4,62 +4,8 @@
 
   off_t *extsize;
-  int i, Nfile, NFILE, mode;
-  char **file, line[4096];
-  FILE *f;
-  glob_t globList;
+  int i, Nfile, mode;
   Stars *stars;
 
-  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; (scan_line (f, line) != EOF); i++) {
-      // find first non-whitespace char & skip commented lines
-      for (i = 0; OHANA_WHITESPACE (line[i]); i++);
-      if (line[i] == '#') continue;
-      if (line[i] == 0) continue;
-
-      // file lines may have:
-      // filename
-      // filename = nebname
-      // filename limited to 4096 chars
-      Nfield = sscanf (line, "%s %s %s", word1, sep, word2);
-      if ((Nfield != 1) && (Nfield != 3)) {
-	fprintf (stderr, "invalid *line: %s
-      }
-
-      fprintf (stderr, "file: %s\n", line);
-      file[i] = strcreate (line);
-      if (i == NFILE - 1) {
-	NFILE += 10;
-	REALLOCATE (file, char *, NFILE);
-      }
-    }
-    Nfile = i;
-  } else {
-    // 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]);
-      }
-    }
-  }
+  AddstarFile *file = LoadFilenames (&Nfile, filename, options);
 
   *Nimages = 0;
@@ -69,7 +15,7 @@
 
   for (i = 0; i < Nfile; i++) {
-    f = fopen (file[i], "r");
+    FILE *f = fopen (file[i].filename, "r");
     if (f == NULL) {
-      fprintf (stderr, "can't read file %s, skipping\n", file[i]);
+      fprintf (stderr, "can't read file %s, skipping\n", file[i].filename);
       continue;
     }
@@ -77,5 +23,5 @@
     // load PMM data if specified (these are not stored as FITS-tables)
     if (PMM_CCD_TABLE != NULL) {
-      LoadDataPMM (f, file[i], images, Nimages, &stars, Nstars);
+      LoadDataPMM (f, file[i].imagename, images, Nimages, &stars, Nstars);
       continue;
     }
@@ -90,12 +36,12 @@
     headerSets = MatchHeaders (&extsize, &NheaderSets, mode, headers, Nheaders);
     if (headerSets == NULL) {
-      fprintf (stderr, "ERROR: can't read headers for %s\n", file[i]);
+      fprintf (stderr, "ERROR: can't read headers for %s\n", file[i].filename);
       goto next_file;
     }
     if (NheaderSets == 0) {
-      fprintf (stderr, "no object data in file %s, skipping\n", file[i]);
+      fprintf (stderr, "no object data in file %s, skipping\n", file[i].filename);
       goto next_file;
     }
-    if (VERBOSE) fprintf (stderr, "file %s has %d headers, including "OFF_T_FMT" images\n", file[i], Nheaders,  NheaderSets);
+    if (VERBOSE) fprintf (stderr, "file %s has %d headers, including "OFF_T_FMT" images\n", file[i].filename, Nheaders,  NheaderSets);
 
     /* supplied photcode is incompatible with multi-chip images */
@@ -112,5 +58,5 @@
     // if these are SDSS data, load with SDSS-specific wrapper
     if (headerSets[0].exttype && !strcmp (headerSets[0].exttype, "SDSS_OBJ")) {
-      LoadDataSDSS (f, file[i], images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets);
+      LoadDataSDSS (f, file[i].imagename, images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets);
       goto next_file;
     }
@@ -118,20 +64,9 @@
     // if these are SDSS data, load with SDSS-specific wrapper
     if (headerSets[0].exttype && !strcmp (headerSets[0].exttype, "UKIRT_OBJ")) {
-      LoadDataUKIRT (f, file[i], images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets);
+      LoadDataUKIRT (f, file[i].imagename, images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets);
       goto next_file;
     }
 
-    LoadData (f, file[i], images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets, options);
-
-    // XXX add a function to (optionally) load the extended source measurements
-    # if (0)
-    if (extSources) {
-      // not sure how to link the measurements here to the psf measurements above (though there is an ID in the det list)
-      LoadDataXSRC (f, file[i], images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets);
-    }
-    if (extFits) {
-      LoadDataXFIT (f, file[i], images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets);
-    }
-    # endif
+    LoadData (f, &file[i], images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets, options);
 
   next_file:
@@ -153,10 +88,7 @@
     exit (0);
   }
+  ohana_memcheck (TRUE);
 
-  for (i = 0; i < Nfile; i++) {
-    FREE (file[i]); 
-  }
-  FREE (file);
-
+  AddstarFileFree (file, Nfile);
   return stars;
 }
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadStarsUKIRT.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadStarsUKIRT.c	(revision 38521)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadStarsUKIRT.c	(revision 38522)
@@ -8,5 +8,5 @@
 // given a file with the pointer at the start of the table block and the 
 // corresponding image header, load the stars from the table
-Stars *ReadStarsUKIRT (FILE *f, char *name, Header *header, Image *images, off_t *nimages, unsigned int *nstars) {
+Stars *ReadStarsUKIRT (FILE *f, char *imagename, Header *header, Image *images, off_t *nimages, unsigned int *nstars) {
 
   off_t Nrow;
@@ -250,5 +250,5 @@
 
     // save the filename
-    snprintf (images[N].name, DVO_IMAGE_NAME_LEN, "%s[%02d]", name, detID);
+    snprintf (images[N].name, DVO_IMAGE_NAME_LEN, "%s[%02d]", imagename, detID);
     *nimages = N + 1;
   }
