Index: /trunk/psphot/src/psphotFindPeaks.c
===================================================================
--- /trunk/psphot/src/psphotFindPeaks.c	(revision 13165)
+++ /trunk/psphot/src/psphotFindPeaks.c	(revision 13166)
@@ -112,4 +112,18 @@
     }
 
+    // limit the total number of returned peak as specified
+    if (pass == 1) {
+	psArraySort (peaks, pmPeakSortBySN);
+	int NMAX = psMetadataLookupS32 (&status, recipe, "PEAKS_NMAX");
+	if (NMAX && (peaks->n > NMAX)) {
+	    psArray *tmpPeaks = psArrayAllocEmpty (NMAX);
+	    for (int i = 0; i < NMAX; i++) {
+		psArrayAdd (tmpPeaks, 100, peaks->data[i]);
+	    }
+	    psFree (peaks);
+	    peaks = tmpPeaks;
+	}
+    }    
+
     // optional dump of all peak data
     char *output = psMetadataLookupStr (&status, recipe, "PEAKS_OUTPUT_FILE");
@@ -118,5 +132,5 @@
     }
     psLogMsg ("psphot", PS_LOG_INFO, "%ld peaks: %f sec\n", peaks->n, psTimerMark ("psphot"));
-    //
+
     // If they asked us to return a set of pmFootprints, not a raw pmPeak list,
     // go ahead and find the footprints, and assign them their peaks.
