chiark / gitweb /
can glue to old moebius too
authorIan Jackson <ian@davenant.relativity.greenend.org.uk>
Wed, 2 Jan 2008 00:10:26 +0000 (00:10 +0000)
committerIan Jackson <ian@davenant.relativity.greenend.org.uk>
Wed, 2 Jan 2008 00:10:26 +0000 (00:10 +0000)
approxmodel [new file with mode: 0755]
generator
library.pl [new file with mode: 0644]
primer.c

diff --git a/approxmodel b/approxmodel
new file mode 100755 (executable)
index 0000000..c1c7d36
--- /dev/null
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+require 'library.pl';
+die unless @ARGV==4;
+($primer,$instructions,$aout,$output) = @ARGV;
+$output =~ s/^\-o// or die "$output ?";
+die if $primer =~ m/^\-/;
+die if $instructions =~ m/^\-/;
+
+$aoutin= "$output.aoutin.tmp";
+$initdata= "$output.initdata.tmp";
+
+run("cat $instructions >$aoutin");
+run("./$primer 'pointmap ' ' ' ' ' ' ' ' ' ' # '  'echo ' ' ' u >>$aoutin");
+
+open A, ">>$aoutin" or die $!;
+print A "quit\n" or die $!;
+close A or die $!;
+    
+run("./$aout <$aoutin >$initdata");
+
+make_initdata();
index 4dab49c4262a82936c65c4c05d000684700f3633..6cdbab295e8d404f1db559e5fdc590e62d53e2af 100755 (executable)
--- a/generator
+++ b/generator
@@ -1,25 +1,26 @@
 #!/usr/bin/perl
+require 'library.pl';
 die unless @ARGV==4;
 ($primer,$zinput,$options,$output) = @ARGV;
 $output =~ s/^\-o// or die "$output ?";
 die if $primer =~ m/^\-/;
 die if $zinput =~ m/^\-/;
 
-die unless $options =~ m/^\-([lT])$/;
+die unless $options =~ m/^\-([gTa])$/;
 $ztype= $1;
 
 $gnuplot= "$output.gnuplot.tmp";
 $initdata= "$output.initdata.tmp";
 
-open Z, "$zinput" or die "$zinput $!";
 open G, ">$gnuplot" or die $!;
 
-sub pg ($$) { printf G "%s(u,v) = %s\n", @_ or die $!; }
+open Z, "$zinput" or die "$zinput $!";
 
+sub pg ($$) { printf G "%s(u,v) = %s\n", @_ or die $!; }
 for (;;) {
     $!=0; defined($_= <Z>) or die "$zinput $!";
     s/\r$//;
-    if ($ztype eq 'l') {
+    if ($ztype eq 'g') {
        print G or die $!;
        last if m/^END$/;
     } elsif ($ztype eq 'T') {
@@ -32,27 +33,8 @@ for (;;) {
 printf G "set print \"-\"\n" or die $!;
 close G or die $!;
 
-sub run ($) {
-    print "    $_[0]\n";
-    $!=0; system($_[0]); die "$! $?" if $! or $?;
-}
-
-run("./$primer >>$gnuplot");
+run("./$primer 'print ' '+-+' 'xyz' '( ' ', ' ');  # ' ".
+    "'print ' ', ' - >>$gnuplot");
 run("gnuplot $gnuplot >$initdata");
 
-open I, "$initdata" or die "$initdata $!";
-open B, ">$output.new" or die "$output.new $!";
-
-$_= <I>;
-m/^(\d+) .*/ or die "$_ ?";
-
-$dim= $1;
-for ($i=0; $i<$dim; $i++) {
-    $!=0; defined($_= <I>) or die "$initdata $!";
-    print B pack "d", $_ or die $!;
-}
-
-close B or die $!;
-rename "$output.new",$output or die $!;
-
-print "    wrote $output\n";
+make_initdata();
diff --git a/library.pl b/library.pl
new file mode 100644 (file)
index 0000000..cb7a59b
--- /dev/null
@@ -0,0 +1,29 @@
+sub run ($) {
+    print "    $_[0]\n";
+    $!=0; system($_[0]); die "$! $?" if $! or $?;
+}
+
+sub make_initdata () {
+    open I, "$initdata" or die "$initdata $!";
+    open B, ">$output.new" or die "$output.new $!";
+
+    $_= <I>;
+    m/^(\d+) .*/ or die "$_ ?";
+
+    $dim= $1;
+
+    for ($i=0; $i<$dim; $i++) {
+       for (;;) {
+           $!=0; defined($_= <I>) or die "$initdata $!";
+           last if m/\S/;
+       }
+       print B pack "d", $_ or die $!;
+    }
+
+    close B or die $!;
+    rename "$output.new",$output or die $!;
+
+    print "    wrote $output\n";
+}
+
+1;
index f023b10365881f25c3de3f4e7b9a23e3bc2c4586..1ec587dedbbf8a323df0a75e7421ff06fd0ced0a 100644 (file)
--- a/primer.c
+++ b/primer.c
@@ -11,9 +11,11 @@ int main(int argc, const char **argv) {
   static const int prec= DBL_DIG+2;
   int vi, k;
   
-  if (argc>1) { fputs("no args please\n",stderr); exit(8); }
+  if (argc!=10 || !strlen(argv[2]) || strlen(argv[2]) != strlen(argv[3]))
+    { fputs("wrong # args or lengths\n",stderr); exit(8); }
 
-  printf("print %d, %d, %d, %d, %d\n", DIM, N, X, Y, D3);
+  printf("%s%d%s%d%s%d%s%d%s%d\n",
+        argv[7], DIM, argv[8], N, argv[8], X, argv[8], Y, argv[8], D3);
   
   FOR_VERTEX(vi) {
     int x= vi & XMASK; /* distance along strip */
@@ -24,12 +26,18 @@ int main(int argc, const char **argv) {
      * So that corresponds to 0..X (since 0==X in our scheme).
      * Vertices with odd y coordinate are halfway to the next x coordinate.
      */
-    double v= (x*2 + (y&1)) * M_PI / (X*2);
+    double v= (x*2 + (y&1)) * 1.0 / (X*2);
 
-    K printf("print %c%c( %-*.*g, %-*.*g);  # %03x %2d %2d\n",
-            "+-+"[k], "xyz"[k],
-            prec+5,prec,u, prec+5,prec,v,
-            vi, x, y);
+    if (!strchr(argv[9],'u'))
+      v *= M_PI;
+    
+    K {
+      if (k >= strlen(argv[2])) break;
+      printf("%s%c%c%s%-*.*g%s%-*.*g%s%03x %2d %2d\n",
+            argv[1], argv[2][k], argv[3][k], argv[4],
+            prec+5,prec,u, argv[5], prec+5,prec,v,
+            argv[6], vi, x, y);
+    }
   }
   flushoutput();
   return 0;