Index: /branches/eam_branches/ipp-20111122/Ohana/src/addstar/include/supercos.h
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/addstar/include/supercos.h	(revision 33005)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/addstar/include/supercos.h	(revision 33006)
@@ -76,5 +76,5 @@
 } FullDetection;
 
-AddstarClientOptions args_loadsupercos (int argc, char **argv, AddstarClientOptions options);
+AddstarClientOptions args_loadsupercos (int *argc, char **argv, AddstarClientOptions options);
 Survey *loadsupercos_survey (char *filename, int *nsurvey);
 Image *loadsupercos_plates (Survey *survey, int Nsurvey, char *filename, int *nimage);
@@ -83,2 +83,3 @@
 int loadsupercos_sortStars (Stars *tstars, int Ntstars);
 int *loadsupercos_image_index (Image *image, int Nimage);
+int loadsupercos_getST (char *line, double *st);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/args_loadsupercos.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/args_loadsupercos.c	(revision 33005)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/args_loadsupercos.c	(revision 33006)
@@ -2,11 +2,11 @@
 static void help (void);
 
-AddstarClientOptions args_loadsupercos (int argc, char **argv, AddstarClientOptions options) {
+AddstarClientOptions args_loadsupercos (int *argc, char **argv, AddstarClientOptions options) {
   
   int N;
 
   /* check for help request */
-  if (get_argument (argc, argv, "-help") ||
-      get_argument (argc, argv, "-h")) {
+  if (get_argument (*argc, argv, "-help") ||
+      get_argument (*argc, argv, "-h")) {
     help ();
   }
@@ -28,26 +28,26 @@
   /* only add to existing regions */
   options.existing_regions = FALSE;
-  if ((N = get_argument (argc, argv, "-existing-regions"))) {
+  if ((N = get_argument (*argc, argv, "-existing-regions"))) {
     options.existing_regions = TRUE;
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
   }
   /* only add to existing objects */
   options.only_match = FALSE;
-  if ((N = get_argument (argc, argv, "-only-match"))) {
+  if ((N = get_argument (*argc, argv, "-only-match"))) {
     options.only_match = TRUE;
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
   }
   /* replace measurement, don't duplicate (ref/cat only) */
   options.replace = FALSE;
-  if ((N = get_argument (argc, argv, "-replace"))) {
+  if ((N = get_argument (*argc, argv, "-replace"))) {
     options.replace = TRUE;
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
   }
 
   /* extra error messages */
   VERBOSE = FALSE;
-  if ((N = get_argument (argc, argv, "-v"))) {
+  if ((N = get_argument (*argc, argv, "-v"))) {
     VERBOSE = TRUE;
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
   }
 
@@ -69,5 +69,5 @@
   DUMP = NULL;
 
-  if (argc < 4) {
+  if (*argc < 4) {
     fprintf (stderr, "USAGE: loadsupercos [options] (surveys.csv) (plates.csv) (detections.bin) [..more files]\n");
     exit (2);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/loadsupercos.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/loadsupercos.c	(revision 33005)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/loadsupercos.c	(revision 33006)
@@ -21,5 +21,5 @@
   // need to construct these options with args_loadWISE...
   options = ConfigInit (&argc, argv);
-  options = args_loadsupercos (argc, argv, options);
+  options = args_loadsupercos (&argc, argv, options);
 
   // load the full sky description table:
Index: /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/loadsupercos_ops.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/loadsupercos_ops.c	(revision 33005)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/loadsupercos_ops.c	(revision 33006)
@@ -4,5 +4,4 @@
 // this is defined in libohana/src/string.c but not generally exposed
 char *_parse_nextword_csv (char *string);
-
 
 int loadsupercos_getFilterInfo (char *line, char *emulsion, char *filterID) {
@@ -54,4 +53,33 @@
 }
 
+int loadsupercos_getST (char *line, double *st) {
+    
+  int i;
+  char *p1 = line;
+
+  // lstObs is field 20
+  for (i = 1; i < 20; i++) {
+    p1 = _parse_nextword_csv (p1);
+    if (!p1) {
+      fprintf (stderr, "error parsing filter info for line %s\n", line);
+      abort();
+    }
+  }
+  if (*p1 == ',') {
+    fprintf (stderr, "missing sidereal time info for line %s\n", line);
+    abort();
+  }
+
+  char hour[3], minute[3];
+  strncpy(hour, p1, 2); hour[2] = 0;
+  strncpy(minute, p1+2, 2); minute[2] = 0;
+
+  double minuteF = atof (minute);
+  double hourF = atof(hour);
+  *st = hourF + minuteF / 60.0;
+	
+  return TRUE;
+}
+
 int loadsupercos_sortStars (Stars *tstars, int Ntstars) {
 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/loadsupercos_plates.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/loadsupercos_plates.c	(revision 33005)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/loadsupercos_plates.c	(revision 33006)
@@ -51,4 +51,6 @@
     dparse_csv (&exptime, 21, line);
     dparse_csv (&sidtime, 20, line);
+    loadsupercos_getST (line, &sidtime);
+
     dparse_csv (&RAo, 14, line);
     dparse_csv (&DECo, 15, line);
@@ -56,5 +58,6 @@
     loadsupercos_getFilterInfo (line, emulsion, filterID);
 
-    altaz (&alt, &az, sidtime - RAo, DECo, survey[survey_id].latitude);
+    // need to pass sidereal time in degrees
+    altaz (&alt, &az, 15.0*sidtime - RAo, DECo, survey[survey_id].latitude);
 
     float scale = stepsize * survey[survey_id].plateScale / 1000.0 / 3600.0; // scale in degrees / pixel
@@ -82,5 +85,5 @@
     }
     image[Nimage].exptime = exptime * 60.0;
-    image[Nimage].sidtime = sidtime; // XXX double check units
+    image[Nimage].sidtime = sidtime; // sidereal time in hours
     image[Nimage].latitude = survey[survey_id].latitude;
 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/loadsupercos_rawdata.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/loadsupercos_rawdata.c	(revision 33005)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/loadsupercos_rawdata.c	(revision 33006)
@@ -3,5 +3,5 @@
 
 # define NBYTE 228
-# define NRECORDS 1000
+# define NRECORDS 1000000
 # define DEBUG 0
 
@@ -66,5 +66,6 @@
 	tstars[i].measure.Yccd = sstars[i].yCen;
 
-	tstars[i].measure.M = sstars[i].prfMag;
+	tstars[i].measure.M = sstars[i].sMag;
+	tstars[i].measure.Map = sstars[i].gMag;
 	tstars[i].measure.photFlags = sstars[i].class;
 
@@ -83,10 +84,11 @@
 	
 	double alt, az;
-	altaz (&alt, &az, sidtime - tstars[i].average.R, tstars[i].average.D, latitude);
-
-	tstars[i].measure.airmass = 1.0 / cos(alt);
+	altaz (&alt, &az, 15.0*sidtime - tstars[i].average.R, tstars[i].average.D, latitude);
+
+	tstars[i].measure.airmass = 1.0 / cos(RAD_DEG*alt);
 	tstars[i].measure.az = az;
 	tstars[i].measure.t = image[Ni].tzero;
 	tstars[i].measure.imageID = image[Ni].imageID;
+	tstars[i].measure.photcode = image[Ni].photcode;
 
 	tstars[i].measure.FWx = ToShortPixels(sstars[i].aU);
@@ -125,4 +127,6 @@
       if (DEBUG) fprintf (stderr, "writing to %s\n", skylist[0].filename[0]);
 
+      int this_image_id = tstars[i].measure.imageID;
+
       // loop over stars in this WISE region that are also in this output region
       Nstars = 0;
@@ -132,4 +136,6 @@
       for (j = i; j < Nrecords; j++) {
 	if (tstars[j].found != -1) continue;
+
+	if (tstars[j].measure.imageID != this_image_id) continue;
 
 	// check if in skyregion
@@ -151,5 +157,5 @@
       }
 	  
-      if (DEBUG) fprintf (stderr, "selected %d stars (%10.6f - %10.6f, %10.6f - %10.6f)\n", Nstars, 
+      if (VERBOSE) fprintf (stderr, "selected %d stars (%10.6f - %10.6f, %10.6f - %10.6f)\n", Nstars, 
 			  region[0].Rmin, region[0].Rmax, region[0].Dmin, region[0].Dmax);
 
