From 8dd86f878d8fd02ebcda87454065e3bb18d13432 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 2 Jan 2008 00:10:26 +0000 Subject: [PATCH] can glue to old moebius too --- approxmodel | 21 +++++++++++++++++++++ generator | 34 ++++++++-------------------------- library.pl | 29 +++++++++++++++++++++++++++++ primer.c | 22 +++++++++++++++------- 4 files changed, 73 insertions(+), 33 deletions(-) create mode 100755 approxmodel create mode 100644 library.pl diff --git a/approxmodel b/approxmodel new file mode 100755 index 0000000..c1c7d36 --- /dev/null +++ b/approxmodel @@ -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(); diff --git a/generator b/generator index 4dab49c..6cdbab2 100755 --- 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($_= ) 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 $!"; - -$_= ; -m/^(\d+) .*/ or die "$_ ?"; - -$dim= $1; -for ($i=0; $i<$dim; $i++) { - $!=0; defined($_= ) 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 index 0000000..cb7a59b --- /dev/null +++ b/library.pl @@ -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 $!"; + + $_= ; + m/^(\d+) .*/ or die "$_ ?"; + + $dim= $1; + + for ($i=0; $i<$dim; $i++) { + for (;;) { + $!=0; defined($_= ) 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; diff --git a/primer.c b/primer.c index f023b10..1ec587d 100644 --- 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; -- 2.30.2