chiark / gitweb /
curveopt: fix handling of empty lines from findcurve
[moebius3.git] / findcurve.c
index 077f31c06c5c6a8815fcb3b2246820846d21eee0..055018f3bfb6abf87e5dba0aabbcf8dcb59dc906 100644 (file)
@@ -26,24 +26,43 @@ static int NP;
 static double *INPUT; /* dyanmic array, on main's stack */
 static double PREP[NPREP];
 
+static void printcore(const double *X) {
+  int i, j;
+  DECLARE_F_G;
+  CALCULATE_F_G;
+  printf("[");
+  for (i=0; i<NP; i++)
+    for (j=0; j<3; j++)
+      printf(" %25.18g,", POINT(i)[j]);
+  printf(" ]\n");
+}
+
 static void prepare(double X[] /* startpoint */) {
   /* fills in PREP and startpoint */
   PREPARE;
 }
 
+//#define DEBUG
+
 static double cb_Efunc(void *xp) {
   const double *X = xp;
+  int P;
   DECLARE_F_G;
   CALCULATE_F_G;
 
-  double e = 0;
-  int P;
-  for (P=0; P<NP-3; P++) {
-    double P_cost;
-    CALCULATE_COST;
-    e += P_cost;
+#ifdef DEBUG
+  int i,j;
+  printf(" Efunc\n");
+  for (j=0; j<3; j++) {
+    for (P=0; P<NP; P++)
+      printf(" %7.4f", POINT(P)[j]);
+    printf("\n");
   }
-  return e;
+  printf("             ");
+#endif
+
+  CALCULATE_COST;
+  return cost;
 }
 
 static void cb_step(const gsl_rng *rng, void *xp, double step_size) {
@@ -69,17 +88,6 @@ static double cb_metric(void *xp, void *yp) {
   return sqrt(s);
 }
 
-static void printcore(const double *X) {
-  int i, j;
-  DECLARE_F_G;
-  CALCULATE_F_G;
-  printf("[");
-  for (i=0; i<NP; i++)
-    for (j=0; j<3; j++)
-      printf(" %.18g,", POINT(i)[i]);
-  printf(" ]\n");
-}
-
 static void __attribute__((unused)) cb_print(void *xp) {
   const double *x = xp;
   printf("\n");
@@ -102,6 +110,7 @@ int main(int argc, const char *const *argv) {
   int i;
 
   NP = atoi(argv[1]);
+  epsilon = atof(argv[2]);
 
   gsl_rng *rng = gsl_rng_alloc(gsl_rng_ranlxd2);
 
@@ -112,7 +121,6 @@ int main(int argc, const char *const *argv) {
     /* NINPUT + 1 doubles: startpoint, epsilon for residual */
     for (i=0; i<NINPUT; i++)
       INPUT[i] = scan1double();
-    epsilon = scan1double();
 
     gsl_rng_set(rng,0);