Index: branches/eam_branches/ipp-20110505/Ohana/src/getstar/src/getstar.c
===================================================================
--- branches/eam_branches/ipp-20110505/Ohana/src/getstar/src/getstar.c	(revision 31458)
+++ branches/eam_branches/ipp-20110505/Ohana/src/getstar/src/getstar.c	(revision 31467)
@@ -9,4 +9,5 @@
   Catalog output;
   FITS_DB db;
+  int code, Nsec, needMeas;
 
   args (argc, argv);
@@ -17,4 +18,8 @@
     
   SkyTableSetFilenames (sky, CATDIR, "cpt");
+
+  code = photcode[0].code;
+  Nsec = GetPhotcodeNsec (code);
+  needMeas = (Nsec == -1);
 
   // create an output catalog with the desired name and format options
@@ -58,5 +63,8 @@
 	catalog.filename = skylist[0].filename[i];
 	catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
-	catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+	catalog.catflags = LOAD_AVES | LOAD_SECF;
+	if (needMeas) {
+	    catalog.catflags |= LOAD_MEAS;
+	}
 
 	// an error exit status here is a significant error
@@ -89,5 +97,8 @@
 	catalog.filename = skylist[0].filename[i];
 	catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
-	catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+	catalog.catflags = LOAD_AVES | LOAD_SECF;
+	if (needMeas) {
+	    catalog.catflags |= LOAD_MEAS;
+	}
 
 	// an error exit status here is a significant error
Index: branches/eam_branches/ipp-20110505/Ohana/src/getstar/src/select_by_region.c
===================================================================
--- branches/eam_branches/ipp-20110505/Ohana/src/getstar/src/select_by_region.c	(revision 31458)
+++ branches/eam_branches/ipp-20110505/Ohana/src/getstar/src/select_by_region.c	(revision 31467)
@@ -4,6 +4,6 @@
 int select_by_region (Catalog *output, Catalog *catalog, SkyRegion *region, int start, int end) {
 
-  int i, j, n, Nm, offset, m, Nsecfilt, code, Nsec;
-  int Nave, NAVE, Nmeas, NMEAS;
+  int i, j, Nm, offset, m, Nsecfilt, code, Nsec;
+  int Nave, NAVE, Nmeas, NMEAS, needMeas;
   double R, D, AREA;
   float mag;
@@ -27,4 +27,5 @@
   code = photcode[0].code;
   Nsec = GetPhotcodeNsec (code);
+  needMeas = (Nsec == -1);
 
   /* select the average objects in this region */
@@ -67,9 +68,7 @@
 
     for (i = 0; i < catalog[0].Naverage; i++) {
-      n = catalog[0].measure[i].averef;
+      // n = catalog[0].measure[i].averef;
       mag = NAN;
-      if (Nsec != -1) {
-        mag = catalog[0].secfilt[i*Nsecfilt + Nsec].M;
-      } else {
+      if (needMeas) {
         offset = catalog[0].average[i].measureOffset;
         for (m = 0; m < catalog[0].average[i].Nmeasure; m++) {
@@ -79,4 +78,6 @@
           }
         }
+      } else {
+        mag = catalog[0].secfilt[i*Nsecfilt + Nsec].M;
       }
       if (isnan(mag)) continue;
@@ -102,5 +103,5 @@
 
   for (i = 0; i < catalog[0].Naverage; i++) {
-    n = catalog[0].measure[i].averef;
+    // n = catalog[0].measure[i].averef;
 
     R = catalog[0].average[i].R;
@@ -119,7 +120,5 @@
     if (MagLimitUse) {
       mag = NAN;
-      if (Nsec != -1) {
-        mag = catalog[0].secfilt[i*Nsecfilt + Nsec].M;
-      } else {
+      if (needMeas) {
         offset = catalog[0].average[i].measureOffset;
         for (m = 0; m < catalog[0].average[i].Nmeasure; m++) {
@@ -129,4 +128,6 @@
           }
         }
+      } else {
+        mag = catalog[0].secfilt[i*Nsecfilt + Nsec].M;
       }
       if (isnan(mag) || (mag > MagLimitValue)) continue;
@@ -142,10 +143,11 @@
     offset = catalog[0].average[i].measureOffset;
 
-    for (j = 0; j < catalog[0].average[i].Nmeasure; j++) {
-      output[0].measure[Nmeas] = catalog[0].measure[offset + j];
-      output[0].measure[Nmeas].averef = Nave;
-      Nmeas ++;
-
-      CHECK_REALLOCATE (output[0].measure, Measure, NMEAS, Nmeas, 1000);
+    if (needMeas) {
+      for (j = 0; j < catalog[0].average[i].Nmeasure; j++) {
+	output[0].measure[Nmeas] = catalog[0].measure[offset + j];
+	output[0].measure[Nmeas].averef = Nave;
+	Nmeas ++;
+	CHECK_REALLOCATE (output[0].measure, Measure, NMEAS, Nmeas, 1000);
+      }
     }
 
