From: Ian Jackson Date: Sun, 30 Dec 2007 17:18:58 +0000 (+0000) Subject: compute initial layout - not yet checked X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=moebius2.git;a=commitdiff_plain;h=f5fef8bc75d9d5658705763fa7c083ae75a501ba compute initial layout - not yet checked --- diff --git a/.bzrignore b/.bzrignore index 22710ca..51d35b4 100644 --- a/.bzrignore +++ b/.bzrignore @@ -1 +1,3 @@ minimise +primer +initial diff --git a/Makefile b/Makefile index d0e7f2e..fc74681 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -TARGETS=minimise +TARGETS= minimise primer initial CWARNS= -Wall -Wwrite-strings -Wpointer-arith -Werror @@ -7,11 +7,21 @@ OPTIMISE= -O2 CFLAGS= $(CWARNS) $(OPTIMISE) -g CXXFLAGS= $(CWARNS) $(OPTIMISE) -g +LIBGSL= -lgsl -lgslcblas + all: $(TARGETS) minimise: energy.o bgl.o common.o mgraph.o - $(CXX) $(CXXFLAGS) -o $@ $^ -lgsl -lgslcblas + $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBGSL) + +primer: primer.o common.o + $(CC) $(CFLAGS) -o $@ $^ $(LIBGSL) + +initial: generator primer sgtatham/z.typescript + ./$^ -o$@ clean: - rm -f *.o $(TARGETS) *.new + rm -f *.o $(TARGETS) *.new *.tmp rm -f best initial + +%.o:: common.h mgraph.h bgl.h diff --git a/common.c b/common.c index 9001025..b87dedb 100644 --- a/common.c +++ b/common.c @@ -45,3 +45,6 @@ void xprod(double r[D3], const double a[D3], const double b[D3]) { r[1]= a[2]*b[0] - a[0]*b[2]; r[2]= a[0]*b[1] - a[1]*b[0]; } + +void diee(const char *what) { perror(what); exit(16); } +void flushoutput(void) { if (fflush(stdout)||ferror(stdout)) diee("stdout"); } diff --git a/common.h b/common.h index f890f84..a642213 100644 --- a/common.h +++ b/common.h @@ -25,6 +25,9 @@ double hypotD2plus(const double p[D3], const double q[D3], double add); double magnD(const double pq[D3]); void xprod(double r[D3], const double a[D3], const double b[D3]); +void flushoutput(void); +void diee(const char *what); + #define FOR_COORD(k) \ for ((k)=0; (k)size == DIM); assert(x->stride == 1); diff --git a/generator b/generator new file mode 100755 index 0000000..1933c55 --- /dev/null +++ b/generator @@ -0,0 +1,48 @@ +#!/usr/bin/perl +die unless @ARGV==3; +($primer,$ztype,$output) = @ARGV; +$output =~ s/^\-o// or die "$output ?"; + +$gnuplot= "$output.gnuplot.tmp"; +$initdata= "$output.initdata.tmp"; + +open Z, "$ztype" or die "$ztype $!"; +open G, ">$gnuplot" or die $!; + +sub pg ($$) { printf G "%s(u,v) = %s\n", @_ or die $!; } + +for (;;) { + $!=0; defined($_= ) or die "$ztype $!"; + s/\r$//; + next unless m/^splot\s+([^,]+),([^,]+),([^,]+)\s*$/; + pg('x',$1); pg('y',$2); pg('z',$3); + last; +} + +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("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"; diff --git a/mgraph.h b/mgraph.h index 85577e9..a33014b 100644 --- a/mgraph.h +++ b/mgraph.h @@ -69,6 +69,8 @@ #define Y1 (1 << YSHIFT) #define YMASK ((Y-1) << YSHIFT) +#define DIM (N*D3) + #define V6 6 #define FOR_VERTEX(v) \ diff --git a/primer.c b/primer.c new file mode 100644 index 0000000..eaa3459 --- /dev/null +++ b/primer.c @@ -0,0 +1,28 @@ +/* + * Generates the repetitive part of the gnuplot input + * for generating the initial triangle vertices from SGT's + * model. + */ + +#include "common.h" +#include "mgraph.h" + +int main(int argc, const char **argv) { + int v, k; + + if (argc>1) { fputs("no args please\n",stderr); exit(8); } + + printf("print %d, %d, %d, %d, %d\n", DIM, N, X, Y, D3); + + FOR_VERTEX(v) { + int x= v & XMASK; /* distance along strip */ + int y= y >> YSHIFT; /* distance across strip */ + double u= y * 1.0 / (Y-1); + double v= x * M_PI / (X-1); /* SGT's u runs 0..pi along the strip */ + K printf("print %c(%.*g,%.*g)\n", + "xyz"[k], + DBL_DIG+2,u, DBL_DIG+2,v); + } + flushoutput(); + return 0; +}