diff options
| author | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
| commit | 37da2899f40661e3e9631e497da8dc59b971cbd0 (patch) | |
| tree | cbc6d4680e347d906f5fa7fca73214418741df72 /appl/math/graph0.b | |
| parent | 54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff) | |
20060303a
Diffstat (limited to 'appl/math/graph0.b')
| -rw-r--r-- | appl/math/graph0.b | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/appl/math/graph0.b b/appl/math/graph0.b new file mode 100644 index 00000000..1e016b51 --- /dev/null +++ b/appl/math/graph0.b @@ -0,0 +1,84 @@ +implement Graph0; + +include "sys.m"; + sys: Sys; + print: import sys; + +include "draw.m"; +include "tk.m"; + tk: Tk; + +include "bufio.m"; + bufio: Bufio; + Iobuf: import bufio; + +include "gr.m"; + gr: GR; + Plot: import gr; + +Graph0: module{ + init: fn(nil: ref Draw->Context, argv: list of string); +}; + + +plotfile(ctxt: ref Draw->Context, nil: list of string, filename: string){ + p := gr->open(ctxt,filename); + input := bufio->open(filename,bufio->OREAD); + if(input==nil){ + print("can't read %s",filename); + exit; + } + + n := 0; + maxn := 100; + x := array[maxn] of real; + y := array[maxn] of real; + while(1){ + xn := input.gett(" \t\n\r"); + if(xn==nil) + break; + yn := input.gett(" \t\n\r"); + if(yn==nil){ + print("after reading %d pairs, saw singleton\n",n); + exit; + } + if(n>=maxn){ + maxn *= 2; + newx := array[maxn] of real; + newy := array[maxn] of real; + for(i:=0; i<n; i++){ + newx[i] = x[i]; + newy[i] = y[i]; + } + x = newx; + y = newy; + } + x[n] = real xn; + y[n] = real yn; + n++; + } + if(n==0){ + print("empty input\n"); + exit; + } + + p.graph(x[0:n],y[0:n]); + p.pen(GR->CIRCLE); + p.graph(x[0:n],y[0:n]); + p.paint("",nil,"",nil); + p.bye(); +} + +init(ctxt: ref Draw->Context, argv: list of string){ + sys = load Sys Sys->PATH; + tk = load Tk Tk->PATH; + bufio = load Bufio Bufio->PATH; + if((gr = load GR GR->PATH) == nil){ + sys->print("%s: Can't load gr\n",hd argv); + exit; + } + + argv = tl argv; + if(argv!=nil) + plotfile(ctxt,argv,hd argv); +} |
