chiark / gitweb /
better machinery; before make view interpolate-compatible
[moebius2.git] / interpolate.c
index 6f519e414a2d35664a443babb6b665f1b3cae4cd..d9d391009ca587894e2519d01d0aa5e2671cf44f 100644 (file)
@@ -16,35 +16,46 @@ static void characterise_input(void) {
   
   r= fstat(0,&stab);  if (r) diee("fstat input to find length");
 
-  if (!stab.st_size || stab.st_size % sizeof(double) ||
+  if (!stab.st_size || stab.st_size % (sizeof(double)*D3) ||
       stab.st_size > INT_MAX)
     fail("input file is not reasonable whole number of doubles\n");
 
-  oldsz= stab.st_size / sizeof(double);
+  oldsz= stab.st_size / (sizeof(double)*D3);
   for (shift=1;
-       shift > XBITS+1 && shift > YBITS+1;
+       shift < XBITS+1 && shift < YBITS+1;
        shift++) {
     oldxbits= XBITS-1;
     oldybits= YBITS-1;
     oldx=  1<<oldxbits;
     oldy= (1<<oldybits)-1;
+    fprintf(stderr,"sizeof(double)=%d XYBITS=%d,%d, XY=%d*%d=%d"
+           " oldsz=%d shift=%d oldxybits=%d,%d oldxy=%d*%d=%d\n",
+           (int)sizeof(double), XBITS,YBITS, X,Y,N,
+           oldsz,shift,oldxbits,oldybits,oldx,oldy,oldx*oldy);
     if (oldx*oldy == oldsz) goto found;
   }
   fail("input file size cannot be interpolated to target file size\n");
 
  found:
   inc= 1<<shift;
+  fprintf(stderr,"inc=%d\n",inc);
 }
 
 static void read_input(void) {
-  int x,y;
+  int x,y, ox,oy, v,ov;
   
-  for (y=0; y<Y; y+=inc)
-    for (x=0; x<X; x+=inc) {
+  for (oy=y=0; y<Y; oy++, y+=inc) {
+    fprintf(stderr, "y=%2d>%2d", oy,y);
+    for (ox=x=0; x<X; ox++, x+=inc) {
       errno= 0;
-      if (fread(all.a[(y << YSHIFT) | x], sizeof(double), D3, stdin) != D3)
-       diee("read input");
+      ov= (oy << oldxbits) | ox;
+      v= (y << YSHIFT) | x;
+      fprintf(stderr, " 0%02o->0x%02x", ov, v);
+      if (fread(all.a[v], sizeof(double), D3, stdin) != D3)
+       diee("\nread input");
     }
+    fputc('\n',stderr);
+  }
 }
 
   /* We use GSL's interpolation functions.  Each xa array is simple