Index: /branches/czw_branch/20160809/Ohana/src/addstar/include/gaia.h
===================================================================
--- /branches/czw_branch/20160809/Ohana/src/addstar/include/gaia.h	(revision 39710)
+++ /branches/czw_branch/20160809/Ohana/src/addstar/include/gaia.h	(revision 39711)
@@ -15,5 +15,5 @@
 AddstarClientOptions args_loadgaia_client (int *argc, char **argv, AddstarClientOptions options);
 
-int loadgaia_table (SkyList *skylistInput, HostTable *hosts, char *filename, AddstarClientOptions *options);
+int loadgaia_table (int Nstart, int Nend, SkyList *skylistInput, HostTable *hosts, char **filename, AddstarClientOptions *options);
 
 Gaia_Stars *loadgaia_make_subset (Gaia_Stars *stars, int Nstars, int start, SkyRegion *region, int *nsubset);
@@ -38,5 +38,5 @@
 Gaia_Stars *loadgaia_load_stars (char *filename, int *nstars);
 
-Gaia_Stars *loadgaia_readstars (char *filename, int *nstars);
+Gaia_Stars *loadgaia_readstars (char *filename, Gaia_Stars *stars, int *nstars, AddstarClientOptions *options);
 
 int loadgaia_sortStars (Gaia_Stars *stars, int Nstars);
Index: /branches/czw_branch/20160809/Ohana/src/addstar/src/args_loadgaia.c
===================================================================
--- /branches/czw_branch/20160809/Ohana/src/addstar/src/args_loadgaia.c	(revision 39710)
+++ /branches/czw_branch/20160809/Ohana/src/addstar/src/args_loadgaia.c	(revision 39711)
@@ -82,4 +82,21 @@
     remove_argument (N, argc, argv);
   }
+  if (!options.photcode) {
+    fprintf (stderr, "ERROR: please supply a photcode name with [-p name]\n");
+    exit (2);
+  }
+
+  /* provide a time for dataset */
+  options.timeref = 0; 
+  if ((N = get_argument (*argc, argv, "-time"))) {
+    time_t tmp;
+    remove_argument (N, argc, argv);
+    if (!ohana_str_to_time (argv[N], &tmp)) { 
+      fprintf (stderr, "syntax error in time\n");
+      exit (1);
+    }
+    options.timeref = tmp;
+    remove_argument (N, argc, argv);
+  }
 
   /* extra error messages */
@@ -91,5 +108,5 @@
 
   /* other addstar options which cannot be used in loadgaia */
-  options.timeref = 0; 
+  // options.timeref = 0; 
   options.mosaic = FALSE;
   options.skip_missed = FALSE;
Index: /branches/czw_branch/20160809/Ohana/src/addstar/src/loadgaia.c
===================================================================
--- /branches/czw_branch/20160809/Ohana/src/addstar/src/loadgaia.c	(revision 39710)
+++ /branches/czw_branch/20160809/Ohana/src/addstar/src/loadgaia.c	(revision 39711)
@@ -11,5 +11,4 @@
 int main (int argc, char **argv) {
 
-  int i;
   SkyTable *sky;
   SkyList *skylist = NULL;
@@ -28,8 +27,17 @@
   skylist = SkyListByPatch (sky, -1, &UserPatch);
 
-  for (i = 1; i < argc; i++) {
-    fprintf (stderr, "loading %s\n", argv[i]);
-    loadgaia_table (skylist, NULL, argv[i], &options);
+  int Nstart = 1;
+  int Nend = argc;
+  while (Nstart < Nend) {
+    Nstart = loadgaia_table (Nstart, Nend, skylist, NULL, argv, &options);
   }
+
+  SkyTableFree (sky);
+  SkyListFree(skylist);
+  FreePhotcodeTable();
+  free (CATDIR);
+
+  ohana_memcheck (VERBOSE);
+  ohana_memdump (VERBOSE);
   exit (0);
 }  
Index: /branches/czw_branch/20160809/Ohana/src/addstar/src/loadgaia_readstars.c
===================================================================
--- /branches/czw_branch/20160809/Ohana/src/addstar/src/loadgaia_readstars.c	(revision 39710)
+++ /branches/czw_branch/20160809/Ohana/src/addstar/src/loadgaia_readstars.c	(revision 39711)
@@ -6,5 +6,5 @@
   myAssert (!strcmp(type, #TYPE), "wrong column type");
 
-Gaia_Stars *loadgaia_readstars (char *filename, int *nstars) {
+Gaia_Stars *loadgaia_readstars (char *filename, Gaia_Stars *stars, int *nstars, AddstarClientOptions *options) {
 
   // read in the full FITS files
@@ -24,5 +24,5 @@
     if (VERBOSE) fprintf (stderr, "can't read image subset header\n");
     fclose (f);
-    return NULL;
+    return stars;
   }
   if (!gfits_fread_matrix (f, &matrix, &header)) {
@@ -30,5 +30,5 @@
     gfits_free_header (&header);
     fclose (f);
-    return NULL;
+    return stars;
   }
 
@@ -38,9 +38,9 @@
   if (!gfits_load_header (f, &theader)) {
     fclose (f);
-    return NULL;
+    return stars;
   }
   if (!gfits_fread_ftable_data (f, &ftable, FALSE)) {
     fclose (f);
-    return (NULL);
+    return stars;
   }
 
@@ -53,5 +53,7 @@
   GET_COLUMN (gMag,    "PHOT_G_MEAN_MAG", 	 float);
   GET_COLUMN (dgFlux,  "PHOT_G_MEAN_FLUX_ERROR", float);
-  GET_COLUMN (Nobs,    "PHOT_G_N_OBS",           float);
+  GET_COLUMN (Nobs,    "PHOT_G_N_OBS",           short);
+
+  int NstarsIn = Nrow;
 
   // free the memory associated with the FITS files
@@ -63,6 +65,4 @@
   fclose (f);
 
-  int NstarsIn = matrix.Naxis[2];
-
   double Rmin = +360.0;
   double Rmax = -360.0;
@@ -70,9 +70,13 @@
   double Dmax = -360.0;
 
-  int Nstars = 0;
-  int NSTARS = 0.1*NstarsIn;
+  // start off where we finished on a previous read
+  int Nstars = *nstars;
+  int NSTARS = Nstars + 0.1*NstarsIn;
 
-  Gaia_Stars *stars = NULL;
-  ALLOCATE (stars, Gaia_Stars, NSTARS);
+  if (!stars) {
+    ALLOCATE (stars, Gaia_Stars, NSTARS);
+  } else {
+    REALLOCATE (stars, Gaia_Stars, NSTARS);
+  }
 
   for (i = 0; i < NstarsIn; i++) {
@@ -102,4 +106,7 @@
     stars[Nstars].measure.FluxPSF = flux;
     stars[Nstars].measure.dFluxPSF = dgFlux[i];
+
+    stars[Nstars].measure.photcode = options->photcode;
+    stars[Nstars].measure.t = options->timeref;
 
     Nstars ++;
Index: /branches/czw_branch/20160809/Ohana/src/addstar/src/loadgaia_table.c
===================================================================
--- /branches/czw_branch/20160809/Ohana/src/addstar/src/loadgaia_table.c	(revision 39710)
+++ /branches/czw_branch/20160809/Ohana/src/addstar/src/loadgaia_table.c	(revision 39711)
@@ -1,12 +1,22 @@
 # include "addstar.h"
 # include "gaia.h"
+# define NSTARS_MAX 1000000
 
-int loadgaia_table (SkyList *skylistInput, HostTable *hosts, char *filename, AddstarClientOptions *options) {
+int loadgaia_table (int Nstart, int Nend, SkyList *skylistInput, HostTable *hosts, char **filename, AddstarClientOptions *options) {
   OHANA_UNUSED_PARAM(hosts);
   
-  int i, Nstars;
+  int i;
 
-  Gaia_Stars *stars = loadgaia_readstars (filename, &Nstars);
-  if (!stars) return FALSE;
+  int Nstars = 0;
+  Gaia_Stars *stars = NULL;
+  for (i = Nstart; (Nstars < NSTARS_MAX) && (i < Nend); i++) {
+    // read the next file and append to the current set of stars
+    fprintf (stderr, "loading %s\n", filename[i]);
+    stars = loadgaia_readstars (filename[i], stars, &Nstars, options);
+  }
+  Nstart = i; // we pass back the entry for the next file to be read
+  if (!stars) return Nstart;
+
+  fprintf (stderr, "writing %d stars to dvo\n", Nstars);
 
   // sort the stars by RA
@@ -41,4 +51,6 @@
     // loadgaia_save_remote (subset, Nsubset, hosts, region, skylist[0].filename[0], options);
     loadgaia_catalog (subset, Nsubset, region, skylist[0].filename[0], options);
+    free (subset);
+    SkyListFree (skylist);
   }
 
@@ -47,5 +59,6 @@
   // harvest_all ();
 
-  return TRUE;
+  free (stars);
+  return Nstart;
 }
 
