forked from fricas/fricas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gnudraw.spad
85 lines (83 loc) · 3.72 KB
/
gnudraw.spad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
)abbrev package GDRAW GnuDraw
++ Author: Bill Page and David Cyganski
++ Date: June 25, 2008
++ Description:
++ This package provides support for gnuplot. These routines
++ generate output files contain gnuplot scripts that may be
++ processed directly by gnuplot. This is especially convenient
++ in the FriCAS wiki environment where gnuplot is called from
++ LaTeX via gnuplottex.
EF ==> Expression Float
SBF ==> SegmentBinding Float
DROP ==> DrawOption
DROP0 ==> DrawOptionFunctions0
STR ==> String
LDF ==> List DoubleFloat
GnuDraw(): with
gnuDraw:(EF, SBF, STR, List DROP)->Void
++ \spad{gnuDraw} provides 2d plotting with options
gnuDraw:(LDF,LDF, STR, List DROP)->Void
++ \spad{gnuDraw} provides 2d plotting from list of values with options
gnuDraw:(EF, SBF, STR)->Void
++ \spad{gnuDraw} provides 2d plotting, default options
gnuDraw:(LDF,LDF, STR)->Void
++ \spad{gnuDraw} provides 2d plotting from list of values, default options
gnuDraw:(EF, SBF, SBF, STR, List DROP)->Void
++ \spad{gnuDraw} provides 3d surface plotting with options
gnuDraw:(EF, SBF, SBF, STR)->Void
++ \spad{gnuDraw} provides 3d surface plotting, default options
== add
-- 2-d plotting
gnuDraw(f:EF,segbind:SBF,filename:STR,opts:List DROP):Void ==
import TwoDimensionalViewport, GraphImage, TopLevelDrawFunctions EF
f1:TextFile:=open(filename::FileName,"output")
-- handle optional parameters
writeLine!(f1,concat(["set title _"",title(opts,"")$DROP0,"_""]))
writeLine!(f1,"plot '-' title '' lw 3 with lines")
-- extract data as List List Point DoubleFloat
p2:=pointLists(makeObject(f, segbind, opts));
for p1 in p2 repeat
for p in p1 repeat
writeLine!(f1,concat([unparse(convert(p.1)@InputForm)," ",
unparse(convert(p.2)@InputForm)]))
writeLine!(f1); -- blank line need to mark a "branch"
close! f1
gnuDraw(l1:LDF,l2:LDF,filename:STR,opts:List DROP):Void ==
import TwoDimensionalViewport, GraphImage, TopLevelDrawFunctionsForPoints
f1:TextFile:=open(filename::FileName,"output")
-- handle optional parameters
writeLine!(f1,concat(["set title _"",title(opts,"")$DROP0,"_""]))
writeLine!(f1,"plot '-' title '' lw 3 with lines")
-- extract data as List List Point DoubleFloat
lp := [point([x, y])$Point(DoubleFloat) for x in l1 for y in l2]
p2 := pointLists(makeGraphImage([lp]))
for p1 in p2 repeat
for p in p1 repeat
writeLine!(f1,concat([unparse(convert(p.1)@InputForm)," ",
unparse(convert(p.2)@InputForm)]))
writeLine!(f1); -- blank line need to mark a "branch"
close! f1
-- default title is ""
gnuDraw(f:EF,segbind:SBF,filename:STR):Void ==
gnuDraw(f,segbind,filename,[title("")$DROP])
gnuDraw(l1:LDF,l2:LDF,filename:STR):Void ==
gnuDraw(l1,l2,filename,[title("")$DROP])
-- 3-d plotting
gnuDraw(f:EF,segbind1:SBF, segbind2:SBF, filename:STR, opts:List DROP):Void ==
import ThreeSpace DoubleFloat, TopLevelDrawFunctions EF
f1:TextFile:=open(filename::FileName,"output")
-- process optional parameters
writeLine!(f1,concat(["set title _"",title(opts,"")$DROP0,"_""]))
writeLine!(f1,"splot '-' title '' with pm3d")
-- extract data as List List Point DoubleFloat
p2 := mesh(makeObject(f, segbind1, segbind2))
for p1 in p2 repeat
for p in p1 repeat
writeLine!(f1,concat([unparse(convert(p.1)@InputForm)," ",
unparse(convert(p.2)@InputForm)," ",
unparse(convert(p.3)@InputForm)]))
writeLine!(f1); -- blank line need to mark a "branch"
close! f1
-- default title is ""
gnuDraw(f:EF,segbind1:SBF, segbind2:SBF, filename:STR):Void ==
gnuDraw(f,segbind1,segbind2,filename,[title("")$DROP])