Index: /branches/eam_branches/ipp-20111122/Ohana/src/opihi/cmd.astro/spex2dgas.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/opihi/cmd.astro/spex2dgas.c	(revision 32917)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/opihi/cmd.astro/spex2dgas.c	(revision 32918)
@@ -49,5 +49,5 @@
 void sortfriends (float *X, int *IDX1, int N);
 
-void get_pressure_gradient (int iObj) {
+void get_pressure_gradient (int iObj, int nCloseMax, float farFrac, int nearNeighbors, float maxPressure) {
 
   int i;
@@ -57,10 +57,14 @@
 
   // only use the first N friends
-  for (i = 0; (i < 10) && (i < object[iObj].Nindex); i++) {
+  for (i = 0; (i < object[iObj].Nindex); i++) {
     int jObj = object[iObj].index[i];
 
-    // only use the 0th object?
-    // if (jObj != 0) continue;
-
+    // some options:
+    // if the iterations are small, we should only worry about getting the near neighbors right
+    // if the iterations are large, we should add in more distant objects
+    if (nearNeighbors && (i >= nCloseMax)) break;
+    if (!nearNeighbors && (i >= nCloseMax)) {
+      if (drand48() > farFrac) continue;
+    }
 
     float Dtgt = object[iObj].Dtgt[i];
@@ -72,5 +76,5 @@
     // float dF = (Dcur < 0.01*Dtgt) ? -100.0 : (Dcur - Dtgt) / Dcur; XXX modified spring constant : too crazy
     float dF = (Dcur - Dtgt);
-    dF = MIN (100.0, MAX (-100.0, dF));
+    dF = MIN (maxPressure, MAX (-maxPressure, dF));
 
     float dPdXi = dF * dX / Dcur;
@@ -83,5 +87,7 @@
     }
 
-    // fprintf (stderr, "Dcur,Dtgt : %f %f : dX,dY,dP : %f %f : %f : %f %f\n", Dcur, Dtgt, dX, dY, dF, dPdXi, dPdYi);
+    if (i >= nCloseMax) {
+      fprintf (stderr, "Dcur,Dtgt : %f %f : dX,dY,dP : %f %f : %f : %f %f\n", Dcur, Dtgt, dX, dY, dF, dPdXi, dPdYi);
+    }
     dPdX += dPdXi;
     dPdY += dPdYi;
@@ -111,5 +117,5 @@
   srand48(B);
  
-  if (argc != 5) goto usage;
+  if (argc != 9) goto usage;
 
   if ((index1   = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) goto escape;
@@ -117,4 +123,8 @@
   if ((distance = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) goto escape;
   int Niter = atoi (argv[4]);
+  int nCloseMax = atoi (argv[5]);
+  int nCloseIter = atoi (argv[6]);
+  float farFrac = atof (argv[7]);
+  float maxPressure = atof (argv[8]);
   // XXX enforce matching lengths on the three vectors
 
@@ -204,7 +214,9 @@
     fprintf (stderr, "iter %d\n", iter);
 
+    int nearNeighbors = (iter < nCloseIter);
+
     // measure (dP/dX),(dP/dY) for all objects
     for (i = 0; i < Nobject; i++) {
-      get_pressure_gradient (i);
+      get_pressure_gradient (i, nCloseMax, farFrac, nearNeighbors, maxPressure);
       move_object (i);
     }
@@ -229,5 +241,5 @@
   
 usage:
-  gprint (GP_ERR, "USAGE: mkclusters (index1) (index2) (distance) scale\n");
+  gprint (GP_ERR, "USAGE: spex2dgas (index1) (index2) (distance) (Niter) (nCloseMax) (nCloseIter) (farFrac) (maxPressure)\n");
   return FALSE;
 }
