chiark / gitweb /
4dab49c4262a82936c65c4c05d000684700f3633
[moebius2.git] / generator
1 #!/usr/bin/perl
2 die unless @ARGV==4;
3 ($primer,$zinput,$options,$output) = @ARGV;
4 $output =~ s/^\-o// or die "$output ?";
5 die if $primer =~ m/^\-/;
6 die if $zinput =~ m/^\-/;
7
8 die unless $options =~ m/^\-([lT])$/;
9 $ztype= $1;
10
11 $gnuplot= "$output.gnuplot.tmp";
12 $initdata= "$output.initdata.tmp";
13
14 open Z, "$zinput" or die "$zinput $!";
15 open G, ">$gnuplot" or die $!;
16
17 sub pg ($$) { printf G "%s(u,v) = %s\n", @_ or die $!; }
18
19 for (;;) {
20     $!=0; defined($_= <Z>) or die "$zinput $!";
21     s/\r$//;
22     if ($ztype eq 'l') {
23         print G or die $!;
24         last if m/^END$/;
25     } elsif ($ztype eq 'T') {
26         next unless m/^splot\s+([^,]+),([^,]+),([^,]+)\s*$/;
27         pg('x',$1); pg('y',$2); pg('z',$3);
28         last;
29     }
30 }
31
32 printf G "set print \"-\"\n" or die $!;
33 close G or die $!;
34
35 sub run ($) {
36     print "    $_[0]\n";
37     $!=0; system($_[0]); die "$! $?" if $! or $?;
38 }
39
40 run("./$primer >>$gnuplot");
41 run("gnuplot $gnuplot >$initdata");
42
43 open I, "$initdata" or die "$initdata $!";
44 open B, ">$output.new" or die "$output.new $!";
45
46 $_= <I>;
47 m/^(\d+) .*/ or die "$_ ?";
48
49 $dim= $1;
50 for ($i=0; $i<$dim; $i++) {
51     $!=0; defined($_= <I>) or die "$initdata $!";
52     print B pack "d", $_ or die $!;
53 }
54
55 close B or die $!;
56 rename "$output.new",$output or die $!;
57
58 print "    wrote $output\n";