Index: /branches/eam_branches/ipp-20211108/Ohana/src/opihi/cmd.astro/imfit.c
===================================================================
--- /branches/eam_branches/ipp-20211108/Ohana/src/opihi/cmd.astro/imfit.c	(revision 41961)
+++ /branches/eam_branches/ipp-20211108/Ohana/src/opihi/cmd.astro/imfit.c	(revision 41962)
@@ -18,4 +18,11 @@
     Insert = TRUE;
     if (Save) { gprint (GP_ERR, "-save and -insert are mutually exclusive\n"); free (Save); return (FALSE); }
+  }
+
+  int minIter = 5;
+  if ((N = get_argument (argc, argv, "-min-iter"))) {
+    remove_argument (N, &argc, argv);
+    minIter = atoi (argv[N]);
+    remove_argument (N, &argc, argv);
   }
 
@@ -131,5 +138,6 @@
       if (i + sx < 0) continue;
       if (i + sx >= Nx) continue;
-      if (*V > SatThreshold) goto next;
+      if (*V > SatThreshold) goto next; // skip pixels above threshold
+      if (!isfinite(*V)) goto next; // skip nan pixels
       dz[N] = (SQ(RDnoise) + MAX(0.0, *V/Gain)); // treat negative pixels as pure read noise
       if (dz[N] <= 0) goto next;
@@ -154,5 +162,5 @@
 
   // keep iterating if chisq is increasing or 
-  for (Niter = 0; (Niter < 25) && ((dchisq <= 0.0) || (dchisq > 0.1*(Npts - Npar))); Niter++) {
+  for (Niter = 0; (Niter < 25) && ((Niter < minIter) || ((dchisq <= 0.0) || (dchisq > 0.1*(Npts - Npar)))); Niter++) {
     chisq = mrq2dmin (x, y, z, dz, Npts, par, Npar, fitfunc, VERBOSE);
     dchisq = ochisq - chisq;
