chiark / gitweb /
new energy calculation but anarres crashes
[moebius2.git] / sgtatham-regenerator
1 #!/usr/bin/perl
2 require 'library.pl';
3 die unless @ARGV==4;
4 ($prime,$zinput,$options,$output) = @ARGV;
5 $output =~ s/^\-o// or die "$output ?";
6 die if $prime =~ m/^\-/;
7 die if $zinput =~ m/^\-/;
8
9 die unless $options =~ m/^\-([gTa])$/;
10 $ztype= $1;
11
12 $gnuplot= "$output.gnuplot.tmp";
13 $initdata= "$output.initdata.tmp";
14
15 open G, ">$gnuplot" or die $!;
16
17 open Z, "$zinput" or die "$zinput $!";
18
19 sub pg ($$) { printf G "%s(u,v) = %s\n", @_ or die $!; }
20 for (;;) {
21     $!=0; defined($_= <Z>) or die "$zinput $!";
22     s/\r$//;
23     if ($ztype eq 'g') {
24         print G or die $!;
25         last if m/^END$/;
26     } elsif ($ztype eq 'T') {
27         next unless m/^splot\s+([^,]+),([^,]+),([^,]+)\s*$/;
28         pg('x',$1); pg('y',$2); pg('z',$3);
29         last;
30     }
31 }
32
33 printf G "set print \"-\"\n" or die $!;
34
35 sub initdata_prime_point_callback ($$$$) {
36     my ($u,$v,$comment,$floatformat) = @_; # SGT's coordinates
37     for ($k=0; $k<3; $k++) {
38         printf(G "print %s( $floatformat, $floatformat ) ;%s\n",
39                qw(x y z)[$k], $u, $v, $comment)
40             or die $!;
41     }
42 }
43
44 sub initdata_return_vertex_transform () {
45     $vertex[1] *= -1;
46 }
47
48 initdata_process_prime();
49
50 close G or die $!;
51
52 run("gnuplot $gnuplot >$initdata");
53
54 make_initdata();