Removed the `plot' collection, in preparation for adding the new one instead.
|
@ -648,8 +648,7 @@ mz-extras :+= (- (package: "swindle")
|
|||
(cond (not dr) => (srcfile: "tool.rkt" "swindle*.png")))
|
||||
|
||||
;; -------------------- plot
|
||||
plt-extras :+= (package: "plot" #:src? #t)
|
||||
(lib: "lib{plplot|fit}*")
|
||||
plt-extras :+= (package: "plot")
|
||||
|
||||
;; -------------------- mzcom
|
||||
plt-extras :+= (- (package: "mzcom" #:src? #t)
|
||||
|
|
|
@ -1151,24 +1151,7 @@ path/s is either such a string or a list of them.
|
|||
"collects/plai" responsible (jay)
|
||||
"collects/plai/private/gc-gui.rkt" drdr:command-line (gracket "-t" *)
|
||||
"collects/planet" responsible (robby)
|
||||
"collects/plot" responsible (eli)
|
||||
"collects/plot/demos/demo-1.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot/demos/demo-10.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot/demos/demo-2.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot/demos/demo-3.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot/demos/demo-4.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot/demos/demo-5.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot/demos/demo-6.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot/demos/demo-7.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot/demos/demo-8.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot/demos/fit-demo-1.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot/demos/fit-demo-2.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot/extend.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot/main.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot/plot-extend.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot/plot.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot/renderers.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot/view.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/plot" responsible (ntoronto)
|
||||
"collects/preprocessor" responsible (eli)
|
||||
"collects/profile" responsible (eli)
|
||||
"collects/r5rs" responsible (mflatt)
|
||||
|
@ -1574,7 +1557,6 @@ path/s is either such a string or a list of them.
|
|||
"collects/tests/planet/test-docs-complete.rkt" drdr:command-line (raco "make" *)
|
||||
"collects/tests/planet/thread-safe-resolver.rkt" drdr:command-line (raco "make" *) drdr:timeout 1000
|
||||
"collects/tests/planet/version.rkt" drdr:command-line (raco "make" *)
|
||||
"collects/tests/plot/run-tests.rkt" drdr:command-line (gracket-text "-t" *)
|
||||
"collects/tests/r6rs" responsible (mflatt)
|
||||
"collects/tests/racket" responsible (mflatt)
|
||||
"collects/tests/racket/all.rktl" drdr:command-line #f
|
||||
|
|
|
@ -150,7 +150,7 @@
|
|||
"expected a parenthesized sequence of property--value pairings after fields"
|
||||
stx)]))
|
||||
|
||||
;; Finally, parse optional inspector expr, again exploting
|
||||
;; Finally, parse optional inspector expr, again exploiting
|
||||
;; `parse-define-struct'.
|
||||
(define (parse-at-inspector id sup-id fields props rest)
|
||||
(let-values ([(_ __ ___ inspector-stx)
|
||||
|
|
|
@ -1,724 +0,0 @@
|
|||
#reader(lib"read.ss""wxme")WXME0108 ##
|
||||
#|
|
||||
This file uses the GRacket editor format.
|
||||
Open this file in DrRacket, or DrScheme version 4 or later
|
||||
to read it.
|
||||
|
||||
http://racket-lang.org/
|
||||
|#
|
||||
45 7 #"wxtext\0"
|
||||
3 1 6 #"wxtab\0"
|
||||
1 1 8 #"wxmedia\0"
|
||||
4 1 8 #"wximage\0"
|
||||
2 0 34 #"(lib \"syntax-browser.ss\" \"mrlib\")\0"
|
||||
1 0 16 #"drscheme:number\0"
|
||||
3 0 44 #"(lib \"number-snip.ss\" \"drscheme\" \"private\")\0"
|
||||
1 0 36 #"(lib \"comment-snip.ss\" \"framework\")\0"
|
||||
1 0 43 #"(lib \"collapsed-snipclass.ss\" \"framework\")\0"
|
||||
0 0 19 #"drscheme:sexp-snip\0"
|
||||
0 0 33 #"(lib \"bullet-snip.ss\" \"browser\")\0"
|
||||
0 0 29 #"drscheme:bindings-snipclass%\0"
|
||||
1 0 36 #"(lib \"cache-image-snip.ss\" \"mrlib\")\0"
|
||||
1 0 25 #"(lib \"matrix.ss\" \"htdp\")\0"
|
||||
1 0 22 #"drscheme:lambda-snip%\0"
|
||||
1 0 8 #"gb:core\0"
|
||||
5 0 10 #"gb:canvas\0"
|
||||
5 0 17 #"gb:editor-canvas\0"
|
||||
5 0 10 #"gb:slider\0"
|
||||
5 0 9 #"gb:gauge\0"
|
||||
5 0 11 #"gb:listbox\0"
|
||||
5 0 12 #"gb:radiobox\0"
|
||||
5 0 10 #"gb:choice\0"
|
||||
5 0 8 #"gb:text\0"
|
||||
5 0 11 #"gb:message\0"
|
||||
5 0 10 #"gb:button\0"
|
||||
5 0 12 #"gb:checkbox\0"
|
||||
5 0 18 #"gb:vertical-panel\0"
|
||||
5 0 9 #"gb:panel\0"
|
||||
5 0 20 #"gb:horizontal-panel\0"
|
||||
5 0 33 #"(lib \"readable.ss\" \"guibuilder\")\0"
|
||||
1 0 56
|
||||
(
|
||||
#"(lib \"hrule-snip.ss\" \"macro-debugger\" \"syntax-browse"
|
||||
#"r\")\0"
|
||||
) 1 0 18 #"java-comment-box%\0"
|
||||
1 0 23 #"java-interactions-box%\0"
|
||||
1 0 45 #"(lib \"image-snipr.ss\" \"slideshow\" \"private\")\0"
|
||||
1 0 26 #"drscheme:pict-value-snip%\0"
|
||||
0 0 38 #"(lib \"pict-snipclass.ss\" \"slideshow\")\0"
|
||||
2 0 55
|
||||
(
|
||||
#"(lib \"vertical-separator-snip.ss\" \"stepper\" \"private"
|
||||
#"\")\0"
|
||||
) 1 0 18 #"drscheme:xml-snip\0"
|
||||
1 0 31 #"(lib \"xml-snipclass.ss\" \"xml\")\0"
|
||||
1 0 21 #"drscheme:scheme-snip\0"
|
||||
2 0 34 #"(lib \"scheme-snipclass.ss\" \"xml\")\0"
|
||||
1 0 10 #"text-box%\0"
|
||||
1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0"
|
||||
1 0 15 #"test-case-box%\0"
|
||||
2 0 1 6 #"wxloc\0"
|
||||
00000000000 1 77 0 1 #"\0"
|
||||
0 75 1 #"\0"
|
||||
0 11 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9
|
||||
#"Standard\0"
|
||||
0 75 11 #" Monospace\0"
|
||||
0 14 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 24
|
||||
#"framework:default-color\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 15
|
||||
#"text:ports out\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 15
|
||||
#"text:ports err\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 17
|
||||
#"text:ports value\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 27
|
||||
#"Matching Parenthesis Style\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 37
|
||||
#"framework:syntax-color:scheme:symbol\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 38
|
||||
#"framework:syntax-color:scheme:keyword\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
|
||||
38 #"framework:syntax-color:scheme:comment\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 37
|
||||
#"framework:syntax-color:scheme:string\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 39
|
||||
#"framework:syntax-color:scheme:constant\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 42
|
||||
#"framework:syntax-color:scheme:parenthesis\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 36
|
||||
#"framework:syntax-color:scheme:error\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 36
|
||||
#"framework:syntax-color:scheme:other\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2
|
||||
38 #"drscheme:check-syntax:lexically-bound\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 31
|
||||
#"drscheme:check-syntax:imported\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 35
|
||||
#"profj:syntax-colors:scheme:keyword\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 2 37
|
||||
#"profj:syntax-colors:scheme:prim-type\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 2 38
|
||||
#"profj:syntax-colors:scheme:identifier\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 34
|
||||
#"profj:syntax-colors:scheme:string\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 35
|
||||
#"profj:syntax-colors:scheme:literal\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 35
|
||||
#"profj:syntax-colors:scheme:comment\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
|
||||
33 #"profj:syntax-colors:scheme:error\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 35
|
||||
#"profj:syntax-colors:scheme:default\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 37
|
||||
#"profj:syntax-colors:scheme:uncovered\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 35
|
||||
#"profj:syntax-colors:scheme:covered\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 0 139 0 0 0 -1 -1 4 1
|
||||
#"\0"
|
||||
0 70 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 4 4
|
||||
#"XML\0"
|
||||
0 70 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 8 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 8 24
|
||||
#"drscheme:text:ports err\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 4 1
|
||||
#"\0"
|
||||
0 71 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 4 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 255 0 0 0 -1 -1 4 1
|
||||
#"\0"
|
||||
0 71 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 255 0 0 0 -1 -1 4 1
|
||||
#"\0"
|
||||
0 71 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 100 0 0 0 0 -1 -1 0 1
|
||||
#"\0"
|
||||
0 75 11 #" Monospace\0"
|
||||
0 11 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 1
|
||||
#"\0"
|
||||
0 75 1 #"\0"
|
||||
0 12 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 1
|
||||
#"\0"
|
||||
0 75 11 #" Monospace\0"
|
||||
0 15 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2
|
||||
14 #"Html Standard\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 0 1
|
||||
#"\0"
|
||||
0 75 1 #"\0"
|
||||
0 10 90 -1 90 -1 3 -1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 1
|
||||
#"\0"
|
||||
0 75 12 #"Courier New\0"
|
||||
0 10 90 -1 90 -1 2 -1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 40 25 15 0 0 0 -1 -1 2 30
|
||||
#"drscheme:check-syntax:keyword\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 40 25 15 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 248 20 64 0 0 0 -1 -1 2 39
|
||||
#"drscheme:check-syntax:unbound-variable\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 248 20 64 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 36 36 140 0 0 0 -1 -1 2 37
|
||||
#"drscheme:check-syntax:bound-variable\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 36 36 140 0 0 0 -1 -1 2 32
|
||||
#"drscheme:check-syntax:primitive\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 36 36 140 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 51 135 39 0 0 0 -1 -1 2 31
|
||||
#"drscheme:check-syntax:constant\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 51 135 39 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 165 0 0 0 0 -1 -1 2 32
|
||||
#"drscheme:check-syntax:tail-call\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 165 0 0 0 0 -1 -1 2 27
|
||||
#"drscheme:check-syntax:base\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 70 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 71 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1 1 1 80 80 248 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 71 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1 1 1 80 80 248 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 71 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 100 0 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 94 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 200 0 0 0 0 0 -1 -1 0 1
|
||||
#"\0"
|
||||
0 -1 1 #"\0"
|
||||
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 200 0 0 0 0 0 -1 -1
|
||||
00000000002 0 00000000000 3 00000000000 125 0 26 3 12 #"#lang scheme"
|
||||
0 0 4 29 1 #"\n"
|
||||
0 0 22 3 1 #"("
|
||||
0 0 14 3 7 #"require"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 14 3 4 #"plot"
|
||||
0 0 22 3 1 #")"
|
||||
0 0 4 29 1 #"\n"
|
||||
0 0 4 29 1 #"\n"
|
||||
0 0 22 3 1 #"("
|
||||
0 0 14 3 4 #"plot"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 4 29 1 #"\n"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 22 3 1 #"("
|
||||
0 0 14 3 6 #"points"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 4 29 1 #"\n"
|
||||
0 0 4 3 2 #" "
|
||||
0 0 22 3 1 #"("
|
||||
0 0 14 3 3 #"map"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 22 3 1 #"("
|
||||
0 0 15 3 6 #"lambda"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 22 3 1 #"("
|
||||
0 0 14 3 1 #"x"
|
||||
0 0 22 3 1 #")"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 22 3 1 #"("
|
||||
0 0 14 3 6 #"vector"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 14 3 1 #"x"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 22 3 1 #"("
|
||||
0 0 14 3 6 #"random"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 14 3 1 #"x"
|
||||
0 0 22 3 3 #")))"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 17 3 25 #"; a random list of points"
|
||||
0 0 4 29 1 #"\n"
|
||||
0 0 4 3 7 #" "
|
||||
0 0 22 3 1 #"("
|
||||
0 0 14 3 10 #"build-list"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 20 3 2 #"30"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 22 3 1 #"("
|
||||
0 0 15 3 6 #"lambda"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 22 3 1 #"("
|
||||
0 0 14 3 1 #"x"
|
||||
0 0 22 3 1 #")"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 22 3 1 #"("
|
||||
0 0 14 3 4 #"add1"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 14 3 1 #"x"
|
||||
0 0 22 3 5 #")))))"
|
||||
0 0 4 29 1 #"\n"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 22 3 1 #"#"
|
||||
0 0 22 3 6 #":x-max"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 20 3 2 #"30"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 22 3 1 #"#"
|
||||
0 0 22 3 6 #":y-max"
|
||||
0 0 4 3 1 #" "
|
||||
0 0 20 3 2 #"30"
|
||||
0 0 22 3 1 #")"
|
||||
0 0 4 29 1 #"\n"
|
||||
0 0 4 29 1 #"\n"
|
||||
0 0 17 3 1 #";"
|
||||
0 0 17 3 1 #" "
|
||||
0 0 17 3 1 #"p"
|
||||
0 0 17 3 1 #"r"
|
||||
0 0 17 3 1 #"o"
|
||||
0 0 17 3 1 #"d"
|
||||
0 0 17 3 1 #"u"
|
||||
0 0 17 3 1 #"c"
|
||||
0 0 17 3 1 #"e"
|
||||
0 0 17 3 1 #"s"
|
||||
0 0 17 3 1 #" "
|
||||
0 0 17 3 1 #"s"
|
||||
0 0 17 3 1 #"o"
|
||||
0 0 17 3 1 #"m"
|
||||
0 0 17 3 1 #"e"
|
||||
0 0 17 3 1 #"t"
|
||||
0 0 17 3 1 #"h"
|
||||
0 0 17 3 1 #"i"
|
||||
0 0 17 3 1 #"n"
|
||||
0 0 17 3 1 #"g"
|
||||
0 0 17 3 1 #" "
|
||||
0 0 17 3 2 #"li"
|
||||
0 0 17 3 1 #"k"
|
||||
0 0 17 3 1 #"e"
|
||||
0 0 17 3 1 #" "
|
||||
0 0 17 3 1 #"t"
|
||||
0 0 17 3 1 #"h"
|
||||
0 0 17 3 1 #"i"
|
||||
0 0 17 3 1 #"s"
|
||||
0 0 17 3 1 #" "
|
||||
0 0 17 3 1 #"-"
|
||||
0 0 17 3 1 #" "
|
||||
0 0 17 3 1 #"t"
|
||||
0 0 17 3 1 #"h"
|
||||
0 0 17 3 1 #"e"
|
||||
0 0 17 3 1 #" "
|
||||
0 0 17 3 1 #"p"
|
||||
0 0 17 3 1 #"o"
|
||||
0 0 17 3 1 #"i"
|
||||
0 0 17 3 1 #"n"
|
||||
0 0 17 3 1 #"t"
|
||||
0 0 17 3 1 #"s"
|
||||
0 0 17 3 1 #" "
|
||||
0 0 17 3 1 #"a"
|
||||
0 0 17 3 1 #"r"
|
||||
0 0 17 3 1 #"e"
|
||||
0 0 17 3 1 #" "
|
||||
0 0 17 3 6 #"random"
|
||||
0 0 4 29 1 #"\n"
|
||||
0 0 17 3 1 #";"
|
||||
0 3 00000000037 4 1 #"\0"
|
||||
2 -1 -1 0 0 0 00000000013 500
|
||||
(
|
||||
#"\211PNG\r\n\32\n\0\0\0\rIHDR\0\0\3 \0\0\2X\b\2\0\0"
|
||||
#"\0\25\24\25'\0\0\30\24IDATx\234\355\335K\223\252\320\31\206"
|
||||
#"\321>)\a\374\377_\313\300A\6\246\214%\b\210/\267\375\255U\31"
|
||||
#"$\236\356\210[\204\247\271\270\377\365\367\376\17\0\200\234\377"
|
||||
#"\34\275\0\0\0\255\21X\0\0a\2\v\0 L`\1\0\204\t,\0\2000\201"
|
||||
#"\5\0\20&\260\0\0\302\4\26\0@\230\300\2\0\b\23X\0\0a\2"
|
||||
#"\v\0 L`\1\0\204\t,\0\2000\201\5\0\20&\260\0\0\302\4\26"
|
||||
#"\0@\230\300\2\0\b\23X\0\0a\2\v\0 L`\1\0\204\t,\0\2000"
|
||||
#"\201\5\0\20&\260\0\0\302\4\26\0@\230\300\2\0\b\23X\0\0a"
|
||||
#"\2\v\0 L`\1\0\204\t,\0\2000\201\5\0\20&\260\0\0\302\4"
|
||||
#"\26\0@\230\300\2\0\b\23X\0\0a\2\v\0 L`\1\0\204\t,\0"
|
||||
#"\2000\201\5\0\20&\260\0\0\302\4\26\0@\230\300\2\0\b\23X"
|
||||
#"\0\0a\2\v\0 L`\1\0\204\t,\0\2000\201\5\0\20&\260\0\0\302"
|
||||
#"\4\26\0@\230\300\2\0\b\23X\0\0a\2\v\0 L`\1\0\204\t,"
|
||||
#"\0\2000\201\5\0\20&\260\0\0\302\4\26\0@\230\300\2\0\b\23"
|
||||
#"X\0\0a\2\v\0 L`\1\0\204\t,\0\200\260\333\321\v\260\267"
|
||||
#"\356\326}\372\247\376\336O\374\374\350\277\2\0\f\375\323\r"
|
||||
#"\177\177\177\335\255\373TW\317\307\37\245e\270\0\200Y\2kQ]"
|
||||
#"\315\3760\0\300S\365k\260\276\252\253\277\277\277\376\336O\234d\4"
|
||||
#"\0\370\23X\0\0q\245\3\353\333\303W\0\0K\224\273\213\360\351q\246"
|
||||
#"\317M\202\0@\\\335\300z+*G\255\0\200\224\272\201\265\5\327\277"
|
||||
#"\3\300\n\355\35\343\20Xa+V\221\335\16\236"
|
||||
) 500
|
||||
(
|
||||
#"\355y\224\256\275\27\325\336\23\355\371\\\236\350\22\317\325"
|
||||
#"\336\23\355\371\\\236\350\307\347\332\347\211\366T\372\"\367O|"
|
||||
#"\27\3\0\360\v\201\5\0\20V(\260\34\224\2\0\366Q(\260&N"
|
||||
#"\374\r\37\377\364\303n6\4\0f\325\272\310\375\221M\257\20541"
|
||||
#"\205\363\333\17\233\354\31\0X\250\342d\317\257\207\246f_\376W\337"
|
||||
#"D\352\370\326\223\241\340\225\365\201W\326\a\3364\271J\324:\202"
|
||||
#"\365\360\325\273\330\336[\16\0l\255\3205X\0\0\373\20X\0\0a\2"
|
||||
#"\v\0 L`\1\233s-#\257\254\17T \260\0\0\302\4\26\0@\230\300"
|
||||
#"\2\0\b\23X\0\0a\2\v\0 L`\1\0\204\t,\0\2000\201\5\0"
|
||||
#"\20&\260\0\0\302\4\26\0@\230\300\2\0\b\23X\0\0a\2\v\0 "
|
||||
#"L`\1\0\204\335\216^\200\326t\267\356\355\221\376\336\37\262${"
|
||||
#"\32\276\352\341\203\25\306\1\200Y\243\273\214\366\b\254\260"
|
||||
#"\232\0311|\325\335\255\2539\24\0L\e\335e\34\262$\233r\212\20\0"
|
||||
#" L`\1\0\204\t,\0\2000\201\5\0\20&\260\0\0\302\4\26\0@\230"
|
||||
#"\300\2\0\b\23X\0\0a\2\v\0 L`\1\0\204\t,\0\2000\201\5"
|
||||
#"\0\20&\260\0\0\302\4\26\0@\230\300\2\0\b\23X\0\0a\2\v"
|
||||
#"\0 L`\1\0\204\t,\0\2000\201\5\0\20&\260\0\0\302\4\26\0@"
|
||||
#"\230\300\2\0\b\23X\0\0a\267\243\27\2405\335\255{{\244\277\367"
|
||||
#"\207,\311\236\206\257z\370`\205q\0`\326\350.\243=\2+\254fF\f_uw"
|
||||
#"\353j\16\5\0\323Fw\31\207,\311\246\234\"\4\0\b\23X\0\0a"
|
||||
#"\2\v\0 L`\1\0\204\t,\0\2000\201\5\0\20&\260\0\0\302\4"
|
||||
#"\26\0@\230\300\2\0\b\23X\0\0a\2\v\0 L`\1\0\204\t,\0"
|
||||
#"\2000\201"
|
||||
) 500
|
||||
(
|
||||
#"\5\0\20&\260\0\0\302\4\26\0@\230\300\2\0\b\23X\0\0a\2"
|
||||
#"\v\0 L`\1\0\204\t,\0\2000\201\5\0\20&\260\0\0\302\4\26"
|
||||
#"\0@\330\355\350\5hMw\353\336\36\351\357\375!K\262\247\341\253"
|
||||
#"\36>Xa\34\0\2305\272\313h\217\300\n\253\231\21\303W\335\335"
|
||||
#"\272\232C\1\300\264\321]\306!K\262)\247\b\1\0\302\4"
|
||||
#"\26\0@\230\300\2\0\b\23X\0\0a\2\v\0 L`\1\0\204\t,\0"
|
||||
#"\2000\201\5\0\20&\260\0\0\302\4\26\0@\230\300\2\0\b\23X"
|
||||
#"\0\0a\2\v\0 L`\1\0\204\t,\0\2000\201\5\0\20&\260\0\0\302"
|
||||
#"\4\26\0@\230\300\2\0\b\23X\0\0a\2\v\0 L`\1\0\204\t,"
|
||||
#"\0\2000\201\5\0\20v;z\1Z\323\335\272\267G\372{\177\310\222\354"
|
||||
#"i\370\252\207\17V\30\a\0f\215\3562\332#\260\302jf\304\360Uw\267"
|
||||
#"\256\346P\0000mt\227q\310\222l\312)B\0\2000\201\5\0\20&\260\0\0"
|
||||
#"\302\4\26\0@\230\300\2\0\b\23X\0\0a\2\v\0 L`\1\0\204"
|
||||
#"\t,\0\2000\201\5\0\20&\260\0\0\302\4\26\0@\230\300\2\0"
|
||||
#"\b\23X\0\0a\2\v\0 L`\1\0\204\335\216^\200ct\267\356\371"
|
||||
#"\337\373{\277\344'\247\177\f\0\340\251b`u\267\356\265\226\336\376"
|
||||
#"\347\247\237|\224\226\314\2\0f\225;E8\314\251\376\336\277\36\320"
|
||||
#"\372\364\223\375\275\377\364\223\0\0\257j\5\326\247\203U\303rZ"
|
||||
#"\376\223\0\0oj\5\26\0\300\16j\5\326\222k\255\206\377\23\0"
|
||||
#"\340+\265\2\v\0`\a\2\313\361*\0 \254z`\251+\0 \256\342\367`"
|
||||
#"=mQW\263\367\30\266\321sKn\245\234\376\2316\306\1\200Y5\357\276"
|
||||
#"\257\eX\e\35\273*\322\r\263/\323\241A\0\36\226\3542"
|
||||
) 500
|
||||
(
|
||||
#"\366Y\222=\25=E8\275\373\367eW\0\300/*\6\226\203+\0\300\246\312"
|
||||
#"\235\"\\XW\217\203X\303\237\24g\0\227\360z\"\302v\373[F"
|
||||
#"\357w\265\2\353\253<zk,\223=\3\\\302psm\3\276\234\321K)\24"
|
||||
#"X\217Ud\342\342\252\341\332\363z1\226u\v\340\374F\377\220~<\""
|
||||
#"\24\246}\32\37\243\267N\241\300Z\267ZX\231\0\256b\366\6\246"
|
||||
#"\331\237)\316\355_A\25/r\a\0^-\351N\215\365\25\201\5@\v"
|
||||
#"\276\272\207i\207\345\2418\201\5\0\245-?m*O\227+t\r\26\0\245"
|
||||
#"\270K\351\27F\357G\216`\1\0\204\t,\0\332\3648\364\342\0\314/"
|
||||
#"\214\336j\2\v\200f\351\203%F\257\254\352\357\275\351L~!\260"
|
||||
#"\0\0\302\4\26\0-Xx\203\233c0\243\226\214\236\241\373\212\300\2"
|
||||
#"\240\21\323\225\320\335:\2110mz\364\366\\\222\6\370\232\6\0"
|
||||
#"\332\361l,\323\25\177\353\323\234\203Fo\35\201\5@S^C\341\365"
|
||||
#"\21\2260z)\2\v\200\6\311\202_\30\275\337\271\6\v\0 L`"
|
||||
#"\1\0\204\t,\0\2000\201\5\0\20&\260\0\0\302\334E\0306:\235"
|
||||
#"\323!K\262\247\321/\240{{\260\3028\0000\253\310w\226\n\254\260"
|
||||
#"\232\31aBP\0\26\32\335e\34\262$\233r\212\20\0 L`\1\0\204\t"
|
||||
#",\0\2000\201\5\0\20&\260\0\0\302\4\26\0@\230\300\2\0\b"
|
||||
#"\23X\0\0a\2\v\0 L`\1\0\204\t,\0\2000\201\5\0\20&\260\0"
|
||||
#"\0\302\4\26\0@\230\300\2\0\b\23X\0\0a\2\v\0 L`\1\0"
|
||||
#"\204\t,\0\2000\201\5\0\20&\260\0\0\302\4\26\0@\230\300\2"
|
||||
#"\0\b\23X\0\0a\267\243\27\2405\335\255{{\244\277\367\207,\311"
|
||||
#"\236\206\257z\370`\205q\0`\326\350.\243=\2+\254fF\f"
|
||||
) 500
|
||||
(
|
||||
#"_uw\353j\16\5\0\323Fw\31\207,\311\246\234\"\4\0\b\23X\0"
|
||||
#"\0a\2\v\0 \3145X\0\325\275^\1\343\352I\210\20X\0u=\322"
|
||||
#"\3525\252\236\261\245\264\340\27\2\v\240\250\321\273}\237\217"
|
||||
#"\f\333\vX\3165X\0\25\315~\227J\177\357\373{\337\344\375\363"
|
||||
#"\260\3\201\5\0\20&\260\0\312Y\376U\300\16b\301:\2\v\200"
|
||||
#"\277\277\277\277\356\326i)H\21X\0\2649W\t\34H`\1\340nA\b"
|
||||
#"\23X\0\345\214^Y\365\270m\360\355A\23\267\303:\2\v\0 L`"
|
||||
#"\1T\264\344\366@\207\257`5\201\5\0\20&\260\0\212\2328\210\365"
|
||||
#"\370\312\6\207\257`5s\21\2\324\365\251\261\244\25\374H`\1"
|
||||
#"\224\246\245`\vN\21\2\0\204\t,\0\2000\201\5\0\20&\260\0\0"
|
||||
#"\302\4\26\0@\230\273\b\303F\247\367:dI\3664z\233\367\333\203"
|
||||
#"\25\306\1\200Y\263S\b\264A`\205\325\314\b\23\304\2\260"
|
||||
#"\320\350.\343\220%\331\224S\204\0\0a\2\v\0 L`\1\0\204\271\6"
|
||||
#"\v`s\356\371\200j\4\26\300\206\36i\365VT\243\17\2-\21X\0"
|
||||
#"[\371t;\355\343A\231\5\rs\r\26\300&f\277\254\244\277\367"
|
||||
#"\375\275o\362\6u@`\1\0\204\t,\200\274\345\337\265\353 \0264I`"
|
||||
#"\1\354\244\273uZ\n\212\20X\0{\220VP\212\300\2\0\b\3635\r"
|
||||
#"\0{\360u\fP\212#X\0y\313/]_~9<p!\2\v\0 L`\1lb\311A,"
|
||||
#"\207\257\240U\2\v\340\30\356+\204\206\271\310\35`+\317\203X&{"
|
||||
#"\206j\4\26\300\206^\347u~{\20h\230\300\2\330\234\242\202j"
|
||||
#"\\\203\5\0\20&\260\0\0\302\4\26\0@\230\300\2\0\b\23X\0"
|
||||
#"\0a\356\"\f\e~s`\205\273\207F\277/\321}\351\0\f\25\371\212"
|
||||
#"]\201\25V"
|
||||
) 500
|
||||
(
|
||||
#"3#\206\257\332\4 \0\214\32\335e\34\262$\233r\212\20\0 L`\1\0"
|
||||
#"\2049E\b\320\224\327\263-\316\324\303Q\4\26@#\206sH\233U\32"
|
||||
#"\216\"\260\0.\357SH\275N5-\263`O\2\v\340\332fo\332}f\226\306"
|
||||
#"\202\335\270\310\35\0 L`\1\0\204\t,\200\v[~\342\257\277"
|
||||
#"\367M~\235#\234\223k\260\0Z\363\f)\27]\301Q\34\301\2\0\b"
|
||||
#"\23X\0mr\370\n\16$\260\0.l\364\312\252\376\336\233\202\35\216%"
|
||||
#"\260\0\0\302\4\26\300\265-\271=\320\341+\330Y\351\273\b\227lq"
|
||||
#"\334\214\3\\\302\304\6\315\2673\260\203u\263\2147\274r\326"
|
||||
#"\r\254%o\352\353\6\313d^\300i}\232s\320\206\213}\274\365\375"
|
||||
#"\302\25\357\371[MfV\321\300z\274\251\323\357\350\333\352b2/\340"
|
||||
#"\344\206\373*\333+v0\3343.\231e\274\371\375i\305\300Zxfp\364g\36Y"
|
||||
#"\326\366:\1\\\232\r\24{\232\330'N\34\230\250\260'\255x\221{"
|
||||
#"\363o*\0\354`I'\r\317\27U\250\253\277\232\2015\253\310{\17\0;"
|
||||
#"\253\263\207\25X\0\300\327L4>\255\3425X\0@\334\272/6j\265\275\34"
|
||||
#"\301\2\0\bs\4+l\266\304\3338\367\274\360[\304&\376\265\215"
|
||||
#"q\0\340\351\323\251\300\307\203\317\177j\365\220\325\e\201\25V"
|
||||
#"\244\eV\177\317\5\0m\30\375\336\242\351\257l\370\373\374\255"
|
||||
#"\r[,\341\261\234\"\34Q\363r<\0 E`\1\0k\254\230h\274\316"
|
||||
#"!\f\2015n\342D\2623_\0\260\304\350\236\264Hc\271\6\353\243"
|
||||
#"\267\263\313\346L\205\306|\332\364\357\277$E|\332\247^z\314\255E"
|
||||
#"\317Z\32N\366\3747yIV\363{U\2015\345\265\262\e^\t\240\240OG"
|
||||
#"\243\35\245\336\310\304\300^w\314\255E\17\353f\31\37\376Vc"
|
||||
#"\376\225Z\t"
|
||||
) 500
|
||||
(
|
||||
#"\266V\355C5\301Ppf\323\353\247\2657nvH\2578\346\326\242\240&\207"
|
||||
#"\3135X@-\263\233\362\"\27\210\354f\335|\300'g-b\226\300\2\nY"
|
||||
#"\370\207\262\275#\23\254E,!\260\0\330\212\371\200)K`\1\325"
|
||||
#"\331\257\357\254\273u\355\215y{\257\210\37\t,\240\264\267Y\322"
|
||||
#"\330MKcn-bH`\1\245=N`\265w\a\323\371\2654\346\326\"\206\4"
|
||||
#"\26P\235\375\342vF\257\254\352\357\375\350t\277\227~#.\275\360lA`"
|
||||
#"\1\0\204\t,\240\220\205\267\252]\375h\312\251\254\230\17"
|
||||
#"\370\344\254E,!\260\200Z\246\367\216\217\e\334\354\27\367t"
|
||||
#"\305k\303\255E\3142\27!P\316\304\364\264v\212[\3704\257\353"
|
||||
#"\245\307\374\227\265\310\24\321\25\b,\240\242u\323\323\262\332s"
|
||||
#"x[\32\363uk\221)\242\213\20X@]\366g\373ko\314\277zE\23\25"
|
||||
#"\3658$\326\336\370\224\345\32,\0\330\203)\242K\21X\0\2609G\247"
|
||||
#"\252\21X\0\260-\223^\27$\260\0\340\0MNz\315\223\300\2\200"
|
||||
#"\303h\254V\271\2130lt\326\255C\226dO\243\e\210\267\a+\214\3"
|
||||
#"\300\267\nn\e\2134\345\277\202o\355v\\\303\370d(\0^-\334*"
|
||||
#"\326\334x6\371\252\235\"\4\0\b\23X\0\260\271\366&\275f\232"
|
||||
#"\300\2\200=\370\n\206R\\\344\16\0\37\257\274\316\36R\232"
|
||||
#"\230\17\307\341\253\306\b,\0\252\233\210\233x\367|:\216\245\256"
|
||||
#"\32#\260\0(m:\241\266\230\203YKU\340\32,\0\352Z\22O\256\235b\5"
|
||||
#"\201\5\0\20&\260\0(\312\34\314lG`\1\300\377\231\203\231\b"
|
||||
#"\201\5\0\377\363L+\215\305\217\4\26\0\374\317\363\214\241\e"
|
||||
#"\375\370\221\300\2\240\250\321+\253\372{?\254+\337\2\312\267"
|
||||
#"\4\26\0@\230\300\2\240.s0\263\21\201\5\0\20f\252\34\340"
|
||||
) 500
|
||||
(
|
||||
#"t^\217(T>r`\34\3661=\31\216\303W\254#\260\200\23y$\305\353"
|
||||
#"\376l\370H\5\306ag\23'\n\2159\353\b,\340,F\17\25<\36)\225"
|
||||
#"\27\306\341\20F\225,\327`\1\2470}\"\346q\347|\205\357~4\16"
|
||||
#"\320\6\201\5\34o\341e.\315\267\205q\200f\b,\0\2000\201\5"
|
||||
#"\234\224\2034\17\306\1\256H`\1g\364\250\nma\34\340\242\334E"
|
||||
#"\0306:\255\325!K\262\247\321\255\377\333\203\25\306\1\200YE"
|
||||
#"\376`\20Xa53\302\304\250\304Y\177\36\214\3\355\31\335e\34\262"
|
||||
#"$\233r\212\20\0 L`\1\307[\370\275\3\315\37\0315\16\320"
|
||||
#"\f\201\5\234\302l[\24\251\n\343\0mp\r\26\\[K\363"
|
||||
#"\1O\314\271[\252*\214\3\243\3349t-\2\v\256\352\323|\300"
|
||||
#"\177W\336\362\16\333\242\346\354{\306\201W\243\357\276U\342\344"
|
||||
#"\4\26\\\322\304|\300\177\27\337\362\276\235#\273\350\253\370"
|
||||
#"\235q\340\341\323aK\363\177\237\234\300\202\353\231=O\364\334\362"
|
||||
#"^t\263{\321\305\2163\0164\377ao\230\213\334\1\0\302\4\26"
|
||||
#"\\\314\362?U\27\336\363\17\234\223\17\373\245\t,hAw\353l^"
|
||||
#"\241\2\37\366\253\20Xpy\266\266P\204\17\373\205\b,\0\2000w"
|
||||
#"\21\302\305\f\277!\351\323U\32n,\202K\363a\2774G\260\0\0\302"
|
||||
#"\4\26\0@\230\300\202\353YrK\266S\6\320\0\37\366\353r\r\26"
|
||||
#"\234Hjj\24\267\32A\21>\354\247%\260\340\24>\315\334\374)\263"
|
||||
#"\236\177\32766\3313\360f\364\303\376g\26\302\323\23Xp\260O["
|
||||
#"\311\331\231\\_\177\340\365\21\2401\303\17\373\237\317\373\351"
|
||||
#"\t,8\322\3573\271\332\310B\21>\354\327\342\"w\0\2000\201\5"
|
||||
#"\2071\223+@\253\4\26\234\213\231\\\1\32 \260\340\2144\26"
|
||||
#"\300\245\t,\0\2000w"
|
||||
) 500
|
||||
(
|
||||
#"\21\206\r\17<T\270\357c\364p\213;\212\177a\270\200V\259B\377"
|
||||
#"\317v<\310|\5O\206b\241\205\3e<\201\2065\271\211s\212\20\0 L`"
|
||||
#"\301\221\314\344\n\320$\327`\301\361&\22j\243\213\25L\260\303"
|
||||
#"\205X]\271\"\201\5\a\3734\347\340F3\271\356\366D\360;\253+"
|
||||
#"\327%\260\340\24\366\231\271y\364P\331\354\254\322p\b\253+\227&"
|
||||
#"\260\340D6\335aL_\3135;\2534\354\311\352\312\325\271\310\35JX\270+"
|
||||
#"2\351!\27bu\345\314\4\26\0@\230\300\2\340\\\226\237\373s"
|
||||
#"\20\213\323r\r\26\24\365\334-\271\212\205\363\263\272r9\216`"
|
||||
#"\1\0\204\t,(\352q$\300\361\0.\301\212\312\345\b,\250\313N\213"
|
||||
#"s\32\275\262\252\277\367\3035\32675pZ\2\v\0 L`A\t\vo\266r<"
|
||||
#"\200\2230\17:W\347.B\250\342\261\307\232\236U\372\272\273\253\267"
|
||||
#"\235\361u_\bK\\}u\335\223\251\262\217\"\260\240\220\347Q\201"
|
||||
#"\226f\317\35]\376\253\277(\376\32]]\367d\364\216%\260"
|
||||
#"\240\226}f\225\336\315\247cr\246\4nCc\253\353\236L\225}8\201\5"
|
||||
#"\25\25\331\266\372\232\3576\24Y]\203L\225}\6.r\a\256j\311"
|
||||
#"\36Bc\1\207\20X\0\320\216\205\207\246\374\355\2615\201\5\\"
|
||||
#"\222\371\200\2013s\r\26\320\b\227B\303(Se\37\302\21,\0\2000G"
|
||||
#"\260\302F\347\317:dI\3664z\376\305\27?\262\263\321\257M\2\246"
|
||||
#"\277dx\177EN\331\v\254\260\363\254\301{2\3+\373\e\335g\214"
|
||||
#"\256u\326F8\325G`t\227q\310\222l\312)B\0\2000\201\5\\\225\371"
|
||||
#"\200a\310\314\356'\341\24!\314p1\331u5y\336\1f\265=\263\373U"
|
||||
#"\b,\2302\334H\3316\235\312\247\v\333\275M\24g\252\354\303\t,"
|
||||
#"\370hz\266T\e"
|
||||
) 500
|
||||
(
|
||||
#"\251\223\30\316\a\374g\27\2\246\312>\232\300\202q\263\263\245"
|
||||
#"j\254S\361^\300(\37\215\243\270\310\35F\230E\30\200_\b,\0"
|
||||
#"\2000\201\5\357\314\"\f\300\217\\\203\5\363L\225\n\300W"
|
||||
#"\34\301\2\0\b\23X0\317\201+\0\276\"\260\340\335\350\225U"
|
||||
#"\375\2757\2475\0\v\t,\0\2000\201\5#\314\"\234\345^K^Y"
|
||||
#"\37\250@`\301\32\366\20\0L\3605\rSF/\3049dI\32\366\251T\246"
|
||||
#"\207z\364\267f\337\235\257~\353\227Y\204\327-\336\231\375\37665\363"
|
||||
#"U\27\355\275\271\353\30\a\230&\260>\32=\1\344\254P\326\304x"
|
||||
#"\256\370\247\351wg\305o\255\233Ex\335\342\235\331\357o\323\247\377~"
|
||||
#"9\355\275\271\353\30\a\230\345\24\341\270O\233\t\337\334\35"
|
||||
#"\264d6\345\257~k\342\335Y\367[\317\37x\375\317\304O\376\370D"
|
||||
#"\347\264\347\333trM\276\250\25\214\3,!\260\216\267\333\366"
|
||||
#"\350T\e\276u\263)\17\177kxxi\3702g\237k\341%\355\323?\260\347"
|
||||
#"\23\245D.\344_\3626\315\376J\312v\243\367\366\242F\257\37\270\334"
|
||||
#"\213Z\361D\a\276\271\353\234j\364<Q)\2k\204\243\334\347\264\360"
|
||||
#"}y\333\276\357\366n\256[\274\262\2565\16\266\t\17VrXN`q\200"
|
||||
#"\335fS6m\363/\326\215^{c\336\336+\2v \2608\213\356\326\355\263"
|
||||
#"s\332\355\211\376Z<\306\276z\364\232\34\212\243\27\341\24\214"
|
||||
#"\3\214\22X\234\302\353\361\217o\177\353\264\373\373_\26\357\344"
|
||||
#"V\274MMj\370\245-\324\360J\16?\372\347\302\202\241uw\373\377\331"
|
||||
#"\312\0\300*\355\325\210\357\301\n[\261\212\234\355*\354}\236k"
|
||||
#"\341\302\314~\177\322\354\203+\236h\243\37X\370\223W\177\233F\177k"
|
||||
#"\371{\367\243\215F\357\300W\264\335\377\355\212'jr%\367D\207?\321_"
|
||||
#"\243\207'"
|
||||
) 500
|
||||
(
|
||||
#"\234\"\34\341JU\0\340\27\2\213c,\374F\250\327\277\237\26\206"
|
||||
#"\357\212\337\212\374\241\266n\361Nn\335\350\3556\346\273i\357\25"
|
||||
#"\255\323\344J\16\e\21X\343V|?5;\230\335\276\217\276A\273\35"
|
||||
#"\222\\\267x\5]q\34\34\330~\260\222\303B\2\213\303Lo\251?"
|
||||
#"m\246\343\363\341d\367\a\273=\321n\366|\233N\256\311\27\265\202q"
|
||||
#"\200%\334E8e\270\21I]\1\332\274\257.\206\35}|v\250\277\375"
|
||||
#"\225\325\277\265\302nO\264\233=\337\246\223k\362E\255\360\3138\330T"
|
||||
#"\362\246\311UB`%5\271\212\254c(xe}\340\225\365\2017M\256\22N\21"
|
||||
#"\2\0\204\t,\0\2000\201\5\0\20&\260\200\315\265wu\5\277\260"
|
||||
#">P\201\300\2\0\b\23X\0\0a\2\v\0 L`\1\0\204\t,\0\2000"
|
||||
#"\201\5\0\20&\260\0\0\302\4\26\0@\230\300\2\0\b\23X\0\0a"
|
||||
#"\2\v\0 L`\1\0\204\t,\0\2000\201\5\0\20v;z\1Z\323\335"
|
||||
#"\272\267G\372{\177\310\222\354i\370\252\207\17V\30\a\0f\215\356"
|
||||
#"2\332#\260\302jf\304\360Uw\267\256\346P\0000mt\227q\310\222l\312)B\0"
|
||||
#"\2000\201\5\0\20&\260\0\0\302\4\26\0@\230\300\2\0\b\23X"
|
||||
#"\0\0a\2\v\0 L`\1\0\204\t,\0\2000\201\5\0\20&\260\0\0\302"
|
||||
#"\4\26\0@\230\300\2\0\b\23X\0\0a\2\v\0 L`\1\0\204\t,"
|
||||
#"\0\2000\201\5\0\20&\260\0\0\302\4\26\0@\230\300\2\0\b\23"
|
||||
#"X\0\0a\2\v\0 L`\1\0\204\335\216^\200\326t\267\356\355\221"
|
||||
#"\376\336\37\262${\32\276\352\341\203\25\306\1\200Y\243\273\214"
|
||||
#"\366\b\254\260\232\0311|\325\335\255\2539\24\0L\e\335e\34\262"
|
||||
#"$\233r\212\20\0 L`\1\233k\362\317SV\263>P"
|
||||
) 500
|
||||
(
|
||||
#"\201\300\2\0\b\23X\0\0a\2\v\0 L`\1\0\204\t\254\343\355"
|
||||
#"v\275g\223\27\226\2667z{\276M\355\255\22\336\246K<\321\236\332"
|
||||
#"\e\275\366\236\250U\2\v\0 L`\1\0\204\t,\0\2000\201\5\0"
|
||||
#"\20&\260\0\0\302\376\231\2217\310=\27\0\260B{5\"\260\0\0\302"
|
||||
#"\234\"\4\0\b\23X\0\0a\2\v\0 L`\1\0\204\t,\0\2000\201"
|
||||
#"\5\0\20&\260\0\0\302\4\26\0@\230\300\2\0\b\23X\0\0a\267"
|
||||
#"\243\27\200\326<'d4\vSY\335\255\233~\367_g\355\264\236\264\352mn"
|
||||
#"\326\205\253\204\365\241I\23\23\365\216\276\343m\254\17\2\213"
|
||||
#"\244\327=\353\343\23r\351\217\a\337Z2\337\371[~YO\2324\214"
|
||||
#"\354O\331\375\266\2X\37\232\364\351\255\237}\374\322\353\203S"
|
||||
#"\204\304\274}Z\372{\337\337\373%{\\\332\360X\1f\17T\274\375"
|
||||
#"\200\365\244\210\321wy\270\316X\37\212ki?\"\260\310\370\364\267"
|
||||
#"\310u?\e|e\366\264 uX\31\2305\272\2224\266\37\21X@\200\35*"
|
||||
#"\260P\221\4\27X\300N&\266\252\27\375\v\225Q\v\367\235\326"
|
||||
#"\a\332&\260\0\200\235<\322\271\273u\3157\264\273\b\1\330\\"
|
||||
#"\221\263B\314z\273\211\270\341\265\302\21,\0\266\325\366~\224\325"
|
||||
#"\332>\27,\260\0\330\220\272\242&\201\5\300V\324\25e\t,`'\23"
|
||||
#"\247\3\354\206\2334\375\266Z\37h\233\300\2 O$\3610q\225U\333+"
|
||||
#"\211\300\"\343\323\37\243m\177~\370\326\304|)\207,\17\eY\370"
|
||||
#"\236Z\37*\e\276\365\215\355G\4\0261o\237\215\307\327\234\\"
|
||||
#"\361S\301\236\32\276\207\250\254o?\370o\333\215\r\226\210#\r"
|
||||
#"\263\351\271w\30\256'-\355G\376]t\2719\255\347g\303\252U\326"
|
||||
#"\354\6\361u\3j=i\314l!\215\276\343\266\e\315\373\352"
|
||||
) 221
|
||||
(
|
||||
#"S\337\306\372 \260\0\0\302\234\"\4\0\b\23X\0\0a\2\v\0 L`"
|
||||
#"\1\0\204\t,\0\2000\201\5\0\20&\260\0\0\302\4\26\0@\230"
|
||||
#"\300\2\0\b\23X\0\0a\2\v\0 L`\1\0\204\t,\0\2000\201\5"
|
||||
#"\0\20&\260\0\0\302\4\26\0@\230\300\2\0\b\23X\0\0a\2\v"
|
||||
#"\0 L`\1\0\204\t,\0\2000\201\5\0\20&\260\0\0\302\4\26\0@"
|
||||
#"\230\300\2\0\b\23X\0\0a\2\v\0 L`\1\0\204\t,\0\2000\201"
|
||||
#"\5\0\20&\260\0\0\302\4\26\0@\230\300\2\0\b\23X\0\0a\2"
|
||||
#"\v\0 L`\1\0\204\t,\0\2000\201\5\0\20&\260\0\0\302\4\26"
|
||||
#"\0@\230\300\2\0\b\373/+T\1\37\252S\336\263\0\0\0\0IEND\256B`"
|
||||
#"\202"
|
||||
) 0 00000000000
|
|
@ -1,25 +0,0 @@
|
|||
#lang scheme
|
||||
(require plot)
|
||||
|
||||
(require mzlib/class plot/plot-extend)
|
||||
; (number -> number) mumbo-jumbo -> 2d-renderer
|
||||
(define-plot-type dashed-line
|
||||
fun 2dview (x-min x-max) ((samples 100) (segments 20) (color 'red) (width 1))
|
||||
(let* ((dash-size (/ (- x-max x-min) segments))
|
||||
(x-lists (build-list (/ segments 2)
|
||||
(lambda (index)
|
||||
(x-values
|
||||
(/ samples segments)
|
||||
(+ x-min (* 2 index dash-size))
|
||||
(+ x-min (* (add1 ( * 2 index)) dash-size)))))))
|
||||
(send* 2dview
|
||||
(set-line-color color)
|
||||
(set-line-width width))
|
||||
(for-each (lambda (dash)
|
||||
(send 2dview plot-line
|
||||
(map (lambda (x) (vector x (fun x))) dash)))
|
||||
x-lists)))
|
||||
;
|
||||
|
||||
(plot (dashed-line (lambda (x) x) (color 'red)))
|
||||
(plot3d (surface (lambda (x y) (* (sin x) (sin y)))))
|
|
@ -1,4 +0,0 @@
|
|||
#lang scheme
|
||||
(require plot)
|
||||
|
||||
(plot (line (lambda (x) x) #:color 'red))
|
|
@ -1,4 +0,0 @@
|
|||
#lang scheme
|
||||
(require plot)
|
||||
|
||||
(plot (line sin #:color 'red))
|
|
@ -1,5 +0,0 @@
|
|||
#lang scheme
|
||||
(require plot)
|
||||
|
||||
(plot (vector-field (gradient (lambda (x y) (* (sin x) (cos y)))) #:samples 25)
|
||||
#:title "gradient field of F(x,y) = sin(x) * sin(y)")
|
|
@ -1,7 +0,0 @@
|
|||
#lang scheme
|
||||
(require plot)
|
||||
|
||||
(define (trig x y) (* (sin x) (sin y)))
|
||||
(plot (shade trig)
|
||||
#:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5
|
||||
#:title "shdade of F(x,y) = sin(x) * sin(y)")
|
|
@ -1,8 +0,0 @@
|
|||
#lang scheme
|
||||
(require plot)
|
||||
|
||||
(define (trig x y) (* (sin x) (sin y)))
|
||||
|
||||
(plot (contour trig)
|
||||
#:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5
|
||||
#:title "contours of F(x,y) = sin(x) * sin(y)")
|
|
@ -1,8 +0,0 @@
|
|||
#lang scheme
|
||||
(require plot)
|
||||
|
||||
(define (trig x y) (* (sin x) (sin y)))
|
||||
|
||||
(plot (vector-field (gradient trig) #:samples 25)
|
||||
#:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5
|
||||
#:title "gradient field of F(x,y) = sin(x) * sin(y)")
|
|
@ -1,14 +0,0 @@
|
|||
#lang scheme
|
||||
(require plot)
|
||||
|
||||
(define (trig x y) (* (sin x) (sin y)))
|
||||
|
||||
(plot (mix (shade trig)
|
||||
(contour trig)
|
||||
(vector-field (gradient trig) #:samples 25))
|
||||
#:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5
|
||||
#:title "gradient field +shdade + contours of F(x,y) = sin(x) * sin(y)")
|
||||
|
||||
(plot3d (mesh3d trig)
|
||||
#:x-min -3.5 #:x-max 3.5 #:y-min -3.5 #:y-max 3.5 #:z-min -1.0 #:z-max 1.5
|
||||
#:bgcolor '(0 0 0) #:fgcolor '(255 0 0))
|
|
@ -1,24 +0,0 @@
|
|||
#lang scheme
|
||||
(require plot)
|
||||
|
||||
(define x-vals (build-list 15 (lambda (x) x) ))
|
||||
(define errors (build-list 15 (lambda (x) 1)))
|
||||
|
||||
(define (fun x)
|
||||
(* 3 (exp (* x -1 1.32))))
|
||||
(define z-vals (map fun x-vals))
|
||||
|
||||
(define (gues-fun x a b)
|
||||
(* a (exp (* x -1 b))))
|
||||
|
||||
(define params
|
||||
(fit gues-fun
|
||||
'((a 1) (b 1))
|
||||
(map vector x-vals z-vals errors)))
|
||||
|
||||
(plot (mix
|
||||
(points (map vector x-vals z-vals))
|
||||
(line (lambda (x)
|
||||
(apply gues-fun x (fit-result-final-params params)))))
|
||||
#:x-min -1 #:x-max 20
|
||||
#:y-min -1 #:y-max 10)
|
|
@ -1,79 +0,0 @@
|
|||
#lang scheme
|
||||
|
||||
;; This is data from the Cavendish experiment
|
||||
(define raw-data
|
||||
'((0.0 -14.7 3.6)
|
||||
(1.0 8.6 3.6)
|
||||
(2.1 28.8 3.0)
|
||||
(3.1 46.7 3.4)
|
||||
(4.2 47.4 3.5)
|
||||
(5.2 36.5 3.4)
|
||||
(6.2 37.0 10.3)
|
||||
(7.2 5.1 3.4)
|
||||
(8.2 -11.2 3.4)
|
||||
(9.1 -22.4 3.5)
|
||||
(10.0 -35.5 3.6)
|
||||
(11.0 -33.6 3.9)
|
||||
(12.0 -21.1 3.9)
|
||||
(12.9 -15.0 4.2)
|
||||
(13.8 -1.6 2.7)
|
||||
(14.9 19.5 3.2)
|
||||
(15.9 27.5 2.8)
|
||||
(17.0 32.6 3.5)
|
||||
(17.9 27.5 2.7)
|
||||
(18.9 20.2 3.3)
|
||||
(20.0 13.8 3.4)
|
||||
(21.0 -1.3 4.2)
|
||||
(22.0 -24.5 6.7)
|
||||
(23.0 -25.0 3.3)
|
||||
(24.0 -25.0 3.1)
|
||||
(25.0 -20.2 3.6)
|
||||
(26.0 -9.9 3.2)
|
||||
(27.0 5.8 3.2)
|
||||
(28.0 14.7 3.0)
|
||||
(29.0 21.8 3.5)
|
||||
(30.0 29.8 2.7)
|
||||
(31.0 21.4 4.1)
|
||||
(32.0 24.6 2.7)
|
||||
(32.9 25.8 12.0)
|
||||
(33.8 0.6 2.9)
|
||||
(34.7 -16.6 3.2)
|
||||
(35.7 -24.0 3.7)
|
||||
(36.6 -24.6 3.8)
|
||||
(37.7 -19.8 3.5)))
|
||||
|
||||
; first column is time data, second is result, third is error. to parse them out...
|
||||
(require mzlib/math)
|
||||
|
||||
(define times
|
||||
(map car raw-data))
|
||||
(define vals
|
||||
(map cadr raw-data))
|
||||
(define errors
|
||||
(map caddr raw-data))
|
||||
|
||||
(define experemental-data (map list->vector raw-data))
|
||||
|
||||
(require plot)
|
||||
|
||||
(plot (mix (points experemental-data #:sym 'circle)
|
||||
(error-bars experemental-data))
|
||||
#:x-min 0 #:x-max 40
|
||||
#:y-min -40 #:y-max 50
|
||||
#:width 400 #:height 300)
|
||||
|
||||
(define (theta x a tau phi T theta0)
|
||||
(+ theta0
|
||||
(* a (exp (/ x tau -1)) (sin (+ phi (/ (* 2 pi x) T))))))
|
||||
|
||||
(define result
|
||||
(fit theta '((a 40) (tau 15) (phi -0.5) (T 15) (theta0 10)) experemental-data))
|
||||
|
||||
(plot (mix (points (map vector times vals) #:sym 'square #:color 'black)
|
||||
(error-bars experemental-data)
|
||||
(line (fit-result-function result) #:color 'green))
|
||||
#:x-min -5 #:x-max 40
|
||||
#:y-min -40 #:y-max 50)
|
||||
|
||||
(fit-result-final-params result)
|
||||
;(pretty-print result)
|
|
@ -1,18 +0,0 @@
|
|||
#lang scheme/base
|
||||
|
||||
(require "plot-extend.rkt"
|
||||
"renderer-helpers.rkt"
|
||||
"view.rkt")
|
||||
|
||||
(provide (except-out (all-from-out "plot-extend.rkt")
|
||||
define-plot-type)
|
||||
plot-view%
|
||||
|
||||
sample-size
|
||||
scale-vectors
|
||||
x-values
|
||||
normalize-vector
|
||||
normalize-vectors
|
||||
make-column
|
||||
xy-list
|
||||
zgrid)
|
|
@ -1,56 +0,0 @@
|
|||
(module fit-low-level racket/base
|
||||
(require mzlib/foreign mzlib/runtime-path
|
||||
(for-syntax racket/base))
|
||||
(unsafe!)
|
||||
|
||||
(define-runtime-path libfit-path '(so "libfit"))
|
||||
|
||||
(define libfit (ffi-lib libfit-path))
|
||||
|
||||
(define do-fit-int
|
||||
(get-ffi-obj "do_fit" libfit
|
||||
(_fun (func : (_fun _int _pointer -> _double))
|
||||
(val-num : _int = (length x-values))
|
||||
(x-values : (_list i _double*))
|
||||
(y-values : (_list i _double*))
|
||||
(z-values : (_list i _double*))
|
||||
(errors : (_list i _double*))
|
||||
(param-num : _int = (length params))
|
||||
(params : (_list i _double*))
|
||||
-> (_list o _double* param-num))))
|
||||
|
||||
(define (do-fit callback x-vals y-vals z-vals errors params)
|
||||
(do-fit-int (lambda (argc argv)
|
||||
(let ([args (cblock->list argv _double argc)])
|
||||
(apply callback args)))
|
||||
x-vals y-vals z-vals errors params))
|
||||
|
||||
(define get-asym-error
|
||||
(get-ffi-obj "get_asym_error" libfit
|
||||
(_fun (len : _?) ; len is only used for list conversion
|
||||
-> (_list o _double* len))))
|
||||
|
||||
(define get-asym-error-percent
|
||||
(get-ffi-obj "get_asym_error_percent" libfit
|
||||
(_fun (len : _?) ; len is only used for list conversion
|
||||
-> (_list o _double* len))))
|
||||
|
||||
(define get-rms
|
||||
(get-ffi-obj "get_rms" libfit
|
||||
(_fun -> _double*)))
|
||||
|
||||
(define get-varience
|
||||
(get-ffi-obj "get_varience" libfit
|
||||
(_fun -> _double*)))
|
||||
|
||||
(define (fit-internal f-of-x-y x-vals y-vals z-vals err-vals params)
|
||||
|
||||
(let* ([len (length params)]
|
||||
[fit-result (do-fit f-of-x-y x-vals y-vals z-vals err-vals params)]
|
||||
[asym-error (get-asym-error len)]
|
||||
[asym-error-percent (get-asym-error-percent len)]
|
||||
[rms (get-rms)]
|
||||
[varience (get-varience)])
|
||||
(list fit-result asym-error asym-error-percent rms varience)))
|
||||
|
||||
(provide fit-internal))
|
|
@ -1,54 +0,0 @@
|
|||
(module fit mzscheme
|
||||
(require plot/math)
|
||||
(require plot/fit-low-level)
|
||||
|
||||
; a structure contain a the results of a curve-fit
|
||||
(define-struct fit-result (
|
||||
rms
|
||||
variance
|
||||
names
|
||||
final-params
|
||||
std-error
|
||||
std-error-percent
|
||||
function
|
||||
) (make-inspector))
|
||||
|
||||
; fit-int : (number* -> number) (list-of (symbol number)) (list-of (vector number [number] number number)) -> fit-result
|
||||
(define (fit-int function guesses data)
|
||||
(let* ((independent-vars (- (procedure-arity function) (length guesses)))
|
||||
(f-of-x-y (cond
|
||||
[(= 1 independent-vars)
|
||||
(lambda (x y . rest)
|
||||
(apply function x rest))]
|
||||
[(= 2 independent-vars)
|
||||
function]
|
||||
[else
|
||||
(error "Function provided is either not of one or two independent variables or the number of
|
||||
guesses given is incorrect")]))
|
||||
(x-vals (map vector-x data))
|
||||
(y-vals (if (= 1 independent-vars)
|
||||
x-vals
|
||||
(map vector-y data)))
|
||||
(z-vals (if (= 1 independent-vars)
|
||||
(map vector-y data)
|
||||
(map vector-z data)))
|
||||
(err-vals (if (= 1 independent-vars)
|
||||
(map vector-z data)
|
||||
(map (lambda (vec) (vector-ref vec 4)) data)))
|
||||
(result (fit-internal f-of-x-y x-vals y-vals z-vals err-vals (map cadr guesses))))
|
||||
(if (null? result)
|
||||
null
|
||||
(begin
|
||||
;(display result)
|
||||
(make-fit-result
|
||||
(list-ref result 3)
|
||||
(list-ref result 4)
|
||||
(map car guesses)
|
||||
(car result)
|
||||
(cadr result)
|
||||
(caddr result)
|
||||
(lambda args (apply function(append args (car result)))))))))
|
||||
|
||||
(provide fit-int
|
||||
(struct fit-result (rms variance names final-params
|
||||
std-error std-error-percent function))))
|
|
@ -1,5 +0,0 @@
|
|||
#lang setup/infotab
|
||||
|
||||
(define scribblings '(("plot.scrbl" (multi-page) (gui-library))))
|
||||
|
||||
(define compile-omit-paths '("demos"))
|
|
@ -1,155 +0,0 @@
|
|||
#lang scheme/base
|
||||
|
||||
(require (prefix-in orig:
|
||||
(only-in "plot.rkt"
|
||||
plot plot3d
|
||||
points line error-bars
|
||||
vector-field contour
|
||||
shade surface))
|
||||
(only-in "plot.rkt"
|
||||
mix
|
||||
derivative gradient make-vec
|
||||
mesh3d)
|
||||
(only-in "fit.rkt" fit-int))
|
||||
|
||||
(provide plot
|
||||
plot3d
|
||||
plot-color?
|
||||
points
|
||||
line
|
||||
error-bars
|
||||
vector-field
|
||||
contour
|
||||
shade
|
||||
surface
|
||||
(rename-out [fit-int fit])
|
||||
mix
|
||||
derivative
|
||||
gradient
|
||||
make-vec
|
||||
mesh3d)
|
||||
|
||||
(define-syntax-rule (out-fit-struct)
|
||||
(begin
|
||||
(require "plot.rkt")
|
||||
(provide (struct-out fit-result))))
|
||||
|
||||
(out-fit-struct)
|
||||
|
||||
(define-syntax-rule (define-plot plot orig:plot
|
||||
[arg-extra ...]
|
||||
[init-extra ...])
|
||||
(define (plot data
|
||||
#:width [width 400]
|
||||
#:height [height 400]
|
||||
#:x-min [x-min -5]
|
||||
#:x-max [x-max 5]
|
||||
#:y-min [y-min -5]
|
||||
#:y-max [y-max 5]
|
||||
#:x-label [x-label "X axis"]
|
||||
#:y-label [y-label "Y axis"]
|
||||
#:title [title ""]
|
||||
#:fgcolor [fgcolor '(0 0 0)]
|
||||
#:bgcolor [bgcolor '(255 255 255)]
|
||||
#:lncolor [lncolor '(255 0 0)]
|
||||
#:out-file [out-file #f]
|
||||
arg-extra ...)
|
||||
(orig:plot data
|
||||
[width width]
|
||||
[height height]
|
||||
[x-min x-min]
|
||||
[x-max x-max]
|
||||
[y-min y-min]
|
||||
[y-max y-max]
|
||||
[x-label x-label]
|
||||
[y-label y-label]
|
||||
[title title]
|
||||
[fgcolor fgcolor]
|
||||
[bgcolor bgcolor]
|
||||
[lncolor lncolor]
|
||||
[out-file out-file]
|
||||
init-extra ...)))
|
||||
|
||||
(define-plot plot orig:plot [] [])
|
||||
|
||||
(define-plot plot3d orig:plot3d
|
||||
[#:z-min [z-min -5]
|
||||
#:z-max [z-max 5]
|
||||
#:z-label [z-label "Z axis"]
|
||||
#:alt [alt 30]
|
||||
#:az [az 45]]
|
||||
[[z-min z-min]
|
||||
[z-max z-max]
|
||||
[z-label z-label]
|
||||
[alt alt]
|
||||
[az az]])
|
||||
|
||||
(define (plot-color? v)
|
||||
(memq v '(white black yellow green aqua pink
|
||||
wheat grey blown blue violet cyan
|
||||
turquoise magenta salmon red)))
|
||||
|
||||
(define (points vecs
|
||||
#:sym [sym 'square]
|
||||
#:color [color 'black])
|
||||
(orig:points vecs [sym sym] [color color]))
|
||||
|
||||
(define (line f
|
||||
#:samples [samples 150]
|
||||
#:width [width 1]
|
||||
#:color [color 'red]
|
||||
#:mode [mode 'standard]
|
||||
#:mapping [mapping 'cartesian]
|
||||
#:t-min [t-min -5]
|
||||
#:t-max [t-max 5])
|
||||
(orig:line f
|
||||
[samples samples]
|
||||
[width width]
|
||||
[color color]
|
||||
[mode mode]
|
||||
[mapping mapping]
|
||||
[t-min t-min]
|
||||
[t-max t-max]))
|
||||
|
||||
(define (error-bars vec
|
||||
#:color [color 'black])
|
||||
(orig:error-bars vec [color color]))
|
||||
|
||||
(define (vector-field f
|
||||
#:width [width 1]
|
||||
#:color [color 'red]
|
||||
#:style [style 'scaled]
|
||||
#:samples [samples 20])
|
||||
(orig:vector-field f
|
||||
[width width]
|
||||
[color color]
|
||||
[style style]
|
||||
[samples samples]))
|
||||
|
||||
(define (contour f
|
||||
#:samples [samples 50]
|
||||
#:width [width 1]
|
||||
#:color [color 'black]
|
||||
#:levels [levels 10])
|
||||
(orig:contour f
|
||||
[samples samples]
|
||||
[width width]
|
||||
[color color]
|
||||
[levels levels]))
|
||||
|
||||
(define (shade f
|
||||
#:samples [samples 50]
|
||||
#:levels [levels 10])
|
||||
(orig:shade f
|
||||
[samples samples]
|
||||
[levels levels]))
|
||||
|
||||
(define (surface f
|
||||
#:samples [samples 50]
|
||||
#:width [width 1]
|
||||
#:color [color 'black])
|
||||
(orig:surface f
|
||||
[samples samples]
|
||||
[width width]
|
||||
[color color]))
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
(module math mzscheme
|
||||
|
||||
; Usefull mathy functions for plots
|
||||
|
||||
(require mzlib/list mzlib/etc mzlib/math)
|
||||
|
||||
; using vectors for n-dimensional points
|
||||
|
||||
; vector-magnitude : (vectorof number) -> number
|
||||
; computes the magnituded of the vector by using pythegorean theorem
|
||||
(define (vector-magnitude vec)
|
||||
(sqrt (foldl (lambda (item total) (+ (sqr item) total)) 0 (vector->list vec))))
|
||||
|
||||
; shortcuts to avoid writing ugly vector-ref code
|
||||
(define (vector-x vec)
|
||||
(vector-ref vec 0))
|
||||
|
||||
(define (vector-y vec)
|
||||
(vector-ref vec 1))
|
||||
|
||||
(define (vector-z vec)
|
||||
(vector-ref vec 2))
|
||||
|
||||
; make-vec : (number number -> number) (number number -> number) -> (vector -> vector)
|
||||
(define (make-vec func1 func2)
|
||||
(lambda (point) (vector (func1 (vector-x point) (vector-y point)) (func2 (vector-x point) (vector-y point)))))
|
||||
|
||||
; derivative : (number -> number) [number] -> (number -> number)
|
||||
(define derivative
|
||||
(opt-lambda (func [h .00000001])
|
||||
(lambda (x) (/ (- (func (+ x h)) (func x)) h))))
|
||||
|
||||
; gradient : (number number -> number) [number] -> (vector -> vector)
|
||||
(define gradient
|
||||
(opt-lambda (func-3d [h .00000001])
|
||||
(lambda (point) (vector ((derivative (lambda (x) (func-3d x (vector-y point))) h) (vector-x point))
|
||||
((derivative (lambda (y) (func-3d (vector-x point) y)) h) (vector-y point))))))
|
||||
|
||||
(provide (all-defined)))
|
|
@ -1,112 +0,0 @@
|
|||
(module plot-extend mzscheme
|
||||
(require mzlib/class plot/view plot/renderer-helpers)
|
||||
|
||||
(define-syntax (define-plot-type stx)
|
||||
(define (join-identifier prefix ident)
|
||||
(datum->syntax-object
|
||||
ident
|
||||
(string->symbol
|
||||
(string-append (symbol->string prefix )
|
||||
(symbol->string (syntax-e ident)))) ))
|
||||
(syntax-case stx ()
|
||||
[(_ name data view ((var default) ...) body)
|
||||
#'(r-lambda-internal name data view ((var default) ...) () body)]
|
||||
[(_ name data view (field ...) ((var default) ...) body)
|
||||
(let ((accessors (map (lambda (f) (join-identifier 'get- f)) (syntax-e #'(field ...)))))
|
||||
(with-syntax (((getter ...) accessors))
|
||||
#'(r-lambda-internal name data view ((var default) ...) ((field getter) ...) body)))]))
|
||||
|
||||
#|
|
||||
(define-syntax r-lambda-internal-test
|
||||
(syntax-rules ()
|
||||
[(_ name data view ((var default) ...) ((value accessor) ...) body)
|
||||
(define-syntax name
|
||||
(lambda (stx-2)
|
||||
(define (find-val sym lst)
|
||||
(cond
|
||||
[(null? lst) #f]
|
||||
[(eq? (car (syntax-object->datum (car lst))) sym)
|
||||
(cadr (syntax-object->datum (car lst)))]
|
||||
[else
|
||||
(find-val sym (cdr lst))]))
|
||||
|
||||
;; there is probably a better way to do this
|
||||
(define (subst-names original overrides)
|
||||
(map
|
||||
(lambda (default-pair)
|
||||
(let ((pair-id (car (syntax-object->datum default-pair))))
|
||||
(cond
|
||||
[(find-val pair-id overrides)
|
||||
=> (lambda (new-val)
|
||||
(datum->syntax-object
|
||||
default-pair
|
||||
(list pair-id new-val)))]
|
||||
[else
|
||||
default-pair])))
|
||||
original))
|
||||
|
||||
(syntax-case stx-2 ()
|
||||
[(_ val)
|
||||
#'(let ((var default) ...
|
||||
(data val))
|
||||
(lambda (view)
|
||||
(let ((value (send view accessor)) ...)
|
||||
body)))]
|
||||
[(_ val (override-name override-value) (... ...) )
|
||||
|
||||
(let ((new-defaults (subst-names
|
||||
(syntax-e #'((var default) ...))
|
||||
|
||||
(syntax-e #'((override-name override-value) (... ...))))))
|
||||
(with-syntax ((((def new-def-val) (... ...)) new-defaults))
|
||||
#'(let ((def new-def-val) (... ...)
|
||||
(data val))
|
||||
(lambda (view)
|
||||
(let ((value (send view accessor)) ...)
|
||||
body)))))])))]))
|
||||
|#
|
||||
(define-syntax r-lambda-internal
|
||||
(syntax-rules ()
|
||||
[(_ name data view ((var default) ...) ((value accessor) ...) body)
|
||||
(define-syntax name
|
||||
(lambda (stx-2)
|
||||
(syntax-case stx-2 ()
|
||||
[(_ val)
|
||||
#'(let ((var default) ...
|
||||
(data val))
|
||||
(lambda (view)
|
||||
(let ((value (send view accessor)) ...)
|
||||
body)))]
|
||||
[(_ val (override-name override-value) (... ...) )
|
||||
(let ((overrides
|
||||
(map
|
||||
(lambda (stx)
|
||||
(let ((pair (syntax-e stx)))
|
||||
(list
|
||||
(syntax-e (car pair))
|
||||
(cadr pair))))
|
||||
(syntax-e #'((override-name override-value) (... ...))))))
|
||||
(let ((new-defaults
|
||||
(map
|
||||
(lambda (a-default)
|
||||
(let ((def-name (syntax-e (car (syntax-e a-default)))))
|
||||
(cond
|
||||
[(assq def-name overrides) =>
|
||||
(lambda (new-val)
|
||||
(datum->syntax-object
|
||||
a-default ; ...
|
||||
(list (car (syntax-e a-default))
|
||||
(cadr new-val))))]
|
||||
[else a-default])))
|
||||
(syntax-e #'((var default) ...)))))
|
||||
(with-syntax ((((var-new default-new) (... ...)) new-defaults))
|
||||
#'(let ((var-new default-new) (... ...)
|
||||
(data val))
|
||||
(lambda (view)
|
||||
(let ((value (send view accessor)) ...)
|
||||
body))))))])))]))
|
||||
(provide
|
||||
define-plot-type
|
||||
(all-from-except plot/view plot-view%)
|
||||
(all-from plot/renderer-helpers)))
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
#lang mzscheme
|
||||
|
||||
(require mzlib/list mzlib/etc mzlib/class
|
||||
"math.rkt" "view.rkt" "renderer-helpers.rkt" "renderers.rkt" "fit.rkt")
|
||||
|
||||
;; plot : plottable (option value)*
|
||||
(define-syntax plot
|
||||
(syntax-rules ()
|
||||
[(_ ren )
|
||||
(instantiate 2d-view% () (renderer ren))]
|
||||
[(_ ren (option value) ...)
|
||||
(instantiate 2d-view% () (renderer ren) (option value) ...)]))
|
||||
|
||||
(define-syntax plot3d
|
||||
(syntax-rules ()
|
||||
[(_ ren )
|
||||
(instantiate 3d-view% () (renderer ren))]
|
||||
[(_ ren (option value) ...)
|
||||
(instantiate 3d-view% () (renderer ren) (option value) ...)]))
|
||||
|
||||
;; mix-int : renderer renderer -> renderer
|
||||
;; creates a renderer that will renderer both of the inputs
|
||||
(define (mix-int renderer1 renderer2)
|
||||
(lambda (view)
|
||||
(send view reset-to-default)
|
||||
(renderer1 view)
|
||||
(send view reset-to-default)
|
||||
(renderer2 view)))
|
||||
|
||||
;; mix : renderer+ -> renderer
|
||||
;; combine any number of renderers
|
||||
(define (mix r1 . the-rest)
|
||||
(if (empty? the-rest)
|
||||
r1
|
||||
(mix-int r1 (apply mix the-rest))))
|
||||
|
||||
;; make-2d-renderer : (2d-view% -> void)
|
||||
;; provides a user with the ability to create their own renderers
|
||||
;; without providing the implementation
|
||||
(define custom identity)
|
||||
|
||||
;;
|
||||
(define-syntax fit
|
||||
(syntax-rules ()
|
||||
[(_ func ((param guess) ...) data)
|
||||
(fit-int func '((param guess) ...) data)]))
|
||||
|
||||
(provide
|
||||
|
||||
;; fitting
|
||||
fit
|
||||
(struct fit-result
|
||||
(rms variance names final-params std-error std-error-percent function))
|
||||
;; to make plots
|
||||
plot
|
||||
plot3d
|
||||
|
||||
;; to combine/create renderers
|
||||
mix
|
||||
custom
|
||||
|
||||
;; 2d-renderers
|
||||
error-bars
|
||||
points
|
||||
line
|
||||
vector-field
|
||||
contour
|
||||
shade
|
||||
;; 3d-rendereres
|
||||
surface
|
||||
mesh3d
|
||||
|
||||
;; from math-tools
|
||||
derivative
|
||||
gradient
|
||||
make-vec
|
||||
|
||||
)
|
|
@ -1,638 +0,0 @@
|
|||
#lang scribble/doc
|
||||
@(require scribble/manual
|
||||
(for-label scheme
|
||||
scheme/gui/base
|
||||
plot
|
||||
plot/extend))
|
||||
|
||||
@title{PLoT: Graph Plotting}
|
||||
|
||||
@author["Alexander Friedman" "Jamie Raymond"]
|
||||
|
||||
PLoT (a.k.a. PLTplot) provides a basic interface for producing common
|
||||
types of plots such as line and vector field plots as well as an
|
||||
advanced interface for producing customized plot types. Additionally,
|
||||
plots and plot-items are first-class values and can be generated in
|
||||
and passed to other programs.
|
||||
|
||||
@table-of-contents[]
|
||||
|
||||
@section{Quick Start}
|
||||
|
||||
@subsection{Overview}
|
||||
|
||||
PLoT (aka PLTplot) provides a basic interface for producing common
|
||||
types of plots such as line and vector field plots as well as an
|
||||
advanced interface for producing customized plot types. Additionally,
|
||||
plots and plot-items are first-class values and can be generated in
|
||||
and passed to other programs.
|
||||
|
||||
@subsection{Basic Plotting}
|
||||
|
||||
After loading the correct module using @racket[(require plot)] try
|
||||
|
||||
@racketblock[(plot (line (lambda (x) x)))]
|
||||
|
||||
Any other function using the contract @racket[(real? . -> . real?)]
|
||||
can be plotted using the same form. To plot multiple items, use the
|
||||
functions @racket[mix] and @racket[mix*] to combine the items to be
|
||||
plotted.
|
||||
|
||||
@racketblock[
|
||||
(plot (mix (line (lambda (x) (sin x)))
|
||||
(line (lambda (x) (cos x)))))
|
||||
]
|
||||
|
||||
The display area and appearance of the plot can be changed by adding
|
||||
brackets argument/value pairs after the first argument.
|
||||
|
||||
@racketblock[
|
||||
(plot (line (lambda (x) (sin x)))
|
||||
#:x-min -1 #:x-max 1 #:title "Sin(x)")
|
||||
]
|
||||
|
||||
The appearance of each individual plot item can be altered by adding
|
||||
argument/value pairs after the data.
|
||||
|
||||
@racketblock[
|
||||
(plot (line (lambda (x) x)
|
||||
#:color 'green #:width 3))
|
||||
]
|
||||
|
||||
Besides plotting lines from functions in 2-D, the plotter can also
|
||||
render a variety of other data in several ways:
|
||||
|
||||
@itemize[
|
||||
|
||||
@item{Discrete data, such as
|
||||
@racketblock[(define data (list (vector 1 1 2)
|
||||
(vector 2 2 2)))]
|
||||
can be interpreted in several ways:
|
||||
@itemize[
|
||||
@item{As points: @racket[(plot (points _data))]}
|
||||
@item{As error data: @racket[(plot (error-bars _data))]}]}
|
||||
|
||||
@item{A function of two variables, such as
|
||||
@racketblock[(define 3dfun (lambda (x y) (* (sin x) (sin y))))]
|
||||
can be plotted on a 2d graph
|
||||
@itemize[
|
||||
@item{Using contours to represent height (z)
|
||||
@racketblock[(plot (contour 3dfun))]}
|
||||
@item{Using color shading
|
||||
@racketblock[(plot (shade 3dfun))]}
|
||||
@item{Using a gradient field
|
||||
@racketblock[(plot (vector-field (gradient 3dfun)))]}]
|
||||
or in a 3d box
|
||||
@itemize[
|
||||
@item{Displaying only the top of the surface
|
||||
@racketblock[(plot3d (surface 3dfun))]}]}
|
||||
|
||||
]
|
||||
|
||||
@subsection[#:tag "ex-curve-fit"]{Curve Fitting}
|
||||
|
||||
The @racketmodname[plot] library uses a non-linear, least-squares fit
|
||||
algorithm to fit parameterized functions to given data.
|
||||
|
||||
To fit a particular function to a curve:
|
||||
|
||||
@itemize[
|
||||
|
||||
@item{Set up the independent and dependent variable data. The first
|
||||
item in each vector is the independent variable, the second is the
|
||||
result. The last item is the weight of the error; we can leave it
|
||||
as @racket[1] since all the items weigh the same.
|
||||
|
||||
@racketblock[
|
||||
(define data '(#(0 3 1)
|
||||
#(1 5 1)
|
||||
#(2 7 1)
|
||||
#(3 9 1)
|
||||
#(4 11 1)))
|
||||
]
|
||||
}
|
||||
|
||||
@item{Set up the function to be fitted using fit. This particular
|
||||
function looks like a line. The independent variables must come
|
||||
before the parameters.
|
||||
|
||||
@racketblock[
|
||||
(define fit-fun
|
||||
(lambda (x m b) (+ b (* m x))))
|
||||
]
|
||||
}
|
||||
|
||||
@item{If possible, come up with some guesses for the values of the
|
||||
parameters. The guesses can be left as one, but each parameter must
|
||||
be named.}
|
||||
|
||||
@item{Do the fit; the details of the function are described in
|
||||
@secref["curve-fit"].
|
||||
|
||||
@racketblock[
|
||||
(define fitted
|
||||
(fit fit-fun
|
||||
'((m 1) (b 1))
|
||||
data))
|
||||
]
|
||||
}
|
||||
|
||||
@item{View the resulting parameters; for example,
|
||||
|
||||
@racketblock[
|
||||
(fit-result-final-params fitted)
|
||||
]
|
||||
|
||||
will produce @racketresultfont{(2.0 3.0)}.
|
||||
}
|
||||
|
||||
@item{For some visual feedback of the fit result, plot the function
|
||||
with the new parameters. For convenience, the structure that is
|
||||
returned by the fit command has already the function.
|
||||
|
||||
@racketblock[
|
||||
(plot (mix (points data)
|
||||
(line (fit-result-function fitted)))
|
||||
#:y-max 15)
|
||||
]}]
|
||||
|
||||
A more realistic example can be found in
|
||||
@filepath{demos/fit-demo-2.rkt} in the @filepath{plot} collection.
|
||||
|
||||
@subsection{Creating Custom Plots}
|
||||
|
||||
Defining custom plots is simple: a plot-item (that is passed to plot
|
||||
or mix) is just a function that acts on a view. Both the 2-D and 3-D
|
||||
view snip have several drawing functions defined that the plot-item
|
||||
can call in any order. The full details of the view interface can be
|
||||
found in @secref["extend"].
|
||||
|
||||
For example, if we wanted to create a constructor that creates
|
||||
plot-items that draw dashed lines given a @racket[(real? . -> . real?)]
|
||||
function, we could do the following:
|
||||
|
||||
@racketblock[
|
||||
(require plot/extend)
|
||||
|
||||
(define (dashed-line fun
|
||||
#:x-min [x-min -5]
|
||||
#:x-max [x-max 5]
|
||||
#:samples [samples 100]
|
||||
#:segments [segments 20]
|
||||
#:color [color 'red]
|
||||
#:width [width 1])
|
||||
(let* ([dash-size (/ (- x-max x-min) segments)]
|
||||
[x-lists (build-list
|
||||
(/ segments 2)
|
||||
(lambda (index)
|
||||
(x-values
|
||||
(/ samples segments)
|
||||
(+ x-min (* 2 index dash-size))
|
||||
(+ x-min (* (add1 (* 2 index))
|
||||
dash-size)))))])
|
||||
(lambda (2dview)
|
||||
(send 2dview set-line-color color)
|
||||
(send 2dview set-line-width width)
|
||||
(for-each
|
||||
(lambda (dash)
|
||||
(send 2dview plot-line
|
||||
(map (lambda (x) (vector x (fun x))) dash)))
|
||||
x-lists))))
|
||||
]
|
||||
|
||||
Plot a test case using @racket[dashed-line]:
|
||||
|
||||
@racketblock[
|
||||
(plot (dashed-line (lambda (x) x) #:color 'blue))
|
||||
]
|
||||
|
||||
@; ----------------------------------------
|
||||
|
||||
@section[#:tag "plot"]{Plotting}
|
||||
|
||||
@defmodule[plot]
|
||||
|
||||
The @racketmodname[plot] library provides the ability to make basic
|
||||
plots, fit curves to data, and some useful miscellaneous functions.
|
||||
|
||||
@subsection{Plotting}
|
||||
|
||||
The @racket[plot] and @racket[plot3d] functions generate plots that can be
|
||||
viewed in the DrRacket interactions window.
|
||||
|
||||
@defproc[(plot [data ((is-a?/c 2d-view%) . -> . void?)]
|
||||
[#:width width real? 400]
|
||||
[#:height height real? 400]
|
||||
[#:x-min x-min real? -5]
|
||||
[#:x-max x-max real? 5]
|
||||
[#:y-min y-min real? -5]
|
||||
[#:y-max y-max real? 5]
|
||||
[#:x-label x-label string? "X axis"]
|
||||
[#:y-label y-label string? "Y axis"]
|
||||
[#:title title string? ""]
|
||||
[#:fgcolor fgcolor (list/c byte? byte? byte) '(0 0 0)]
|
||||
[#:bgcolor bgcolor (list/c byte? byte? byte) '(255 255 255)]
|
||||
[#:lncolor lncolor (list/c byte? byte? byte) '(255 0 0)]
|
||||
[#:out-file out-file (or/c path-string? output-port? #f) #f])
|
||||
(is-a?/c image-snip%)]{
|
||||
|
||||
Plots @racket[data] in 2-D, where @racket[data] is generated by
|
||||
functions like @racket[points] or @racket[lines].
|
||||
|
||||
A @racket[data] value is represented as a procedure that takes a
|
||||
@racket[2d-view%] instance and adds plot information to it.
|
||||
|
||||
The result is a @racket[image-snip%] for the plot. If an @racket[#:out-file]
|
||||
path or port is provided, the plot is also written as a PNG image to
|
||||
the given path or port.}
|
||||
|
||||
@defproc[(plot3d [data ((is-a?/c 3d-view%) . -> . void?)]
|
||||
[#:width width real? 400]
|
||||
[#:height height real? 400]
|
||||
[#:x-min x-min real? -5]
|
||||
[#:x-max x-max real? 5]
|
||||
[#:y-min y-min real? -5]
|
||||
[#:y-max y-max real? 5]
|
||||
[#:z-min z-min real? -5]
|
||||
[#:z-max z-max real? 5]
|
||||
[#:alt alt real? 30]
|
||||
[#:az az real? 45]
|
||||
[#:x-label x-label string? "X axis"]
|
||||
[#:y-label y-label string? "Y axis"]
|
||||
[#:z-label z-label string? "Z axis"]
|
||||
[#:title title string? ""]
|
||||
[#:fgcolor fgcolor (list/c byte? byte? byte) '(0 0 0)]
|
||||
[#:bgcolor bgcolor (list/c byte? byte? byte) '(255 255 255)]
|
||||
[#:lncolor lncolor (list/c byte? byte? byte) '(255 0 0)])
|
||||
(is-a?/c image-snip%)]{
|
||||
|
||||
Plots @racket[data] in 3-D, where @racket[data] is generated by a
|
||||
function like @racket[surface]. The arguments @racket[alt] and
|
||||
@racket[az] set the viewing altitude (in degrees) and the azimuth
|
||||
(also in degrees), respectively.
|
||||
|
||||
A 3-D @racket[data] value is represented as a procedure that takes a
|
||||
@racket[3d-view%] instance and adds plot information to it.}
|
||||
|
||||
|
||||
@defproc[(points [vecs (listof (vector/c real? real?))]
|
||||
[#:sym sym (or/c character? integer? symbol?) 'fullsquare]
|
||||
[#:color color plot-color? 'black])
|
||||
((is-a?/c 2d-view%) . -> . void?)]{
|
||||
|
||||
Creates 2-D plot data (to be provided to @racket[plot]) given a list
|
||||
of points specifying locations. The @racket[sym] argument determines
|
||||
the appearance of the points. It can be a symbol, an ASCII character,
|
||||
or a small integer (between -1 and 127). The following symbols are
|
||||
known: @racket['pixel], @racket['dot], @racket['plus],
|
||||
@racket['asterisk], @racket['circle], @racket['times],
|
||||
@racket['square], @racket['triangle], @racket['oplus], @racket['odot],
|
||||
@racket['diamond], @racket['5star], @racket['6star],
|
||||
@racket['fullsquare], @racket['bullet], @racket['full5star],
|
||||
@racket['circle1], @racket['circle2], @racket['circle3],
|
||||
@racket['circle4], @racket['circle5], @racket['circle6],
|
||||
@racket['circle7], @racket['circle8], @racket['leftarrow],
|
||||
@racket['rightarrow], @racket['uparrow], @racket['downarrow]. }
|
||||
|
||||
|
||||
@defproc[(line [f (real? . -> . (or/c real? (vector real? real?)))]
|
||||
[#:samples samples exact-nonnegative-integer? 150]
|
||||
[#:width width exact-positive-integer? 1]
|
||||
[#:color color plot-color? 'red]
|
||||
[#:mode mode (one-of/c 'standard 'parametric) 'standard]
|
||||
[#:mapping mapping (or-of/c 'cartesian 'polar) 'cartesian]
|
||||
[#:t-min t-min real? -5]
|
||||
[#:t-max t-max real? 5])
|
||||
((is-a?/c 2d-view%) . -> . void?)]{
|
||||
|
||||
Creates 2-D plot data to draw a line.
|
||||
|
||||
The line is specified in either functional, i.e. @math{y = f(x)}, or
|
||||
parametric, i.e. @math{x,y = f(t)}, mode. If the function is
|
||||
parametric, the @racket[mode] argument must be set to
|
||||
@racket['parametric]. The @racket[t-min] and @racket[t-max] arguments
|
||||
set the parameter when in parametric mode.}
|
||||
|
||||
|
||||
@defproc[(error-bars [vecs (listof (vector/c real? real? real?))]
|
||||
[#:color color plot-color? 'black])
|
||||
((is-a?/c 2d-view%) . -> . void?)]{
|
||||
|
||||
Creates 2-D plot data for error bars given a list of vectors. Each
|
||||
vector specifies the center of the error bar @math{(x,y)} as the first
|
||||
two elements and its magnitude as the third.}
|
||||
|
||||
|
||||
@defproc[(vector-field [f ((vector real? real?) . -> . (vector real? real?))]
|
||||
[#:width width exact-positive-integer? 1]
|
||||
[#:color color plot-color? 'red]
|
||||
[#:style style (one-of/c 'scaled 'normalized 'read) 'scaled])
|
||||
((is-a?/c 2d-view%) . -> . void?)]{
|
||||
|
||||
Creates 2-D plot data to draw a vector-field from a vector-valued
|
||||
function.}
|
||||
|
||||
|
||||
@defproc[(contour [f (real? real? . -> . real?)]
|
||||
[#:samples samples exact-nonnegative-integer? 50]
|
||||
[#:width width exact-positive-integer? 1]
|
||||
[#:color color plot-color? 'black]
|
||||
[#:levels levels (or/c exact-nonnegative-integer?
|
||||
(listof real?))
|
||||
10])
|
||||
((is-a?/c 2d-view%) . -> . void?)]{
|
||||
|
||||
Creates 2-D plot data to draw contour lines, rendering a 3-D function
|
||||
a 2-D graph cotours (respectively) to represent the value of the
|
||||
function at that position.}
|
||||
|
||||
@defproc[(shade [f (real? real? . -> . real?)]
|
||||
[#:samples samples exact-nonnegative-integer? 50]
|
||||
[#:levels levels (or/c exact-nonnegative-integer?
|
||||
(listof real?))
|
||||
10])
|
||||
((is-a?/c 2d-view%) . -> . void?)]{
|
||||
|
||||
Creates 2-D plot data to draw like @racket[contour], except using
|
||||
shading instead of contour lines.}
|
||||
|
||||
|
||||
@defproc[(surface [f (real? real? . -> . real?)]
|
||||
[#:samples samples exact-nonnegative-integer? 50]
|
||||
[#:width width exact-positive-integer? 1]
|
||||
[#:color color plot-color? 'black])
|
||||
((is-a?/c 3d-view%) . -> . void?)]{
|
||||
|
||||
Creates 3-D plot data to draw a 3-D surface in a 2-D box, showing only
|
||||
the @italic{top} of the surface.}
|
||||
|
||||
|
||||
@defproc[(mix [data (any/c . -> . void?)] ...+)
|
||||
(any/c . -> . void?)]{
|
||||
|
||||
Creates a procedure that calls each @racket[data] on its argument in
|
||||
order. Thus, this function can composes multiple plot @racket[data]s
|
||||
into a single data.}
|
||||
|
||||
|
||||
@defproc[(plot-color? [v any/c]) boolean?]{
|
||||
|
||||
Returns @racket[#t] if @racket[v] is one of the following symbols,
|
||||
@racket[#f] otherwise:
|
||||
|
||||
@racketblock[
|
||||
'white 'black 'yellow 'green 'aqua 'pink
|
||||
'wheat 'grey 'blown 'blue 'violet 'cyan
|
||||
'turquoise 'magenta 'salmon 'red
|
||||
]}
|
||||
|
||||
@; ----------------------------------------
|
||||
|
||||
@subsection[#:tag "curve-fit"]{Curve Fitting}
|
||||
|
||||
PLoT uses the standard Non-Linear Least Squares fit algorithm for
|
||||
curve fitting. The code that implements the algorithm is public
|
||||
domain, and is used by the @tt{gnuplot} package.
|
||||
|
||||
@defproc[(fit [f (real? ... . -> . real?)]
|
||||
[guess-list (list/c (list symbol? real?))]
|
||||
[data (or/c (list-of (vector/c real? real? real?))
|
||||
(list-of (vector/c real? real? real? real?)))])
|
||||
fit-result?]{
|
||||
|
||||
Attempts to fit a @defterm{fittable function} to the data that is
|
||||
given. The @racket[guess-list] should be a set of arguments and
|
||||
values. The more accurate your initial guesses are, the more likely
|
||||
the fit is to succeed; if there are no good values for the guesses,
|
||||
leave them as @racket[1].}
|
||||
|
||||
@defstruct[fit-result ([rms real?]
|
||||
[variance real?]
|
||||
[names (listof symbol?)]
|
||||
[final-params (listof real?)]
|
||||
[std-error (listof real?)]
|
||||
[std-error-percent (listof real?)]
|
||||
[function (real? ... . -> . real?)])]{
|
||||
|
||||
The @racket[params] field contains an associative list of the
|
||||
parameters specified in @racket[fit] and their values. Note that the
|
||||
values may not be correct if the fit failed to converge. For a visual
|
||||
test, use the @racket[function] field to get the function with the
|
||||
parameters in place and plot it along with the original data.}
|
||||
|
||||
@; ----------------------------------------
|
||||
|
||||
@subsection{Miscellaneous Functions}
|
||||
|
||||
@defproc[(derivative [f (real? . -> . real?)] [h real? .000001])
|
||||
(real? . -> . real?)]{
|
||||
|
||||
Creates a function that evaluates the numeric derivative of
|
||||
@racket[f]. The given @racket[h] is the divisor used in the
|
||||
calculation.}
|
||||
|
||||
@defproc[(gradient [f (real? real? . -> . real?)] [h real? .000001])
|
||||
((vector/c real? real?) . -> . (vector/c real? real?))]{
|
||||
|
||||
Creates a vector-valued function that the numeric gradient of
|
||||
@racket[f].}
|
||||
|
||||
@defproc[(make-vec [fx (real? real? . -> . real?)] [fy (real? real? . -> . real?)])
|
||||
((vector/c real? real?) . -> . (vector/c real? real?))]{
|
||||
|
||||
Creates a vector-values function from two parts.}
|
||||
|
||||
@; ----------------------------------------
|
||||
|
||||
@section[#:tag "extend"]{Customizing Plots}
|
||||
|
||||
@defmodule[plot/extend]
|
||||
|
||||
The @racketmodname[plot/extend] module allows you to create your own
|
||||
constructors, further customize the appearance of the plot windows,
|
||||
and in general extend the package.
|
||||
|
||||
@defproc[(sample-size [sample-count exact-positive-integer?]
|
||||
[x-min number]
|
||||
[x-max number])
|
||||
real?]{
|
||||
|
||||
Given @racket[sample-count], @racket[x-min], and @racket[x-max], returns the
|
||||
size of each sample.}
|
||||
|
||||
|
||||
@defproc[(scale-vectors [vecs (listof vector?)] [x-sample-size real?] [y-sample-size real?])
|
||||
(listof vector?)]{
|
||||
|
||||
Scales vectors, causing them to fit in their boxes.}
|
||||
|
||||
|
||||
@defproc[(x-values [sample-count exact-positive-integer?]
|
||||
[x-min number]
|
||||
[x-max number])
|
||||
(listof real?)]{
|
||||
|
||||
Given @racket[samples], @racket[x-min], and @racket[x-max], returns a
|
||||
list of @racket[x]s spread across the range.}
|
||||
|
||||
|
||||
@defproc[(normalize-vector [vec vector?] [x-sample-size real?] [y-sample-size real?])
|
||||
vector?]{
|
||||
|
||||
Normalizes @racket[vec] based on @racket[x-sample-size] and
|
||||
@racket[y-sample-size].}
|
||||
|
||||
|
||||
@defproc[(normalize-vectors [vecs (listof vector?)] [x-sample-size real?] [y-sample-size real?])
|
||||
(listof vector?)]{
|
||||
|
||||
Normalizes @racket[vecs] based on @racket[x-sample-size] and
|
||||
@racket[y-sample-size].}
|
||||
|
||||
|
||||
@defproc[(make-column [x real?] [ys (listof real?)])
|
||||
(listof (vector/c real? real?))]{
|
||||
|
||||
Given an @racket[x] and a list of @racket[_y]s, produces a list of
|
||||
points pairing the @racket[x] with each of the @racket[_y]s.}
|
||||
|
||||
|
||||
@defproc[(xy-list [sample-count exact-positive-integer?]
|
||||
[x-min real?]
|
||||
[x-max real?]
|
||||
[y-min real?]
|
||||
[y-max real?])
|
||||
(listof (listof (vector/c real? real?)))]{
|
||||
|
||||
Makes a list of all the positions on the graph.}
|
||||
|
||||
|
||||
@defproc[(zgrid [f (real? real? . -> . real?)]
|
||||
[xs (listof real?)]
|
||||
[ys (listof real?)])
|
||||
(listof (listof real?))]{
|
||||
|
||||
Given a function that consumes @racket[_x] and @racket[_y] to produce
|
||||
@racket[_z], a list of @racket[_x]s, and a list of @racket[_y]s, produces a
|
||||
list of @racket[_z] column values.}
|
||||
|
||||
@; ----------------------------------------
|
||||
|
||||
@defclass[plot-view% image-snip% ()]{
|
||||
|
||||
@defmethod[(get-x-min) real?]{
|
||||
Returns the minimum plottable @racket[_x] coordinate.}
|
||||
|
||||
@defmethod[(get-y-min) real?]{
|
||||
Returns the minimum plottable @racket[_y] coordinate.}
|
||||
|
||||
@defmethod[(get-x-max) real?]{
|
||||
Returns the maximum plottable @racket[_x] coordinate.}
|
||||
|
||||
@defmethod[(get-y-max) real?]{
|
||||
Returns the maximum plottable @racket[_y] coordinate.}
|
||||
|
||||
@defmethod[(set-line-color [color plot-color?]) void?]{
|
||||
Sets the drawing color.}
|
||||
|
||||
@defmethod[(set-line-width [width real?]) void?]{
|
||||
Sets the drawing line width.}
|
||||
|
||||
}
|
||||
|
||||
@; ----------------------------------------
|
||||
|
||||
@defclass[2d-view% plot-view% ()]{
|
||||
|
||||
Provides an interface to drawing 2-D plots. An instance of
|
||||
@racket[2d-view%] is created by @racket[plot], and the following
|
||||
methods can be used to adjust it.
|
||||
|
||||
@defmethod[(set-labels [x-label string?]
|
||||
[y-label string?]
|
||||
[title string?])
|
||||
void?]{
|
||||
|
||||
Sets the axis labels and title.}
|
||||
|
||||
|
||||
@defmethod[(plot-vector [head (vector/c real? real?)]
|
||||
[tail (vector/c real? real?)])
|
||||
void?]{
|
||||
|
||||
Plots a single vector.}
|
||||
|
||||
|
||||
@defmethod[(plot-vectors [vecs (listof (list/c (vector/c real? real?)
|
||||
(vector/c real? real?)))])
|
||||
void?]{
|
||||
|
||||
Plots a set of vectors.}
|
||||
|
||||
|
||||
@defmethod[(plot-points [points (listof (vector/c real? real?))]
|
||||
[sym (or/c character? integer? symbol?)])
|
||||
void?]{
|
||||
|
||||
Plots points using a specified symbol. See @racket[points] for
|
||||
possible values for @racket[sym]}
|
||||
|
||||
|
||||
@defmethod[(plot-line [points (listof (vector/c real? real?))]) void?]{
|
||||
|
||||
Plots a line given a set of points.}
|
||||
|
||||
|
||||
@defmethod[(plot-contours [grid (listof (listof real?))]
|
||||
[xs (listof real?)]
|
||||
[ys (listof real?)]
|
||||
[levels (listof real?)]) void?]{
|
||||
|
||||
Plots a grid representing a 3-D function using contours to distinguish levels.}
|
||||
|
||||
@defmethod[(plot-shades [grid (listof (listof real?))]
|
||||
[xs (listof real?)]
|
||||
[ys (listof real?)]
|
||||
[levels (listof real?)]) void?]{
|
||||
|
||||
Plots a grid representing a 3-D function using shades to show levels.}
|
||||
|
||||
}
|
||||
|
||||
@; ----------------------------------------
|
||||
|
||||
@defclass[3d-view% plot-view% ()]{
|
||||
|
||||
Provides an interface to drawing 3-D plots. An instance of
|
||||
@racket[3d-view%] is created by @racket[plot3d], and the following
|
||||
methods can be used to adjust it.
|
||||
|
||||
|
||||
@defmethod[(plot-surface [xs (listof real?)]
|
||||
[ys (listof real?)]
|
||||
[zs (listof real?)]) void?]{
|
||||
|
||||
Plots a grid representing a 3d function in a 3d box, showing only the
|
||||
top of the surface.}
|
||||
|
||||
|
||||
@defmethod[(plot-line [xs (listof real?)]
|
||||
[ys (listof real?)]
|
||||
[zs (listof real?)]) void?]{
|
||||
|
||||
Plots a line in 3-D space.}
|
||||
|
||||
|
||||
@defmethod[(get-z-min) real?]{
|
||||
Returns the minimum plottable @racket[_z] coordinate.}
|
||||
|
||||
@defmethod[(get-z-max) real?]{
|
||||
Returns the maximum plottable @racket[_z] coordinate.}
|
||||
|
||||
@defmethod[(get-alt) real?]{
|
||||
Returns the altitude (in degrees) from which the 3-D box is viewed.}
|
||||
|
||||
@defmethod[(get-az) real?]{
|
||||
Returns the azimuthal angle.}
|
||||
|
||||
}
|
|
@ -1,408 +0,0 @@
|
|||
#lang racket/base
|
||||
(require mzlib/etc
|
||||
racket/list
|
||||
ffi/unsafe
|
||||
racket/runtime-path
|
||||
racket/class
|
||||
(for-syntax racket/base))
|
||||
|
||||
(define-runtime-path plplot-path '(so "libplplot"))
|
||||
(define-runtime-path font-dir "fonts")
|
||||
|
||||
(define libplplot (ffi-lib plplot-path))
|
||||
|
||||
(define plplotlibdir (get-ffi-obj "plplotLibDir" libplplot _string))
|
||||
|
||||
;; set the lib dir to contain the fonts:
|
||||
(let ([path font-dir])
|
||||
;; free current pointer, if any:
|
||||
(let ([p (get-ffi-obj "plplotLibDir" libplplot _pointer)])
|
||||
(when p (free p)))
|
||||
;; install new value:
|
||||
(set-ffi-obj! "plplotLibDir" libplplot _bytes
|
||||
;; malloc the string, since the GC won't see the static variable:
|
||||
(let* ([gced-bytes (path->bytes path)]
|
||||
[len (bytes-length gced-bytes)]
|
||||
[p (malloc (add1 len) 'raw)]
|
||||
[malloced-bytes (make-sized-byte-string p len)])
|
||||
(bytes-copy! malloced-bytes 0 gced-bytes)
|
||||
;; set nul terminator:
|
||||
(ptr-set! p _byte len 0)
|
||||
malloced-bytes)))
|
||||
|
||||
(define-cstruct _dc_Dev
|
||||
([user_data _pointer]
|
||||
[drawLine _fpointer]
|
||||
[drawLines _fpointer]
|
||||
[fillPoly _fpointer]
|
||||
[setWidth _fpointer]
|
||||
[setColor _fpointer]
|
||||
[setColorRGB _fpointer]
|
||||
[startPage _fpointer]
|
||||
[endPage _fpointer]
|
||||
[endDoc _fpointer]))
|
||||
|
||||
(define _PLINT _int)
|
||||
|
||||
(define _plflt _double*)
|
||||
(define _plint _int)
|
||||
|
||||
;; While an array generated from a list is passed to an
|
||||
;; plot library function, we might perform a GC through
|
||||
;; the back-end drawing operation. So, arrays must be
|
||||
;; allocated as non-moving objects
|
||||
(define-fun-syntax _list/still
|
||||
(lambda (stx)
|
||||
(syntax-case stx (i)
|
||||
[(_ i ty) #'(_list/still i ty 'atomic-interior)]
|
||||
[(_ i ty mode)
|
||||
#'(type: _pointer
|
||||
pre: (x => (list->cblock/mode x ty mode)))])))
|
||||
|
||||
(define-fun-syntax _matrix-of
|
||||
(lambda (stx)
|
||||
(syntax-case stx (i)
|
||||
[(_ ty)
|
||||
#'(_list/still i (_list/still i ty) 'interior)])))
|
||||
|
||||
(define (list->cblock/mode l type mode)
|
||||
(if (null? l)
|
||||
#f ; null => NULL
|
||||
(let ([cblock (malloc (length l) type mode)])
|
||||
(let loop ([l l] [i 0])
|
||||
(unless (null? l)
|
||||
(ptr-set! cblock type i (car l))
|
||||
(loop (cdr l) (add1 i))))
|
||||
cblock)))
|
||||
|
||||
(define-syntax define*
|
||||
(syntax-rules ()
|
||||
[(_ (name . args) body ...)
|
||||
(begin (provide name) (define (name . args) body ...))]
|
||||
[(_ name expr)
|
||||
(begin (provide name) (define name expr))]))
|
||||
|
||||
(define* pl-setup-page
|
||||
(get-ffi-obj "c_plspage" libplplot
|
||||
(_fun (xp : _plflt = 0.0)
|
||||
(yp : _plflt = 0.0)
|
||||
(xleng : _plint)
|
||||
(yleng : _plint)
|
||||
(xoff : _plint = 0)
|
||||
(yoff : _plint = 0)
|
||||
-> _void)))
|
||||
|
||||
(define* pl-set-device
|
||||
(get-ffi-obj "c_plsdev" libplplot (_fun _string -> _void)))
|
||||
|
||||
(define* pl-set-output-file
|
||||
(get-ffi-obj "c_plsfnam" libplplot (_fun _string -> _void)))
|
||||
|
||||
(define* pl-init-plot
|
||||
(get-ffi-obj "c_plinit" libplplot (_fun -> _dc_Dev-pointer)))
|
||||
|
||||
(define* pl-finish-plot
|
||||
(get-ffi-obj "c_plend" libplplot (_fun -> _void)))
|
||||
|
||||
(define* pl-set-plot-environment
|
||||
(get-ffi-obj "c_plenv" libplplot
|
||||
(_fun _plflt _plflt _plflt _plflt _plint _plint -> _void)))
|
||||
|
||||
(define* pl-set-labels
|
||||
(get-ffi-obj "c_pllab" libplplot
|
||||
(_fun _string _string _string -> _void)))
|
||||
|
||||
(define* pl-plot-line
|
||||
(get-ffi-obj "c_plline" libplplot
|
||||
(_fun _plint (x : (_list/still i _plflt)) (y : (_list/still i _plflt)) -> _void)))
|
||||
|
||||
(define* pl-plot-segment
|
||||
(get-ffi-obj "c_pljoin" libplplot
|
||||
(_fun _plflt _plflt _plflt _plflt -> _void)))
|
||||
|
||||
(define* pl-set-background-color
|
||||
(get-ffi-obj "c_plscolbg" libplplot
|
||||
(_fun _plint _plint _plint -> _void)))
|
||||
|
||||
|
||||
(define* pl-select-colormap0-index
|
||||
(get-ffi-obj "c_plcol0" libplplot
|
||||
(_fun _plint -> _void)))
|
||||
|
||||
(define* pl-set-colormap0-index
|
||||
(get-ffi-obj "c_plscol0" libplplot
|
||||
(_fun _plint _plint _plint _plint -> _void)))
|
||||
|
||||
(define* pl-set-line-width
|
||||
(get-ffi-obj "c_plwid" libplplot
|
||||
(_fun _plint -> _void)))
|
||||
|
||||
(define* pl-write-text
|
||||
(get-ffi-obj "c_plptex" libplplot
|
||||
(_fun _plflt _plflt _plflt _plflt _plflt _string -> _void)))
|
||||
|
||||
;;(define* pl-2d-countour-plot ...)
|
||||
;;(define* pl-2d-shade-plot ...)
|
||||
|
||||
(define* pl-x-error-bars
|
||||
(get-ffi-obj "c_plerrx" libplplot
|
||||
(_fun _plint (_list/still i _plflt)
|
||||
(_list/still i _plflt)
|
||||
(_list/still i _plflt) -> _void)))
|
||||
|
||||
(define* pl-y-error-bars
|
||||
(get-ffi-obj "c_plerry" libplplot
|
||||
(_fun _plint (_list/still i _plflt)
|
||||
(_list/still i _plflt)
|
||||
(_list/still i _plflt) -> _void)))
|
||||
|
||||
(define* pl-plot-points
|
||||
(get-ffi-obj "c_plpoin" libplplot
|
||||
(_fun _plint (x : (_list/still i _plflt)) (y : (_list/still i _plflt)) _plint
|
||||
-> _void)))
|
||||
|
||||
(define* pl-fill
|
||||
(get-ffi-obj "c_plfill" libplplot
|
||||
(_fun (n : _plint = (length x-values))
|
||||
(x-values : (_list/still i _plflt))
|
||||
(y-values : (_list/still i _plflt))
|
||||
-> _void)))
|
||||
|
||||
(define* pl-world-3d
|
||||
(get-ffi-obj "c_plw3d" libplplot
|
||||
(_fun
|
||||
_plflt _plflt _plflt _plflt _plflt _plflt _plflt _plflt _plflt _plflt _plflt
|
||||
->
|
||||
_void)))
|
||||
|
||||
;; bit-masks for some of the functions..
|
||||
(define-values (DRAW_LINEX DRAW_LINEY MAG_COLOR BASE_CONT TOP_CONT SURF_CONT DRAW_SIDES DRAW_FACETED MESH)
|
||||
(apply values (build-list 9 (lambda (s) (arithmetic-shift 1 s)))))
|
||||
|
||||
(define DRAW_LINEXY (bitwise-ior DRAW_LINEX DRAW_LINEY))
|
||||
|
||||
|
||||
(define* pl-plot3d
|
||||
(get-ffi-obj "c_plot3d" libplplot
|
||||
(_fun
|
||||
(x-values : (_list/still i _plflt))
|
||||
(y-values : (_list/still i _plflt))
|
||||
(z-values : (_matrix-of _plflt))
|
||||
(nx : _int = (length x-values))
|
||||
(ny : _int = (length y-values))
|
||||
(draw-opt1 : _int = DRAW_LINEXY)
|
||||
(draw-opt2 : _int = 0)
|
||||
-> _void))) ;; these are documented in the plplot ref manual, and will be obseleted.
|
||||
|
||||
(define* pl-mesh3d
|
||||
(get-ffi-obj "c_plot3d" libplplot
|
||||
(_fun
|
||||
(x-values : (_list/still i _plflt))
|
||||
(y-values : (_list/still i _plflt))
|
||||
(z-values : (_matrix-of _plflt))
|
||||
(nx : _int = (length x-values))
|
||||
(ny : _int = (length y-values))
|
||||
(draw-opt1 : _int = DRAW_LINEXY)
|
||||
-> _void)))
|
||||
|
||||
; ;; this function needs to go.
|
||||
; (define* pl-plot-points
|
||||
; (get-ffi-obj "c_plpoin" libplplot
|
||||
; (_fun
|
||||
; (nx : _int = (length x-values))
|
||||
; (x-values : (_list/still i _plflt))
|
||||
; (y-values : (_list/still i _plflt))
|
||||
; (code : _int))))
|
||||
|
||||
(define* pl-box3
|
||||
(get-ffi-obj "c_plbox3" libplplot
|
||||
(_fun
|
||||
(x-ops : _string) (x-title : _string) (x-spacing : _plflt) (x-ticks : _int)
|
||||
(y-ops : _string) (y-title : _string) (y-spacing : _plflt) (y-ticks : _int)
|
||||
(z-ops : _string) (z-title : _string) (z-spacing : _plflt) (z-ticks : _int)
|
||||
-> _void)))
|
||||
|
||||
(define* pl-line3
|
||||
(get-ffi-obj "c_plline3" libplplot
|
||||
(_fun
|
||||
(n-points : _int = (length x-values))
|
||||
(x-values : (_list/still i _plflt))
|
||||
(y-values : (_list/still i _plflt))
|
||||
(z-values : (_list/still i _plflt))
|
||||
-> _void)))
|
||||
|
||||
|
||||
(define* pl-poly3
|
||||
(get-ffi-obj "c_plpoly3" libplplot
|
||||
(_fun
|
||||
(n-points : _int = (length x-values))
|
||||
(x-values : (_list/still i _plflt))
|
||||
(y-values : (_list/still i _plflt))
|
||||
(z-values : (_list/still i _plflt))
|
||||
(draw-mask : (_list/still i _int))
|
||||
(direction : _int)
|
||||
-> _void)))
|
||||
|
||||
;; need the CStruct PLcGrid ;
|
||||
;; PLFLT *xg, *yg, *zg;
|
||||
;; PLINT nx, ny, nz;
|
||||
(define-cstruct _PLcGrid ((xg _pointer)
|
||||
(yg _pointer)
|
||||
(zg _pointer)
|
||||
(nx _int)
|
||||
(ny _int)
|
||||
(nz _int)))
|
||||
|
||||
(define pl-2d-contour-plot-int
|
||||
(get-ffi-obj "c_plcont" libplplot
|
||||
(_fun
|
||||
(matrix : (_matrix-of _plflt))
|
||||
(nx : _int = (PLcGrid-nx grid))
|
||||
(ny : _int = (PLcGrid-ny grid))
|
||||
(t1 : _plint = 1)
|
||||
(t2 : _int = (PLcGrid-nx grid))
|
||||
(t3 : _plint = 1)
|
||||
(t4 : _int = (PLcGrid-ny grid))
|
||||
(levels : (_list/still i _plflt))
|
||||
(nlevels : _int = (length levels))
|
||||
(pltr : _fpointer = (get-ffi-obj "pltr1" libplplot _fpointer))
|
||||
(grid : _PLcGrid-pointer)
|
||||
-> _void)))
|
||||
|
||||
(define* (pl-2d-contour-plot z-vals x-vals y-vals levels)
|
||||
(let ((grid-obj (make-PLcGrid (list->cblock x-vals _plflt) (list->cblock y-vals _plflt) #f
|
||||
(length x-vals) (length y-vals) 0)))
|
||||
(pl-2d-contour-plot-int z-vals levels grid-obj)))
|
||||
|
||||
|
||||
|
||||
(define pl-2d-shade-plot-int
|
||||
(get-ffi-obj "c_plshades" libplplot
|
||||
(_fun
|
||||
(matrix : (_matrix-of _plflt))
|
||||
(nx : _int = (PLcGrid-nx grid))
|
||||
(ny : _int = (PLcGrid-ny grid))
|
||||
(null-val : _pointer = #f)
|
||||
(x_min : _plflt = 0)
|
||||
(x_max : _plflt = 0)
|
||||
(y_min : _plflt = 0)
|
||||
(y_max : _plflt = 0)
|
||||
(levels : (_list/still i _plflt))
|
||||
(nlevels : _int = (length levels))
|
||||
(fill_width : _int = 1)
|
||||
(cont_col : _int = 1)
|
||||
(cont_width : _int = 0)
|
||||
(fill_fun : _fpointer = (get-ffi-obj "c_plfill" libplplot _fpointer))
|
||||
(rectan : _int = 1)
|
||||
(pltr : _fpointer = (get-ffi-obj "pltr1" libplplot _fpointer))
|
||||
(grid : _PLcGrid-pointer)
|
||||
-> _void)))
|
||||
|
||||
(define* (pl-2d-shade-plot z-vals x-vals y-vals levels)
|
||||
;; this can prolly be inlined above..
|
||||
(let ((grid-obj (make-PLcGrid (list->cblock x-vals _plflt) (list->cblock y-vals _plflt) #f
|
||||
(length x-vals) (length y-vals) 0)))
|
||||
(pl-2d-shade-plot-int z-vals levels grid-obj)))
|
||||
|
||||
|
||||
;; set up color map numbers
|
||||
(define plscmap1n
|
||||
(get-ffi-obj "c_plscmap1n" libplplot
|
||||
(_fun _int -> _void)))
|
||||
|
||||
;; set up the map
|
||||
(define plscmap1l
|
||||
(get-ffi-obj "c_plscmap1l" libplplot
|
||||
(_fun
|
||||
(itype : _plint)
|
||||
(npts : _int = (length intencity))
|
||||
(intencity : (_list/still i _plflt))
|
||||
(coord1 : (_list/still i _plflt))
|
||||
(coord2 : (_list/still i _plflt))
|
||||
(coord3 : (_list/still i _plflt))
|
||||
(rev : _pointer = #f)
|
||||
-> _void)))
|
||||
|
||||
(define pl-mesh3dc-int
|
||||
(get-ffi-obj "c_plmeshc" libplplot
|
||||
(_fun
|
||||
(x-values : (_list/still i _plflt))
|
||||
(y-values : (_list/still i _plflt))
|
||||
(z-values : (_matrix-of _plflt))
|
||||
(x-len : _int = (length x-values))
|
||||
(y-len : _int = (length y-values))
|
||||
(opts : _int)
|
||||
(levels : (_list/still i _plflt))
|
||||
(n-levels : _int = (length levels))
|
||||
-> _void)))
|
||||
|
||||
(define* (pl-mesh3dc x-vals y-vals z-vals contours? lines? colored? sides? levels)
|
||||
(let ((opts (foldl
|
||||
(lambda (mask use? current) (bitwise-ior current (if use? mask 0)))
|
||||
0
|
||||
(list DRAW_LINEXY MAG_COLOR BASE_CONT DRAW_SIDES)
|
||||
(list contours? lines? colored? sides?))))
|
||||
(plscmap1n 256)
|
||||
(plscmap1l 0 '(0.0 1.0) '(240 0) '(.6 .6) '(.8 .8))
|
||||
(pl-mesh3dc-int x-vals y-vals z-vals opts levels)))
|
||||
|
||||
(define (dc-draw-line dest x1 y1 x2 y2)
|
||||
(send (ptr-ref dest _racket) draw-line x1 y1 x2 y2))
|
||||
(define (dc-draw-multi dest xs ys n go)
|
||||
(let ([xs (cast xs _pointer (_vector o _short n))]
|
||||
[ys (cast ys _pointer (_vector o _short n))])
|
||||
(go (ptr-ref dest _racket)
|
||||
(for/list ([x (in-vector xs)]
|
||||
[y (in-vector ys)])
|
||||
(cons x y)))))
|
||||
(define (dc-draw-lines dest xs ys n)
|
||||
(dc-draw-multi dest xs ys n
|
||||
(lambda (dc l) (send dc draw-lines l))))
|
||||
(define (dc-fill-poly dest xs ys n)
|
||||
(dc-draw-multi dest xs ys n
|
||||
(lambda (dc l) (send dc draw-polygon l))))
|
||||
(define (dc-set-width dest w)
|
||||
(send (ptr-ref dest _racket) set-width w))
|
||||
(define (dc-set-color dest index)
|
||||
(send (ptr-ref dest _racket) set-index-color index))
|
||||
(define (dc-set-color/rgb dest r g b)
|
||||
(send (ptr-ref dest _racket) set-rgb-color r g b))
|
||||
(define (dc-start-page dest)
|
||||
(send (ptr-ref dest _racket) start-page))
|
||||
(define (dc-end-page dest)
|
||||
(send (ptr-ref dest _racket) end-page))
|
||||
(define (dc-end-doc dest)
|
||||
(send (ptr-ref dest _racket) end-doc)
|
||||
(free-immobile-cell dest))
|
||||
|
||||
(define draw_line (function-ptr dc-draw-line
|
||||
(_fun _pointer _short _short _short _short -> _void)))
|
||||
(define draw_lines (function-ptr dc-draw-lines
|
||||
(_fun _pointer _pointer _pointer _PLINT -> _void)))
|
||||
(define fill_poly (function-ptr dc-fill-poly
|
||||
(_fun _pointer _pointer _pointer _PLINT -> _void)))
|
||||
(define set_width (function-ptr dc-set-width
|
||||
(_fun _pointer _int -> _void)))
|
||||
(define set_color (function-ptr dc-set-color
|
||||
(_fun _pointer _short -> _void)))
|
||||
(define set_color_rgb (function-ptr dc-set-color/rgb
|
||||
(_fun _pointer _short _short _short -> _void)))
|
||||
(define start_page (function-ptr dc-start-page
|
||||
(_fun _pointer -> _void)))
|
||||
(define end_page (function-ptr dc-end-page
|
||||
(_fun _pointer -> _void)))
|
||||
(define end_doc (function-ptr dc-end-doc
|
||||
(_fun _pointer -> _void)))
|
||||
|
||||
(provide init-dev!)
|
||||
(define (init-dev! dev obj)
|
||||
(set-dc_Dev-user_data! dev (malloc-immobile-cell obj))
|
||||
(set-dc_Dev-drawLine! dev draw_line)
|
||||
(set-dc_Dev-drawLines! dev draw_lines)
|
||||
(set-dc_Dev-fillPoly! dev fill_poly)
|
||||
(set-dc_Dev-setWidth! dev set_width)
|
||||
(set-dc_Dev-setColor! dev set_color)
|
||||
(set-dc_Dev-setColorRGB! dev set_color_rgb)
|
||||
(set-dc_Dev-startPage! dev start_page)
|
||||
(set-dc_Dev-endPage! dev end_page)
|
||||
(set-dc_Dev-endDoc! dev end_doc))
|
|
@ -1,58 +0,0 @@
|
|||
(module renderer-helpers mzscheme
|
||||
|
||||
; Contains the helpers for the plot-renderers package
|
||||
; useful for building your own renderers
|
||||
|
||||
(require mzlib/list mzlib/math plot/math)
|
||||
|
||||
; sample-size: number number number -> number
|
||||
(define (sample-size samples x-min x-max)
|
||||
(/ (- x-max x-min) (- samples 1)))
|
||||
|
||||
; scale-vectors : listof-posn number number -> listof-posn
|
||||
; scales vectors, causing them to fit in their boxes
|
||||
(define (scale-vectors deltas x-sample-size y-sample-size)
|
||||
(let* ((x-max-value (apply max (map vector-x deltas)))
|
||||
(y-max-value (apply max (map vector-y deltas)))
|
||||
(x-div-const (/ x-max-value x-sample-size))
|
||||
(y-div-const (/ y-max-value y-sample-size)))
|
||||
(map (lambda (point) (vector (* (/ (vector-x point) x-div-const) 9/10)
|
||||
(* (/ (vector-y point) y-div-const) 9/10))) deltas)))
|
||||
|
||||
; x-values : number number number -> listof-number
|
||||
(define (x-values samples x-min x-max)
|
||||
(let ((ss (sample-size samples x-min x-max)))
|
||||
(build-list samples (lambda (x) (+ x-min (* x ss))))))
|
||||
|
||||
; normalze-vector : posn number number -> posn
|
||||
(define (normalize-vector vec x-sample-size y-sample-size)
|
||||
(let* ((size (vector-magnitude vec)))
|
||||
(if (zero? size)
|
||||
(vector 0 0)
|
||||
(vector (* (/ (vector-x vec) size) x-sample-size 9/10)
|
||||
(* (/ (vector-y vec) size) y-sample-size 9/10)))))
|
||||
|
||||
; normalize-vector : listof-posn number number -> listolf-posn
|
||||
(define (normalize-vectors deltas x-sample-size y-sample-size)
|
||||
(map (lambda (vec) (normalize-vector vec x-sample-size y-sample-size)) deltas))
|
||||
|
||||
; make-column : number listof-number -> listof-points
|
||||
(define (make-column x-val y-values)
|
||||
(map (lambda (y) (vector x-val y)) y-values))
|
||||
|
||||
; xy-list : number number number number number -> listof-posn
|
||||
; make a list of all the positions on the graph
|
||||
(define (xy-list samples x-min x-max y-min y-max)
|
||||
(let* ((x-vals (x-values samples x-min x-max))
|
||||
(y-vals (x-values samples y-min y-max)))
|
||||
(apply append (map (lambda (x) (make-column x y-vals)) x-vals))))
|
||||
|
||||
; zgrid : (number number -> number) listof-number listof-number -> listof-listof number
|
||||
(define (zgrid func x-vals y-vals samples)
|
||||
(map (lambda (x) (map (lambda (y) (func x y)) y-vals)) x-vals))
|
||||
|
||||
(provide (all-defined))
|
||||
|
||||
(require mzlib/class mzlib/etc)
|
||||
|
||||
)
|
|
@ -1,180 +0,0 @@
|
|||
(module renderers mzscheme
|
||||
(require plot/math plot/renderer-helpers mzlib/class plot/plot-extend)
|
||||
|
||||
;line : (number -> number) [number] [symbol] [number] -> (2dplotview -> nothing)
|
||||
(define-plot-type line
|
||||
func 2dplotview (x-min x-max) ((samples 150) (color 'red)
|
||||
(width 1)
|
||||
(mode 'standard)
|
||||
(mapping 'cartesian)
|
||||
(t-min -5) (t-max 5))
|
||||
(let*
|
||||
((t-min (if (or (eq? mapping 'polar) (eq? mode 'parametric))
|
||||
t-min x-min))
|
||||
(t-max (if (or (eq? mapping 'polar)(eq? mode 'parametric))
|
||||
t-max x-max)) ; maybe let-values?
|
||||
(points
|
||||
(case mode
|
||||
((standard) (map (lambda (x) (vector x (func x)))
|
||||
(x-values samples x-min x-max)))
|
||||
((parametric) (map func (x-values samples t-min t-max))))))
|
||||
(send* 2dplotview
|
||||
(set-line-color color) (set-line-width width)
|
||||
(plot-line
|
||||
(case mapping
|
||||
((cartesian) points)
|
||||
((polar) (map
|
||||
(lambda (point) ; convert to cartesian from theta, r
|
||||
(vector
|
||||
(* (vector-y point) (cos (vector-x point)))
|
||||
(* (vector-y point) (sin (vector-x point)))))
|
||||
points)))))))
|
||||
|
||||
; error-bars : (listof (vector x y err)) [symbol] -> (2dplotview -> nothing)
|
||||
(define-plot-type error-bars
|
||||
errs 2dplotview () ((color 'red))
|
||||
(let* ((y-list (map vector-y errs))
|
||||
(e-list (map vector-z errs))
|
||||
(y-mins (map (lambda (y e) (- y e)) y-list e-list ))
|
||||
(y-maxs (map (lambda (y e) (+ y e)) y-list e-list )))
|
||||
(send 2dplotview set-line-color color)
|
||||
(send 2dplotview plot-y-errors (map vector (map vector-x errs)
|
||||
y-mins y-maxs))))
|
||||
|
||||
|
||||
; field : (vector -> vector) [number] [symbol] [number] [symbol] -> (2dplotview -> nothing)
|
||||
; plots a vector field
|
||||
; styles are
|
||||
; scaled -> vector field with scaled vectors
|
||||
; normalized -> all vectors same size, indicates direction
|
||||
; real -> all vectors drawn to scale
|
||||
(define-plot-type vector-field
|
||||
vfun 2dplotview
|
||||
(x-min x-max y-min y-max)
|
||||
([samples 20] [color 'black] [width 1] [style 'scaled])
|
||||
(let* ((points (xy-list samples x-min x-max y-min y-max))
|
||||
(results (map vfun points))
|
||||
(new-results
|
||||
(case style
|
||||
[(real) results]
|
||||
[(scaled) (scale-vectors results
|
||||
(sample-size samples x-min x-max)
|
||||
(sample-size samples y-min y-max))]
|
||||
[(normalized) (normalize-vectors
|
||||
results
|
||||
(sample-size samples x-min x-max)
|
||||
(sample-size samples y-min y-max))]
|
||||
[else (error (string-append "Unknown vector field style passed to field-renderer: " (symbol->string style)))])))
|
||||
(send* 2dplotview
|
||||
(set-line-color color) (set-line-width width)
|
||||
(plot-vectors points new-results))))
|
||||
|
||||
; contour : (nubmer number -> number) [number] [symbol] [number] [number u listof-number] -> (2dplotview -> void)
|
||||
; renders a contour plot given function and contour levels
|
||||
(define-plot-type contour
|
||||
fun3d 2dplotview
|
||||
(x-min x-max y-min y-max)
|
||||
((samples 50) (color 'black) (width 1) (levels 10))
|
||||
(let* ((x-vals (x-values samples x-min x-max))
|
||||
(y-vals (x-values samples y-min y-max))
|
||||
(grid (zgrid fun3d x-vals y-vals samples))
|
||||
(z-max (apply max (map (lambda (row) (apply max row)) grid)))
|
||||
(z-min (apply min (map (lambda (row) (apply min row)) grid)))
|
||||
(c-levels (if (list? levels) levels (x-values levels z-min z-max))))
|
||||
(send* 2dplotview
|
||||
(set-line-color color) (set-line-width width)
|
||||
(plot-contours grid x-vals y-vals c-levels))))
|
||||
|
||||
; shade : (number number -> number) [number] [symbol] [number] [number / listof-number] -> (2dplotview -> nothing)
|
||||
; renders a shade plot given function and shade levels
|
||||
(define-plot-type shade
|
||||
fun3d 2dplotview (x-min x-max y-min y-max)
|
||||
((samples 50) (levels 10))
|
||||
(let* ((x-vals (x-values samples x-min x-max))
|
||||
(y-vals (x-values samples y-min y-max))
|
||||
(grid (zgrid fun3d x-vals y-vals samples))
|
||||
(z-max (apply max (map (lambda (row) (apply max row)) grid)))
|
||||
(z-min (apply min (map (lambda (row) (apply min row)) grid)))
|
||||
(c-levels (x-values levels z-min z-max)))
|
||||
(send* 2dplotview
|
||||
(plot-shades grid x-vals y-vals c-levels))))
|
||||
|
||||
; points : (listof vector) [symbol] -> (2dplotview -> nothing)
|
||||
; plots a set of points using a specific character
|
||||
(define-plot-type points
|
||||
lop 2dplotview ((sym 'fullsquare) (color 'black))
|
||||
(send* 2dplotview
|
||||
(set-line-color color)
|
||||
(plot-points lop
|
||||
(cond [(and (integer? sym) (<= -1 sym 127)) sym]
|
||||
[(and (char? sym)
|
||||
(char<=? (integer->char 32)
|
||||
sym
|
||||
(integer->char 127)))
|
||||
(char->integer sym)]
|
||||
[(assq sym point-syms) => cadr]
|
||||
[else (error "Symbol not found in table!")]))))
|
||||
|
||||
; the symbol-> char table
|
||||
(define point-syms
|
||||
'((pixel -1)
|
||||
(dot 1)
|
||||
(plus 2)
|
||||
(asterisk 3)
|
||||
(circle 4)
|
||||
(times 5)
|
||||
(square 6)
|
||||
(triangle 7)
|
||||
(oplus 8)
|
||||
(odot 9)
|
||||
;; (??? 10)
|
||||
(diamond 11)
|
||||
(5star 12)
|
||||
;; (square 13)
|
||||
;; (??? 14)
|
||||
(6star 15)
|
||||
(fullsquare 16)
|
||||
(bullet 17)
|
||||
(full5star 18)
|
||||
;; (square 19)
|
||||
(circle1 20)
|
||||
(circle2 21)
|
||||
(circle3 22)
|
||||
(circle4 23)
|
||||
(circle5 24)
|
||||
(circle6 25)
|
||||
(circle7 26)
|
||||
(circle8 27)
|
||||
(leftarrow 28)
|
||||
(rightarrow 29)
|
||||
(uparrow 30)
|
||||
(downarrow 31)))
|
||||
|
||||
|
||||
;; 3D PLOTTERS
|
||||
; plot a surface
|
||||
(define-plot-type surface
|
||||
fun3d 3dplotview (x-min x-max y-min y-max)
|
||||
((samples 50) (color 'black) (width '1))
|
||||
(let* ((x-vals (x-values samples x-min x-max))
|
||||
(y-vals (x-values samples y-min y-max))
|
||||
(grid (zgrid fun3d x-vals y-vals samples)))
|
||||
(send* 3dplotview
|
||||
(set-line-color color) (set-line-width width)
|
||||
(plot-surface x-vals y-vals grid))))
|
||||
|
||||
(define-plot-type mesh3d
|
||||
fun3d 3dplotview (x-min x-max y-min y-max z-min z-max)
|
||||
((samples 50) (width '1) (levels 10) (color #t) (lines #t)
|
||||
(contours #t) (sides #f))
|
||||
(let* ((x-vals (x-values samples x-min x-max))
|
||||
(y-vals (x-values samples y-min y-max))
|
||||
(grid (zgrid fun3d x-vals y-vals samples))
|
||||
(c-levels (if (list? levels) levels (x-values levels z-min z-max))))
|
||||
(send* 3dplotview
|
||||
(set-line-width width)
|
||||
(plot-3dmesh x-vals y-vals grid lines color contours sides c-levels))))
|
||||
|
||||
(provide (all-defined)))
|
||||
|
||||
|
|
@ -1,354 +0,0 @@
|
|||
(module view mzscheme
|
||||
(require plot/plplot plot/math mzlib/class mzlib/file
|
||||
racket/draw racket/snip
|
||||
mzlib/math)
|
||||
|
||||
;; including suggested fix from Doug Williams
|
||||
|
||||
; macro for creating a field in a class with a getter and a setter
|
||||
(define-syntax (fields-with-accessors stx)
|
||||
(define (join-identifier prefix ident)
|
||||
(datum->syntax-object
|
||||
ident
|
||||
(string->symbol (string-append (symbol->string prefix )(symbol->string (syntax-e ident)))) ))
|
||||
(syntax-case stx ()
|
||||
[(_ (field init) ... )
|
||||
(let ((accessors (map (lambda (id) (join-identifier 'get- id)) (syntax-e #'(field ...))))
|
||||
(setters (map (lambda (id) (join-identifier 'set- id)) (syntax-e #'(field ...)))))
|
||||
(with-syntax (((accessor ... ) accessors)
|
||||
((setter ...) setters))
|
||||
#'(fields-with-accessors-helper (accessor setter field init) ...)))]))
|
||||
|
||||
; for accessors
|
||||
(define-syntax fields-with-accessors-helper
|
||||
(syntax-rules ()
|
||||
[(_ (accessor setter field init) ...)
|
||||
(begin
|
||||
(init-field (field init)) ...
|
||||
(define (accessor) field) ...
|
||||
(define (setter val) (set! field val)) ...) ]))
|
||||
|
||||
|
||||
; base class for a plot view
|
||||
;
|
||||
(define plot-view%
|
||||
(class* image-snip% ()
|
||||
(public
|
||||
set-line-color
|
||||
set-line-width
|
||||
set-plot-environment
|
||||
reset-to-default
|
||||
get-x-min
|
||||
get-x-max
|
||||
get-y-min
|
||||
get-y-max
|
||||
|
||||
get-x-label
|
||||
get-y-label
|
||||
get-title
|
||||
start-plot
|
||||
finish-plot
|
||||
|
||||
get-renderer
|
||||
|
||||
get-height
|
||||
get-width)
|
||||
|
||||
(init-field
|
||||
renderer)
|
||||
|
||||
(fields-with-accessors
|
||||
(height 300)
|
||||
(width 400)
|
||||
(out-file #f) ;; if file is not #f, keep the file
|
||||
(x-min -5)
|
||||
(x-max 5)
|
||||
(y-min -5)
|
||||
(y-max 5)
|
||||
(x-label "X axis")
|
||||
(y-label "Y axis")
|
||||
(title "")
|
||||
(device 'dc)
|
||||
(fgcolor '(0 0 0))
|
||||
(bgcolor '(255 255 255))
|
||||
(lncolor '(255 0 0)))
|
||||
|
||||
(define x-size 400)
|
||||
(define y-size 300)
|
||||
(define bitmap (make-bitmap width height))
|
||||
|
||||
(inherit
|
||||
set-bitmap
|
||||
load-file)
|
||||
|
||||
(define (get-renderer) renderer)
|
||||
|
||||
; set the initial environment
|
||||
(define (set-plot-environment x-min x-max y-min y-max just other)
|
||||
(pl-set-plot-environment x-min x-max y-min y-max just other))
|
||||
|
||||
; changes the *initial* colormap to match the colors
|
||||
; this should probably be done dynamically
|
||||
(define (init-colors)
|
||||
(apply pl-set-colormap0-index 0 bgcolor) ; 0 to white
|
||||
(apply pl-set-colormap0-index 1 fgcolor) ; 1 to black
|
||||
(apply pl-set-colormap0-index 15 lncolor)) ; 15 to red
|
||||
|
||||
; these are the colors to whitch the plot will be initialzed
|
||||
(define colors '((white 0) (black 1) (yellow 2) (green 3)
|
||||
(aqua 4) (pink 5) (wheat 6) (grey 7)
|
||||
(brown 8) (blue 9) (violet 10) (cyan 11)
|
||||
(turquoise 12) (magenta 13) (salmon 14) (red 15)))
|
||||
|
||||
; set-line-width : number -> nothing
|
||||
(define (set-line-width width) (pl-set-line-width width))
|
||||
|
||||
; reset-to-default : void
|
||||
; resets some of the state to default
|
||||
(define (reset-to-default)
|
||||
(init-colors)
|
||||
(set-line-color 'black)
|
||||
(set-line-width 0))
|
||||
|
||||
;set-line-color : symbol -> nothing
|
||||
(define (set-line-color color)
|
||||
(let ((index (cond [(assq color colors ) => cadr]
|
||||
[else (error (format "color ~v not found" color))])))
|
||||
(pl-select-colormap0-index index)))
|
||||
|
||||
; start the plot
|
||||
; does housekeeping/setup for plplot
|
||||
(define (start-plot)
|
||||
(cond
|
||||
[(eq? device 'dc)
|
||||
(init-colors)
|
||||
(pl-setup-page width height)
|
||||
(pl-set-device "dc")
|
||||
(let ([dev (pl-init-plot)])
|
||||
(init-dev! dev (let ([dc (make-object bitmap-dc% bitmap)])
|
||||
(send dc set-origin 0 height)
|
||||
(send dc set-scale 1 -1)
|
||||
(send dc set-smoothing 'aligned)
|
||||
(send dc set-background (apply make-object color% bgcolor))
|
||||
(send dc clear)
|
||||
(new (class object%
|
||||
(define/public (draw-line x1 y1 x2 y2)
|
||||
(send dc draw-line x1 y1 x2 y2))
|
||||
(define/public (draw-lines points)
|
||||
(send dc draw-lines points))
|
||||
(define/public (draw-polygon points)
|
||||
(send dc draw-polygon points))
|
||||
(define/public (set-width n)
|
||||
(send dc set-pen (send (send dc get-pen) get-color) n 'solid))
|
||||
(define/public (set-index-color i)
|
||||
(let ([color (case i
|
||||
[(0) (apply make-object color% bgcolor)]
|
||||
[(1) (apply make-object color% fgcolor)]
|
||||
[(15) (apply make-object color% lncolor)]
|
||||
[else (make-object color% (symbol->string (car (list-ref colors i))))])])
|
||||
(send dc set-pen color (send (send dc get-pen) get-width) 'solid)
|
||||
(send dc set-brush color 'solid)))
|
||||
(define/public (set-rgb-color r g b)
|
||||
(let ([color (make-object color% r g b)])
|
||||
(send dc set-pen color (send (send dc get-pen) get-width) 'solid)
|
||||
(send dc set-brush color 'solid)))
|
||||
(define/public (start-page) (void))
|
||||
(define/public (end-page) (void))
|
||||
(define/public (end-doc)
|
||||
(send dc set-bitmap #f))
|
||||
(super-new))))))
|
||||
(set-line-color 'black)
|
||||
(set-line-width 0)]
|
||||
[else
|
||||
(error "Incorrect device specified")]))
|
||||
|
||||
; finish the plot.. loads the file
|
||||
(define (finish-plot)
|
||||
(cond
|
||||
[(eq? device 'dc)
|
||||
(pl-finish-plot)
|
||||
(when out-file
|
||||
(send bitmap save-file out-file 'png))
|
||||
(set-bitmap bitmap)]
|
||||
[else
|
||||
(error "Incorrect device specified")]))
|
||||
|
||||
(super-instantiate ())))
|
||||
|
||||
;; a 2d plot view
|
||||
(define 2d-view%
|
||||
(class* plot-view% ()
|
||||
(public
|
||||
set-labels
|
||||
plot-y-errors
|
||||
plot-vector
|
||||
plot-vectors
|
||||
plot-points
|
||||
plot-line
|
||||
plot-contours
|
||||
plot-shades
|
||||
fill)
|
||||
|
||||
; set-labels : string string string -> nothing
|
||||
; sets the x, y and title lables
|
||||
(define (set-labels x-label y-label title)
|
||||
(pl-set-labels x-label y-label title))
|
||||
|
||||
; plot-contours: listoflistof number, listof-number, listof-number, listof-number
|
||||
(define (plot-contours z x-vals y-vals levels)
|
||||
(pl-2d-contour-plot z x-vals y-vals levels))
|
||||
|
||||
; plot-shades: listoflistof number, listof-number, listof-number, listof-number
|
||||
(define (plot-shades z x-vals y-vals levels)
|
||||
(pl-2d-shade-plot z x-vals y-vals levels))
|
||||
|
||||
; plot-line : (listof vector) -> void
|
||||
; plots a line with the given points
|
||||
(define (plot-line points)
|
||||
(pl-plot-line (length points)
|
||||
(map vector-x points)
|
||||
(map vector-y points)))
|
||||
|
||||
; plot-points : (listof vector) -> void
|
||||
; plots given points with a . symbol
|
||||
(define (plot-points points sym)
|
||||
(pl-plot-points (length points)
|
||||
(map vector-x points)
|
||||
(map vector-y points)
|
||||
sym))
|
||||
|
||||
(define v-head-ratio 1/4) ; size of the vector head
|
||||
(define rot (* 5 pi 1/6))
|
||||
|
||||
; plot-vectors: (listof (list vector vector)) - > void
|
||||
(define (plot-vectors from delta)
|
||||
(for-each (lambda (f d) (send this plot-vector f d)) from delta))
|
||||
|
||||
; plot-vector : vector vector -> nothing
|
||||
(define (plot-vector from delta)
|
||||
(unless (= 0 (vector-magnitude delta))
|
||||
(let* ((x (vector-x from)) (x2 (+ x (vector-x delta)))
|
||||
(y (vector-y from)) (y2 (+ y (vector-y delta)))
|
||||
(ang (atan (vector-y delta) (vector-x delta)))
|
||||
(len (vector-magnitude delta))
|
||||
(x3 (+ x2 (* len v-head-ratio (cos (+ ang rot)))))
|
||||
(x4 (+ x2 (* len v-head-ratio (cos (- ang rot)))))
|
||||
(y3 (+ y2 (* len v-head-ratio (sin (+ ang rot)))))
|
||||
(y4 (+ y2 (* len v-head-ratio (sin (- ang rot))))))
|
||||
(plot-line (list from
|
||||
(vector x2 y2)
|
||||
(vector x3 y3)
|
||||
(vector x4 y4)
|
||||
(vector x2 y2))))))
|
||||
|
||||
; fill : (list-of number) (list-of number) -> void
|
||||
(define (fill xs ys)
|
||||
(pl-fill xs ys))
|
||||
|
||||
; plot-y-errors (listof (vector x y-min y-max)) ->nothing
|
||||
; plots y error bars given a vector containing the x y and z (error magnitude) points
|
||||
(define (plot-y-errors errlist)
|
||||
(pl-y-error-bars (length errlist) (map vector-x errlist) (map vector-y errlist) (map vector-z errlist)))
|
||||
|
||||
|
||||
|
||||
(inherit start-plot set-plot-environment finish-plot
|
||||
get-x-min get-x-max get-y-min get-y-max get-renderer
|
||||
get-x-label get-y-label get-title)
|
||||
(define (plot)
|
||||
(start-plot)
|
||||
(set-plot-environment (get-x-min) (get-x-max) (get-y-min) (get-y-max) 0 1)
|
||||
(set-labels (get-x-label) (get-y-label) (get-title))
|
||||
(with-handlers ((exn? (lambda (ex) (finish-plot) (raise ex))))
|
||||
((get-renderer) this))
|
||||
(finish-plot)
|
||||
this)
|
||||
|
||||
(super-instantiate ())
|
||||
(plot)))
|
||||
|
||||
; 3d view
|
||||
; for making meshes and stuff
|
||||
|
||||
(define 3d-view%
|
||||
(class* plot-view% ()
|
||||
(public
|
||||
plot-polygon
|
||||
plot-line
|
||||
plot-surface
|
||||
plot-3dmesh
|
||||
get-z-min
|
||||
get-z-max
|
||||
get-alt
|
||||
get-az)
|
||||
|
||||
|
||||
(fields-with-accessors
|
||||
(z-min -5)
|
||||
(z-max 5)
|
||||
(alt 30)
|
||||
(az 45)
|
||||
(z-label "Z-Axis"))
|
||||
|
||||
; set-labels : string string string -> nothing
|
||||
; sets the x, y and title lables
|
||||
(define (set-labels x-label y-label title)
|
||||
(pl-set-labels x-label y-label title))
|
||||
|
||||
; define the 3d world
|
||||
(define (world3d x y z xmin xmax ymin ymax zmin zmax alt az)
|
||||
(pl-world-3d x y z xmin xmax ymin ymax zmin zmax alt az))
|
||||
|
||||
; set up the axies box
|
||||
(define (box3d
|
||||
xopts xlabel xticks nxsub
|
||||
yopts ylabel yticks nysub
|
||||
zopts zlabel zticks nzsub)
|
||||
(pl-box3 xopts xlabel xticks nxsub
|
||||
yopts ylabel yticks nysub
|
||||
zopts zlabel zticks nzsub))
|
||||
|
||||
; draw a simple 3d surface plot
|
||||
(define (plot-surface x y z)
|
||||
(pl-plot3d x y z))
|
||||
|
||||
; plot-3dmesh
|
||||
(define (plot-3dmesh x y z lines? colored? contours? sides? levels)
|
||||
(pl-mesh3dc x y z lines? colored? contours? sides? levels))
|
||||
|
||||
(inherit start-plot set-plot-environment finish-plot get-x-min
|
||||
get-x-max get-y-min get-y-max get-renderer get-x-label get-y-label
|
||||
get-title)
|
||||
|
||||
(define (plot)
|
||||
(start-plot)
|
||||
(set-plot-environment -1 1 -1 1 0 -2)
|
||||
(world3d 1 1 1 (get-x-min) (get-x-max) (get-y-min) (get-y-max) z-min z-max alt az)
|
||||
(box3d
|
||||
"bnstu" (get-x-label) 0 0
|
||||
"bnstu" (get-y-label) 0 0
|
||||
"bnstu" z-label 0 0)
|
||||
(set-labels "" "" (get-title))
|
||||
(with-handlers ((exn? (lambda (ex) (finish-plot) (raise ex))))
|
||||
((get-renderer) this))
|
||||
(finish-plot)
|
||||
this)
|
||||
|
||||
; plot a polygon in 3 space
|
||||
(define (plot-polygon x y z draw ifc)
|
||||
(pl-poly3 x y z draw ifc))
|
||||
|
||||
|
||||
; plot a line in 3 space
|
||||
; x y and z are lists of equal length
|
||||
(define (plot-line x y z)
|
||||
(pl-line3 x y z))
|
||||
|
||||
|
||||
(super-instantiate ())
|
||||
(plot)))
|
||||
|
||||
(provide
|
||||
plot-view%
|
||||
2d-view%
|
||||
3d-view%))
|
Before Width: | Height: | Size: 53 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 53 KiB |
Before Width: | Height: | Size: 6.5 KiB |
|
@ -1,113 +0,0 @@
|
|||
#!/bin/sh
|
||||
#| -*- scheme -*-
|
||||
exec gracket "$0" "$@"
|
||||
|#
|
||||
#lang scheme
|
||||
(require plot file/md5 scheme/runtime-path
|
||||
racket/draw)
|
||||
|
||||
(define-runtime-path here "./")
|
||||
|
||||
(define (read-file file)
|
||||
(with-input-from-file file (lambda () (read-bytes (file-size file)))))
|
||||
|
||||
(define-syntax run-test
|
||||
(syntax-rules ()
|
||||
[(_ description (plot args ...) file-name)
|
||||
(let* ([result-file-name
|
||||
(build-path here (string-append file-name "-out.png"))]
|
||||
[expected-file-name
|
||||
(build-path here (string-append file-name ".png"))])
|
||||
(plot args ... #:out-file result-file-name)
|
||||
(printf "testing \"~a\" ... " description)
|
||||
(let* ([bm1 (read-bitmap result-file-name)]
|
||||
[bm2 (read-bitmap expected-file-name)]
|
||||
[w (send bm1 get-width)]
|
||||
[h (send bm1 get-height)]
|
||||
[s1 (make-bytes (* 4 w h))]
|
||||
[s2 (make-bytes (* 4 w h))])
|
||||
(send bm1 get-argb-pixels 0 0 w h s1)
|
||||
(send bm2 get-argb-pixels 0 0 w h s2)
|
||||
(if (and (= (send bm2 get-width) w)
|
||||
(= (send bm2 get-width) h)
|
||||
;; The generated and target images can be a little different,
|
||||
;; but not much --- less than 1/255 difference average difference
|
||||
;; over all RGB components (which is really pretty close)
|
||||
((/ (for/fold ([diff 0]) ([i (in-range (* w h 4))])
|
||||
(+ diff (abs (- (bytes-ref s1 i) (bytes-ref s2 i)))))
|
||||
(* w h 4))
|
||||
. <= .
|
||||
1.0))
|
||||
(begin (display "passed\n") (delete-file result-file-name))
|
||||
(begin
|
||||
(printf "failed! expected results in ~a, plot produced results in ~a\n"
|
||||
expected-file-name
|
||||
result-file-name)))))]))
|
||||
|
||||
(run-test "Line"
|
||||
(plot (line (lambda (x) x) #:color 'red))
|
||||
"red-identity")
|
||||
|
||||
(run-test "Vector Field"
|
||||
(plot (vector-field (gradient (lambda (x y) (* (sin x) (cos y))))
|
||||
#:samples 25)
|
||||
#:title "gradient field of F(x,y) = sin(x) * sin(y)")
|
||||
"vector-field")
|
||||
|
||||
(define (trig x y) (* (sin x) (sin y)))
|
||||
|
||||
(run-test "Shading"
|
||||
(plot (shade trig)
|
||||
#:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5
|
||||
#:title "shdade of F(x,y) = sin(x) * sin(y)")
|
||||
"shade")
|
||||
|
||||
(run-test "Contours"
|
||||
(plot (contour trig)
|
||||
#:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5
|
||||
#:title "contours of F(x,y) = sin(x) * sin(y)")
|
||||
"contours")
|
||||
|
||||
(run-test "Mix of all three"
|
||||
(plot (mix (shade trig)
|
||||
(contour trig)
|
||||
(vector-field (gradient trig) #:samples 25))
|
||||
#:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5
|
||||
#:title "gradient field & shade & contours")
|
||||
"mix")
|
||||
|
||||
(run-test "3d mesg"
|
||||
(plot3d (mesh3d trig)
|
||||
#:x-min -3.5 #:x-max 3.5
|
||||
#:y-min -3.5 #:y-max 3.5
|
||||
#:z-min -1.0 #:z-max 1.5
|
||||
#:bgcolor '(0 0 0) #:fgcolor '(255 0 0))
|
||||
"3d-mesh")
|
||||
|
||||
(require plot/plot-extend)
|
||||
|
||||
; (number -> number) mumbo-jumbo -> 2d-renderer
|
||||
(define-plot-type dashed-line
|
||||
fun 2dview (x-min x-max) ((samples 100) (segments 20) (color 'red) (width 1))
|
||||
(let* ((dash-size (/ (- x-max x-min) segments))
|
||||
(x-lists (build-list (/ segments 2)
|
||||
(lambda (index)
|
||||
(x-values
|
||||
(/ samples segments)
|
||||
(+ x-min (* 2 index dash-size))
|
||||
(+ x-min (* (add1 ( * 2 index)) dash-size)))))))
|
||||
(send* 2dview
|
||||
(set-line-color color)
|
||||
(set-line-width width))
|
||||
(for-each (lambda (dash)
|
||||
(send 2dview plot-line
|
||||
(map (lambda (x) (vector x (fun x))) dash)))
|
||||
x-lists)))
|
||||
|
||||
(run-test "Simple plot-extend"
|
||||
(plot (dashed-line (lambda (x) x) [color 'red]))
|
||||
"dashed-line")
|
||||
|
||||
(run-test "canvas sizing"
|
||||
(plot (line sin) #:height 100 #:width 100)
|
||||
"size")
|
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 31 KiB |
|
@ -39,28 +39,20 @@ all:
|
|||
3m:
|
||||
cd racket; $(MAKE) 3m
|
||||
$(MAKE) @MAKE_GRACKET@-3m
|
||||
$(MAKE) @MAKE_PLOT@-3m
|
||||
|
||||
gracket-3m:
|
||||
cd gracket; $(MAKE) 3m
|
||||
|
||||
plot-3m:
|
||||
cd plot; $(MAKE) 3m
|
||||
|
||||
no-3m:
|
||||
$(NOOP)
|
||||
|
||||
cgc:
|
||||
cd racket; $(MAKE) cgc
|
||||
$(MAKE) @MAKE_GRACKET@-cgc
|
||||
$(MAKE) @MAKE_PLOT@-cgc
|
||||
|
||||
gracket-cgc:
|
||||
cd gracket; $(MAKE) cgc
|
||||
|
||||
plot-cgc:
|
||||
cd plot; $(MAKE) cgc
|
||||
|
||||
no-cgc:
|
||||
$(NOOP)
|
||||
|
||||
|
@ -73,8 +65,8 @@ both:
|
|||
SETUP_ARGS = -X "$(DESTDIR)$(collectsdir)" -N "raco setup" -l- setup $(PLT_SETUP_OPTIONS) $(PLT_ISO) @INSTALL_SETUP_FLAGS@
|
||||
|
||||
# Pass compile and link flags to `make install' for use by any
|
||||
# collection-setup actions (currently in "plot") that compile
|
||||
# and link C code:
|
||||
# collection-setup actions (none currently, was used in "plot") that
|
||||
# compile and link C code:
|
||||
CFLAGS = @CFLAGS@ @COMPFLAGS@ @PREFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
WITH_ENV_VARS = env CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"
|
||||
|
@ -92,7 +84,6 @@ install-common-first:
|
|||
mkdir -p $(ALLDIRINFO)
|
||||
|
||||
install-common-middle:
|
||||
$(MAKE) install-@MAKE_PLOT@
|
||||
$(MAKE) @MAKE_COPYTREE@-run
|
||||
$(MAKE) install-@MAKE_GRACKET@-post-collects
|
||||
$(MAKE) lib-finish
|
||||
|
@ -100,9 +91,6 @@ install-common-middle:
|
|||
install-common-last:
|
||||
$(MAKE) fix-paths
|
||||
|
||||
install-plot:
|
||||
cd plot; $(MAKE) install
|
||||
|
||||
install-no:
|
||||
$(NOOP)
|
||||
|
||||
|
|
19
src/configure
vendored
|
@ -721,7 +721,6 @@ ICP
|
|||
MRLIBINSTALL
|
||||
LIBFINISH
|
||||
MAKE_GRACKET
|
||||
MAKE_PLOT
|
||||
MAKE_COPYTREE
|
||||
MAKE_FINISH
|
||||
WXPRECOMP
|
||||
|
@ -1333,7 +1332,6 @@ Optional Features:
|
|||
--enable-foreign support foreign calls (enabled by default)
|
||||
--enable-places support places (3m only; usually enabled by default)
|
||||
--enable-futures support futures (usually enabled by default)
|
||||
--enable-plot support plot libraries (enabled by default)
|
||||
--enable-float support single-precision floats (enabled by default)
|
||||
--enable-floatinstead use single-precision by default
|
||||
--enable-racket=<path> use <path> as Racket executable to build Racket
|
||||
|
@ -1986,13 +1984,6 @@ if test "${enable_futures+set}" = set; then
|
|||
enableval=$enable_futures;
|
||||
fi
|
||||
|
||||
# Check whether --enable-plot was given.
|
||||
if test "${enable_plot+set}" = set; then
|
||||
enableval=$enable_plot;
|
||||
else
|
||||
enable_plot=yes
|
||||
fi
|
||||
|
||||
# Check whether --enable-float was given.
|
||||
if test "${enable_float+set}" = set; then
|
||||
enableval=$enable_float;
|
||||
|
@ -2312,7 +2303,6 @@ show_explicitly_enabled "${enable_xonx}" "Unix style"
|
|||
show_explicitly_enabled "${enable_shared}" "Shared libraries"
|
||||
|
||||
show_explicitly_disabled "${enable_gracket}" GRacket
|
||||
show_explicitly_disabled "${enable_plot}" Plot
|
||||
|
||||
if test "$LIBTOOLPROG" != "" ; then
|
||||
echo "=== Libtool program: $LIBTOOLPROG"
|
||||
|
@ -8802,14 +8792,6 @@ fi
|
|||
makefiles="$makefiles foreign/Makefile"
|
||||
ac_configure_args="$ac_configure_args$SUB_CONFIGURE_EXTRAS"
|
||||
|
||||
if test -d "${srcdir}/plot" && test "${enable_plot}" = "yes" ; then
|
||||
makefiles="$makefiles
|
||||
plot/Makefile"
|
||||
MAKE_PLOT=plot
|
||||
else
|
||||
MAKE_PLOT=no
|
||||
fi
|
||||
|
||||
if test "${enable_gracket}" = "yes" ; then
|
||||
makefiles="$makefiles
|
||||
gracket/Makefile
|
||||
|
@ -9581,7 +9563,6 @@ ICP!$ICP$ac_delim
|
|||
MRLIBINSTALL!$MRLIBINSTALL$ac_delim
|
||||
LIBFINISH!$LIBFINISH$ac_delim
|
||||
MAKE_GRACKET!$MAKE_GRACKET$ac_delim
|
||||
MAKE_PLOT!$MAKE_PLOT$ac_delim
|
||||
MAKE_COPYTREE!$MAKE_COPYTREE$ac_delim
|
||||
MAKE_FINISH!$MAKE_FINISH$ac_delim
|
||||
WXPRECOMP!$WXPRECOMP$ac_delim
|
||||
|
|
|
@ -84,8 +84,6 @@
|
|||
["libpangocairo-1.0-0.dll" 94625]
|
||||
["libpangowin32-1.0-0.dll" 102210]
|
||||
["libpangoft2-1.0-0.dll" 679322]
|
||||
["libplplot.dll" 245760]
|
||||
["libfit.dll" 73728]
|
||||
,@(if (getenv "PLT_WIN_GTK")
|
||||
'(["libatk-1.0-0.dll" 153763]
|
||||
["libgtk-win32-2.0-0.dll" 4740156]
|
||||
|
@ -111,9 +109,7 @@
|
|||
["libgthread-2.0-0.dll" 126615]
|
||||
["libpangocairo-1.0-0.dll" 185168]
|
||||
["libpangowin32-1.0-0.dll" 192656]
|
||||
["libpangoft2-1.0-0.dll" 1188615]
|
||||
["libplplot.dll" 248832]
|
||||
["libfit.dll" 69120]]]))
|
||||
["libpangoft2-1.0-0.dll" 1188615]]]))
|
||||
|
||||
(define-values [package dest-dir]
|
||||
(command-line #:args [package [dest-dir (current-directory)]]
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
|
||||
srcdir = @srcdir@
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
bindir = @bindir@
|
||||
libdir = @libdir@
|
||||
libpltdir = @libpltdir@
|
||||
collectsdir = @collectsdir@
|
||||
builddir = @builddir@
|
||||
|
||||
ICP=@ICP@
|
||||
|
||||
CC = @CC@
|
||||
|
||||
# See ../Makefile about RUN_RACKET_<X>, which
|
||||
# typically redirects to RUN_THIS_RACKET_<X>:
|
||||
RUN_THIS_RACKET_CGC = ../racket/racket@CGC@
|
||||
|
||||
WITH_ENV = env CC="@PLAIN_CC@" CFLAGS="@CFLAGS@ @COMPFLAGS@ @PREFLAGS@" LDFLAGS="@LDFLAGS@"
|
||||
|
||||
PLPLOT_SRCS = $(srcdir)/plplot/dc_drv.c \
|
||||
$(srcdir)/plplot/plcont.c \
|
||||
$(srcdir)/plplot/plfill.c \
|
||||
$(srcdir)/plplot/plmap.c \
|
||||
$(srcdir)/plplot/plshade.c \
|
||||
$(srcdir)/plplot/plwind.c \
|
||||
$(srcdir)/plplot/pdfutils.c \
|
||||
$(srcdir)/plplot/plcore.c \
|
||||
$(srcdir)/plplot/plgridd.c \
|
||||
$(srcdir)/plplot/plmeta.c \
|
||||
$(srcdir)/plplot/plstripc.c \
|
||||
$(srcdir)/plplot/plargs.c \
|
||||
$(srcdir)/plplot/plctrl.c \
|
||||
$(srcdir)/plplot/plhist.c \
|
||||
$(srcdir)/plplot/plot3d.c \
|
||||
$(srcdir)/plplot/plsym.c \
|
||||
$(srcdir)/plplot/plbox.c \
|
||||
$(srcdir)/plplot/plcvt.c \
|
||||
$(srcdir)/plplot/plimage.c \
|
||||
$(srcdir)/plplot/plpage.c \
|
||||
$(srcdir)/plplot/pltick.c \
|
||||
$(srcdir)/plplot/plbuf.c \
|
||||
$(srcdir)/plplot/pldtik.c \
|
||||
$(srcdir)/plplot/plline.c \
|
||||
$(srcdir)/plplot/plsdef.c \
|
||||
$(srcdir)/plplot/plvpor.c
|
||||
|
||||
FIT_SRCS = $(srcdir)/fit/fit.c $(srcdir)/fit/matrix.c
|
||||
|
||||
XCOLLECTS = -X ../racket/gc2/xform-collects
|
||||
|
||||
plot-lib: libplplot@SO_SUFFIX@ libfit@SO_SUFFIX@
|
||||
|
||||
3m:
|
||||
$(MAKE) plot-lib
|
||||
cgc:
|
||||
$(MAKE) plot-lib
|
||||
|
||||
libplplot@SO_SUFFIX@:
|
||||
$(WITH_ENV) @RUN_RACKET_CGC@ -c $(srcdir)/build.rkt "libplplot" $(PLPLOT_SRCS)
|
||||
|
||||
libfit@SO_SUFFIX@:
|
||||
$(WITH_ENV) @RUN_RACKET_CGC@ -c $(srcdir)/build.rkt "libfit" $(FIT_SRCS)
|
||||
|
||||
install:
|
||||
cd ..; $(ICP) plot/libplplot@SO_SUFFIX@ "$(DESTDIR)$(libpltdir)/libplplot@SO_SUFFIX@"
|
||||
cd ..; $(ICP) plot/libfit@SO_SUFFIX@ "$(DESTDIR)$(libpltdir)/libfit@SO_SUFFIX@"
|
|
@ -1,2 +0,0 @@
|
|||
..\..\racket build.rkt libplplot plplot/dc_drv.c plplot/plcont.c plplot/plfill.c plplot/plmap.c plplot/plshade.c plplot/plwind.c plplot/pdfutils.c plplot/plcore.c plplot/plgridd.c plplot/plmeta.c plplot/plstripc.c plplot/plargs.c plplot/plctrl.c plplot/plhist.c plplot/plot3d.c plplot/plsym.c plplot/plbox.c plplot/plcvt.c plplot/plimage.c plplot/plpage.c plplot/pltick.c plplot/plbuf.c plplot/pldtik.c plplot/plline.c plplot/plsdef.c plplot/plvpor.c
|
||||
..\..\racket build.rkt libfit fit/fit.c fit/matrix.c
|
|
@ -1,32 +0,0 @@
|
|||
(module build racket/base
|
||||
(require racket/path
|
||||
racket/file
|
||||
dynext/file
|
||||
dynext/link
|
||||
dynext/compile)
|
||||
|
||||
(define-values (libname c-files)
|
||||
(let ([l (vector->list (current-command-line-arguments))])
|
||||
(values (car l)
|
||||
(cdr l))))
|
||||
|
||||
(define sys-subpath (system-library-subpath #f))
|
||||
|
||||
(define so-name (append-extension-suffix libname))
|
||||
(parameterize (;; we compile a simple .so, not an extension
|
||||
[current-standard-link-libraries '()])
|
||||
(when (or (not (file-exists? so-name))
|
||||
(let ([so-time (file-or-directory-modify-seconds so-name)])
|
||||
(for/or ([f c-files])
|
||||
((file-or-directory-modify-seconds f) . > . so-time))))
|
||||
(let ([o-files
|
||||
(for/list ([c-file c-files])
|
||||
(let ([o-file (append-object-suffix (path-replace-suffix (file-name-from-path c-file) #""))])
|
||||
;; first #f means not quiet (here and in link-extension)
|
||||
(compile-extension #f c-file o-file null)
|
||||
o-file))])
|
||||
(let* ([flags (if (string=? "i386-cygwin" (path->string sys-subpath))
|
||||
;; DLL needs every dependence explicit:
|
||||
'("-lc" "-lm" "-lcygwin" "-lkernel32")
|
||||
null)])
|
||||
(link-extension #f (append o-files flags) so-name))))))
|
|
@ -1,6 +0,0 @@
|
|||
|
||||
#if (defined(__WIN32__) || defined(WIN32) || defined(_WIN32))
|
||||
# define MZ_DLLEXPORT __declspec(dllexport)
|
||||
#else
|
||||
# define MZ_DLLEXPORT
|
||||
#endif
|
|
@ -1,752 +0,0 @@
|
|||
/* NOTICE: Change of Copyright Status
|
||||
*
|
||||
* The author of this module, Carsten Grammes, has expressed in
|
||||
* personal email that he has no more interest in this code, and
|
||||
* doesn't claim any copyright. He has agreed to put this module
|
||||
* into the public domain.
|
||||
*
|
||||
* Lars Hecking 15-02-1999
|
||||
*/
|
||||
|
||||
/*
|
||||
* Nonlinear least squares fit according to the
|
||||
* Marquardt-Levenberg-algorithm
|
||||
*
|
||||
* added as Patch to Gnuplot (v3.2 and higher)
|
||||
* by Carsten Grammes
|
||||
* Experimental Physics, University of Saarbruecken, Germany
|
||||
*
|
||||
* Internet address: cagr@rz.uni-sb.de
|
||||
*
|
||||
* Copyright of this module: 1993, 1998 Carsten Grammes
|
||||
*
|
||||
* Permission to use, copy, and distribute this software and its
|
||||
* documentation for any purpose with or without fee is hereby granted,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation.
|
||||
*
|
||||
* This software is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* 930726: Recoding of the Unix-like raw console I/O routines by:
|
||||
* Michele Marziani (marziani@ferrara.infn.it)
|
||||
* drd: start unitialised variables at 1 rather than NEARLY_ZERO
|
||||
* (fit is more likely to converge if started from 1 than 1e-30 ?)
|
||||
*
|
||||
* HBB (Broeker@physik.rwth-aachen.de) : fit didn't calculate the errors
|
||||
* in the 'physically correct' (:-) way, if a third data column containing
|
||||
* the errors (or 'uncertainties') of the input data was given. I think
|
||||
* I've fixed that, but I'm not sure I really understood the M-L-algo well
|
||||
* enough to get it right. I deduced my change from the final steps of the
|
||||
* equivalent algorithm for the linear case, which is much easier to
|
||||
* understand. (I also made some minor, mostly cosmetic changes)
|
||||
*
|
||||
* HBB (again): added error checking for negative covar[i][i] values and
|
||||
* for too many parameters being specified.
|
||||
*
|
||||
* drd: allow 3d fitting. Data value is now called fit_z internally,
|
||||
* ie a 2d fit is z vs x, and a 3d fit is z vs x and y.
|
||||
*
|
||||
* Lars Hecking : review update command, for VMS in particular, where
|
||||
* it is not necessary to rename the old file.
|
||||
*
|
||||
* HBB, 971023: lifted fixed limit on number of datapoints, and number
|
||||
* of parameters.
|
||||
*/
|
||||
|
||||
|
||||
#define FIT_MAIN
|
||||
|
||||
#define NULL 0
|
||||
|
||||
//#include <scheme.h>
|
||||
|
||||
|
||||
|
||||
#include "matrix.h"
|
||||
#include "fit.h"
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* #define STANDARD stderr */
|
||||
|
||||
|
||||
enum marq_res {
|
||||
OK, ERROR, BETTER, WORSE
|
||||
};
|
||||
typedef enum marq_res marq_res_t;
|
||||
|
||||
#ifdef INFINITY
|
||||
# undef INFINITY
|
||||
#endif
|
||||
|
||||
#define INFINITY 1e30
|
||||
#define NEARLY_ZERO 1e-30
|
||||
|
||||
|
||||
/* Relative change for derivatives */
|
||||
#define DELTA 0.001
|
||||
|
||||
#define MAX_DATA 2048
|
||||
#define MAX_PARAMS 32
|
||||
#define MAX_LAMBDA 1e20
|
||||
#define MIN_LAMBDA 1e-20
|
||||
#define LAMBDA_UP_FACTOR 10
|
||||
#define LAMBDA_DOWN_FACTOR 10
|
||||
|
||||
#define TBOOLEAN int
|
||||
|
||||
# define PLUSMINUS "+/-"
|
||||
|
||||
|
||||
|
||||
/* HBB 971023: new, allow for dynamic adjustment of these: */
|
||||
static UNUSED int max_data;
|
||||
static UNUSED int max_params;
|
||||
|
||||
static double epsilon = 1e-5; /* convergence limit */
|
||||
static int maxiter = 0; /* HBB 970304: maxiter patch */
|
||||
|
||||
static UNUSED char *FIXED = "# FIXED";
|
||||
static UNUSED char *GNUFITLOG = "FIT_LOG";
|
||||
static UNUSED char *FITLIMIT = "FIT_LIMIT";
|
||||
static UNUSED char *FITSTARTLAMBDA = "FIT_START_LAMBDA";
|
||||
static UNUSED char *FITLAMBDAFACTOR = "FIT_LAMBDA_FACTOR";
|
||||
static UNUSED char *FITMAXITER = "FIT_MAXITER"; /* HBB 970304: maxiter patch */
|
||||
static UNUSED char *FITSCRIPT = "FIT_SCRIPT";
|
||||
static UNUSED char *DEFAULT_CMD = "replot"; /* if no fitscript spec. */
|
||||
|
||||
|
||||
static int num_data, num_params;
|
||||
static UNUSED int columns;
|
||||
static double *fit_x;
|
||||
static double *fit_y;
|
||||
static double *fit_z ;
|
||||
static double *err_data;
|
||||
static double *a;
|
||||
|
||||
|
||||
/* static fixstr * par_name; */
|
||||
|
||||
static double startup_lambda = 0;
|
||||
static double lambda_down_factor = LAMBDA_DOWN_FACTOR;
|
||||
static double lambda_up_factor = LAMBDA_UP_FACTOR;
|
||||
|
||||
|
||||
static void * current_fun;
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
internal vars to store results of fit
|
||||
*****************************************************************/
|
||||
|
||||
double rms = 0;
|
||||
double varience = 0;
|
||||
double *asym_error;
|
||||
double *asym_error_percent;
|
||||
|
||||
MZ_DLLEXPORT
|
||||
double get_rms()
|
||||
{return rms;}
|
||||
|
||||
MZ_DLLEXPORT
|
||||
double get_varience()
|
||||
{return varience;}
|
||||
|
||||
MZ_DLLEXPORT
|
||||
double * get_asym_error()
|
||||
{return asym_error;}
|
||||
|
||||
MZ_DLLEXPORT
|
||||
double * get_asym_error_percent()
|
||||
{return asym_error_percent;}
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
internal Prototypes
|
||||
*****************************************************************/
|
||||
|
||||
/*static void printmatrix __PROTO((double **C, int m, int n)); */
|
||||
static UNUSED void print_matrix_and_vectors (double **C, double *d, double *r, int m, int n);
|
||||
static marq_res_t marquardt (double a[], double **alpha, double *chisq,
|
||||
double *lambda);
|
||||
static TBOOLEAN analyze (double a[], double **alpha, double beta[],
|
||||
double *chisq);
|
||||
static void calculate (double *zfunc, double **dzda, double a[]);
|
||||
static void call_scheme (double *par, double *data);
|
||||
|
||||
static TBOOLEAN regress (double a[]);
|
||||
//static void show_fit (int i, double chisq, double last_chisq, double *a,
|
||||
// double lambda, FILE * device);
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
New utility routine: print a matrix (for debugging the alg.)
|
||||
*****************************************************************/
|
||||
static UNUSED void printmatrix(C, m, n)
|
||||
double **C;
|
||||
int m, n;
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < m; i++) {
|
||||
for (j = 0; j < n - 1; j++);
|
||||
/* Dblf2("%.8g |", C[i][j]); */
|
||||
/* Dblf2("%.8g\n", C[i][j]); */
|
||||
}
|
||||
/* Dblf("\n"); */
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Yet another debugging aid: print matrix, with diff. and residue vector
|
||||
**************************************************************************/
|
||||
static UNUSED void print_matrix_and_vectors(C, d, r, m, n)
|
||||
double **C;
|
||||
double *d, *r;
|
||||
int m, n;
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < m; i++) {
|
||||
for (j = 0; j < n; j++);
|
||||
/* Dblf2("%8g ", C[i][j]); */
|
||||
/* Dblf3("| %8g | %8g\n", d[i], r[i]); */
|
||||
}
|
||||
/* Dblf("\n"); */
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
Marquardt's nonlinear least squares fit
|
||||
*****************************************************************/
|
||||
static marq_res_t marquardt(a, C, chisq, lambda)
|
||||
double a[];
|
||||
double **C;
|
||||
double *chisq;
|
||||
double *lambda;
|
||||
{
|
||||
int i, j;
|
||||
static double *da = 0, /* delta-step of the parameter */
|
||||
*temp_a = 0, /* temptative new params set */
|
||||
*d = 0, *tmp_d = 0, **tmp_C = 0, *residues = 0;
|
||||
double tmp_chisq;
|
||||
|
||||
/* Initialization when lambda == -1 */
|
||||
|
||||
if (*lambda == -1) { /* Get first chi-square check */
|
||||
TBOOLEAN analyze_ret;
|
||||
|
||||
temp_a = vec(num_params);
|
||||
d = vec(num_data + num_params);
|
||||
tmp_d = vec(num_data + num_params);
|
||||
da = vec(num_params);
|
||||
residues = vec(num_data + num_params);
|
||||
tmp_C = matr(num_data + num_params, num_params);
|
||||
|
||||
analyze_ret = analyze(a, C, d, chisq);
|
||||
|
||||
/* Calculate a useful startup value for lambda, as given by Schwarz */
|
||||
/* FIXME: this is doesn't turn out to be much better, really... */
|
||||
if (startup_lambda != 0)
|
||||
*lambda = startup_lambda;
|
||||
else {
|
||||
*lambda = 0;
|
||||
for (i = 0; i < num_data; i++)
|
||||
for (j = 0; j < num_params; j++)
|
||||
*lambda += C[i][j] * C[i][j];
|
||||
*lambda = sqrt(*lambda / num_data / num_params);
|
||||
}
|
||||
|
||||
/* Fill in the lower square part of C (the diagonal is filled in on
|
||||
each iteration, see below) */
|
||||
for (i = 0; i < num_params; i++)
|
||||
for (j = 0; j < i; j++)
|
||||
C[num_data + i][j] = 0, C[num_data + j][i] = 0;
|
||||
/* printmatrix(C, num_data+num_params, num_params); */
|
||||
return analyze_ret ? OK : ERROR;
|
||||
}
|
||||
/* once converged, free dynamic allocated vars */
|
||||
|
||||
if (*lambda == -2) {
|
||||
return OK;
|
||||
}
|
||||
/* Givens calculates in-place, so make working copies of C and d */
|
||||
|
||||
for (j = 0; j < num_data + num_params; j++)
|
||||
memcpy(tmp_C[j], C[j], num_params * sizeof(double));
|
||||
memcpy(tmp_d, d, num_data * sizeof(double));
|
||||
|
||||
/* fill in additional parts of tmp_C, tmp_d */
|
||||
|
||||
for (i = 0; i < num_params; i++) {
|
||||
/* fill in low diag. of tmp_C ... */
|
||||
tmp_C[num_data + i][i] = *lambda;
|
||||
/* ... and low part of tmp_d */
|
||||
tmp_d[num_data + i] = 0;
|
||||
}
|
||||
/* printmatrix(tmp_C, num_data+num_params, num_params); */
|
||||
|
||||
/* FIXME: residues[] isn't used at all. Why? Should it be used? */
|
||||
|
||||
Givens(tmp_C, tmp_d, da, residues, num_params + num_data, num_params, 1);
|
||||
/*print_matrix_and_vectors (tmp_C, tmp_d, residues,
|
||||
num_params+num_data, num_params); */
|
||||
|
||||
/* check if trial did ameliorate sum of squares */
|
||||
|
||||
for (j = 0; j < num_params; j++)
|
||||
temp_a[j] = a[j] + da[j];
|
||||
|
||||
if (!analyze(temp_a, tmp_C, tmp_d, &tmp_chisq)) {
|
||||
/* FIXME: will never be reached: always returns TRUE */
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (tmp_chisq < *chisq) { /* Success, accept new solution */
|
||||
if (*lambda > MIN_LAMBDA) {
|
||||
/* (void) putc('/', stderr); */
|
||||
*lambda /= lambda_down_factor;
|
||||
}
|
||||
*chisq = tmp_chisq;
|
||||
for (j = 0; j < num_data; j++) {
|
||||
memcpy(C[j], tmp_C[j], num_params * sizeof(double));
|
||||
d[j] = tmp_d[j];
|
||||
}
|
||||
for (j = 0; j < num_params; j++)
|
||||
a[j] = temp_a[j];
|
||||
return BETTER;
|
||||
} else { /* failure, increase lambda and return */
|
||||
/* (void) putc('*', stderr); */
|
||||
*lambda *= lambda_up_factor;
|
||||
return WORSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* FIXME: in the new code, this function doesn't really do enough to be
|
||||
* useful. Maybe it ought to be deleted, i.e. integrated with
|
||||
* calculate() ?
|
||||
*/
|
||||
/*****************************************************************
|
||||
compute chi-square and numeric derivations
|
||||
*****************************************************************/
|
||||
static TBOOLEAN analyze(a, C, d, chisq)
|
||||
double a[];
|
||||
double **C;
|
||||
double d[];
|
||||
double *chisq;
|
||||
{
|
||||
/*
|
||||
* used by marquardt to evaluate the linearized fitting matrix C
|
||||
* and vector d, fills in only the top part of C and d
|
||||
* I don't use a temporary array zfunc[] any more. Just use
|
||||
* d[] instead.
|
||||
*/
|
||||
int i, j;
|
||||
|
||||
*chisq = 0;
|
||||
calculate(d, C, a);
|
||||
|
||||
for (i = 0; i < num_data; i++) {
|
||||
/* note: order reversed, as used by Schwarz */
|
||||
d[i] = (d[i] - fit_z[i]) / err_data[i];
|
||||
*chisq += d[i] * d[i];
|
||||
for (j = 0; j < num_params; j++)
|
||||
C[i][j] /= err_data[i];
|
||||
}
|
||||
/* FIXME: why return a value that is always TRUE ? */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* To use the more exact, but slower two-side formula, activate the
|
||||
following line: */
|
||||
|
||||
#define TWO_SIDE_DIFFERENTIATION
|
||||
|
||||
/*****************************************************************
|
||||
compute function values and partial derivatives of chi-square
|
||||
*****************************************************************/
|
||||
static void calculate(zfunc, dzda, a)
|
||||
double *zfunc;
|
||||
double **dzda;
|
||||
double a[];
|
||||
{
|
||||
int k, p;
|
||||
double tmp_a;
|
||||
double *tmp_high, *tmp_pars;
|
||||
#ifdef TWO_SIDE_DIFFERENTIATION
|
||||
double *tmp_low;
|
||||
#endif
|
||||
|
||||
tmp_high = vec(num_data); /* numeric derivations */
|
||||
#ifdef TWO_SIDE_DIFFERENTIATION
|
||||
tmp_low = vec(num_data);
|
||||
#endif
|
||||
tmp_pars = vec(num_params);
|
||||
|
||||
/* first function values */
|
||||
|
||||
call_scheme(a, zfunc);
|
||||
|
||||
/* then derivatives */
|
||||
|
||||
for (p = 0; p < num_params; p++)
|
||||
tmp_pars[p] = a[p];
|
||||
for (p = 0; p < num_params; p++) {
|
||||
tmp_a = fabs(a[p]) < NEARLY_ZERO ? NEARLY_ZERO : a[p];
|
||||
tmp_pars[p] = tmp_a * (1 + DELTA);
|
||||
call_scheme(tmp_pars, tmp_high);
|
||||
#ifdef TWO_SIDE_DIFFERENTIATION
|
||||
tmp_pars[p] = tmp_a * (1 - DELTA);
|
||||
call_scheme(tmp_pars, tmp_low);
|
||||
#endif
|
||||
for (k = 0; k < num_data; k++)
|
||||
#ifdef TWO_SIDE_DIFFERENTIATION
|
||||
dzda[k][p] = (tmp_high[k] - tmp_low[k]) / (2 * tmp_a * DELTA);
|
||||
#else
|
||||
dzda[k][p] = (tmp_high[k] - zfunc[k]) / (tmp_a * DELTA);
|
||||
#endif
|
||||
tmp_pars[p] = a[p];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
evaluate the scheme function
|
||||
*****************************************************************/
|
||||
static void call_scheme(par, data)
|
||||
double *par;
|
||||
double *data;
|
||||
{
|
||||
int rators = 2 + num_params;
|
||||
double * rands =
|
||||
(double *) malloc(rators * sizeof(double));
|
||||
|
||||
int i;
|
||||
|
||||
/* set up the constant params */
|
||||
for(i = 0 ; i< num_params; i++) {
|
||||
rands[i+2] = par[i];
|
||||
}
|
||||
|
||||
/* now calculate the function at the existing points */
|
||||
for (i = 0; i < num_data; i++) {
|
||||
rands[0] = fit_x[i];
|
||||
rands[1] = fit_y[i];
|
||||
|
||||
data[i] = ((double (*) (int, double *) )current_fun) // ouch!
|
||||
(rators, rands);
|
||||
}
|
||||
|
||||
free(rands);
|
||||
|
||||
}
|
||||
|
||||
/* /\***************************************************************** */
|
||||
/* evaluate the scheme function */
|
||||
/* *****************************************************************\/ */
|
||||
/* static void call_scheme(par, data) */
|
||||
/* double *par; */
|
||||
/* double *data; */
|
||||
/* { */
|
||||
/* int rators = 2 + num_params; */
|
||||
/* Scheme_Object ** rands = */
|
||||
/* scheme_malloc(rators * sizeof(Scheme_Object)); */
|
||||
|
||||
/* int i; */
|
||||
|
||||
/* /\* set up the constant params *\/ */
|
||||
/* for(i = 0 ; i< num_params; i++) { */
|
||||
/* rands[i+2] = scheme_make_double(par[i]); */
|
||||
/* } */
|
||||
|
||||
/* /\* now calculate the function at the existing points *\/ */
|
||||
/* for (i = 0; i < num_data; i++) { */
|
||||
/* rands[0] = scheme_make_double(fit_x[i]); */
|
||||
/* rands[1] = scheme_make_double(fit_y[i]); */
|
||||
|
||||
/* data[i] = scheme_real_to_double(scheme_apply(current_fun, rators, rands)); */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
/*****************************************************************
|
||||
Frame routine for the marquardt-fit
|
||||
*****************************************************************/
|
||||
static TBOOLEAN regress(a)
|
||||
double a[];
|
||||
{
|
||||
double **covar, *dpar, **C, chisq, last_chisq, lambda;
|
||||
int iter, i, j;
|
||||
marq_res_t res;
|
||||
|
||||
chisq = last_chisq = INFINITY;
|
||||
C = matr(num_data + num_params, num_params);
|
||||
lambda = -1; /* use sign as flag */
|
||||
iter = 0; /* iteration counter */
|
||||
|
||||
/* Initialize internal variables and 1st chi-square check */
|
||||
|
||||
if ((res = marquardt(a, C, &chisq, &lambda)) == ERROR)
|
||||
return 0; /* an error occurded */
|
||||
|
||||
res = BETTER;
|
||||
|
||||
/* show_fit(iter, chisq, chisq, a, lambda, STANDARD); */
|
||||
|
||||
/* MAIN FIT LOOP: do the regression iteration */
|
||||
|
||||
do {
|
||||
if (res == BETTER) {
|
||||
iter++;
|
||||
last_chisq = chisq;
|
||||
}
|
||||
if ((res = marquardt(a, C, &chisq, &lambda)) == BETTER)
|
||||
{};
|
||||
/* show_fit(iter, chisq, last_chisq, a, lambda, STANDARD); */
|
||||
} while ((res != ERROR)
|
||||
&& (lambda < MAX_LAMBDA)
|
||||
&& ((maxiter == 0) || (iter <= maxiter))
|
||||
&& (res == WORSE
|
||||
|| ((chisq > NEARLY_ZERO)
|
||||
? ((last_chisq - chisq) / chisq)
|
||||
: (last_chisq - chisq)) > epsilon
|
||||
)
|
||||
);
|
||||
|
||||
/* fit done */
|
||||
|
||||
/* save all the info that was otherwise printed out */
|
||||
|
||||
rms = sqrt(chisq / (num_data - num_params));
|
||||
varience = chisq / (num_data - num_params);
|
||||
asym_error = malloc (num_params * sizeof (double));
|
||||
asym_error_percent = malloc (num_params * sizeof (double)) ;
|
||||
|
||||
/* don't know what the following code does... */
|
||||
|
||||
/* compute covar[][] directly from C */
|
||||
Givens(C, 0, 0, 0, num_data, num_params, 0);
|
||||
covar = C + num_data;
|
||||
Invert_RtR(C, covar, num_params);
|
||||
|
||||
dpar = vec(num_params);
|
||||
for (i = 0; i < num_params; i++) {
|
||||
/* FIXME: can this still happen ? */
|
||||
if (covar[i][i] <= 0.0) /* HBB: prevent floating point exception later on */
|
||||
return 0; /* Eex("Calculation error: non-positive diagonal element in covar. matrix"); */
|
||||
dpar[i] = sqrt(covar[i][i]);
|
||||
}
|
||||
|
||||
/* transform covariances into correlations */
|
||||
for (i = 0; i < num_params; i++) {
|
||||
/* only lower triangle needs to be handled */
|
||||
for (j = 0; j <= i; j++)
|
||||
covar[i][j] /= dpar[i] * dpar[j];
|
||||
}
|
||||
|
||||
/* scale parameter errors based on chisq */
|
||||
chisq = sqrt(chisq / (num_data - num_params));
|
||||
for (i = 0; i < num_params; i++)
|
||||
dpar[i] *= chisq;
|
||||
|
||||
for(i = 0; i< num_params; i++)
|
||||
{
|
||||
double temp =
|
||||
(fabs(a[i]) < NEARLY_ZERO) ? 0.0 : fabs(100.0 * dpar[i] / a[i]);
|
||||
asym_error[i] = dpar[i];
|
||||
asym_error_percent[i] = temp;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
|
||||
/******** CRAP LEFT OVER FROM GNUPLOT ***********/
|
||||
|
||||
/* HBB 970304: the maxiter patch: */
|
||||
/*
|
||||
if ((maxiter > 0) && (iter > maxiter)) {
|
||||
Dblf2("\nMaximum iteration count (%d) reached. Fit stopped.\n", maxiter);
|
||||
} else {
|
||||
Dblf2("\nAfter %d iterations the fit converged.\n", iter);
|
||||
}
|
||||
|
||||
Dblf2("final sum of squares of residuals : %g\n", chisq);
|
||||
if (chisq > NEARLY_ZERO) {
|
||||
Dblf2("rel. change during last iteration : %g\n\n", (chisq - last_chisq) / chisq);
|
||||
} else {
|
||||
Dblf2("abs. change during last iteration : %g\n\n", (chisq - last_chisq));
|
||||
}
|
||||
|
||||
if (res == ERROR)
|
||||
// Eex("FIT: error occurred during fit");
|
||||
*/
|
||||
/* compute errors in the parameters */
|
||||
|
||||
/* if (num_data == num_params) { */
|
||||
/* int i; */
|
||||
|
||||
/* Dblf("\nExactly as many data points as there are parameters.\n"); */
|
||||
/* Dblf("In this degenerate case, all errors are zero by definition.\n\n"); */
|
||||
/* Dblf("Final set of parameters \n"); */
|
||||
/* Dblf("======================= \n\n"); */
|
||||
/* for (i = 0; i < num_params; i++) */
|
||||
/* Dblf3("%-15.15s = %-15g\n", par_name[i], a[i]); */
|
||||
/* } else if (chisq < NEARLY_ZERO) { */
|
||||
/* int i; */
|
||||
|
||||
/* Dblf("\nHmmmm.... Sum of squared residuals is zero. Can't compute errors.\n\n"); */
|
||||
/* Dblf("Final set of parameters \n"); */
|
||||
/* Dblf("======================= \n\n"); */
|
||||
/* for (i = 0; i < num_params; i++) */
|
||||
/* Dblf3("%-15.15s = %-15g\n", par_name[i], a[i]); */
|
||||
/* } else { */
|
||||
/* Dblf2("degrees of freedom (ndf) : %d\n", num_data - num_params); */
|
||||
/* Dblf2("rms of residuals (stdfit) = sqrt(WSSR/ndf) : %g\n", sqrt(chisq / (num_data - num_params))); */
|
||||
/* Dblf2("variance of residuals (reduced chisquare) = WSSR/ndf : %g\n\n", chisq / (num_data - num_params)); */
|
||||
|
||||
/* /\* get covariance-, Korrelations- and Kurvature-Matrix *\/ */
|
||||
/* /\* and errors in the parameters *\/ */
|
||||
|
||||
/* /\* compute covar[][] directly from C *\/ */
|
||||
/* Givens(C, 0, 0, 0, num_data, num_params, 0); */
|
||||
/* /\*printmatrix(C, num_params, num_params); *\/ */
|
||||
|
||||
/* /\* Use lower square of C for covar *\/ */
|
||||
/* covar = C + num_data; */
|
||||
/* Invert_RtR(C, covar, num_params); */
|
||||
/* /\*printmatrix(covar, num_params, num_params); *\/ */
|
||||
|
||||
/* /\* calculate unscaled parameter errors in dpar[]: *\/ */
|
||||
/* dpar = vec(num_params); */
|
||||
/* for (i = 0; i < num_params; i++) { */
|
||||
/* /\* FIXME: can this still happen ? *\/ */
|
||||
/* if (covar[i][i] <= 0.0) /\* HBB: prevent floating point exception later on *\/ */
|
||||
/* Eex("Calculation error: non-positive diagonal element in covar. matrix"); */
|
||||
/* dpar[i] = sqrt(covar[i][i]); */
|
||||
/* } */
|
||||
|
||||
/* /\* transform covariances into correlations *\/ */
|
||||
/* for (i = 0; i < num_params; i++) { */
|
||||
/* /\* only lower triangle needs to be handled *\/ */
|
||||
/* for (j = 0; j <= i; j++) */
|
||||
/* covar[i][j] /= dpar[i] * dpar[j]; */
|
||||
/* } */
|
||||
|
||||
/* /\* scale parameter errors based on chisq *\/ */
|
||||
/* chisq = sqrt(chisq / (num_data - num_params)); */
|
||||
/* for (i = 0; i < num_params; i++) */
|
||||
/* dpar[i] *= chisq; */
|
||||
|
||||
/* Dblf("Final set of parameters Asymptotic Standard Error\n"); */
|
||||
/* Dblf("======================= ==========================\n\n"); */
|
||||
|
||||
/* for (i = 0; i < num_params; i++) { */
|
||||
/* double temp = */
|
||||
/* (fabs(a[i]) < NEARLY_ZERO) ? 0.0 : fabs(100.0 * dpar[i] / a[i]); */
|
||||
/* Dblf6("%-15.15s = %-15g %-3.3s %-12.4g (%.4g%%)\n", */
|
||||
/* par_name[i], a[i], PLUSMINUS, dpar[i], temp); */
|
||||
/* } */
|
||||
|
||||
/* Dblf("\n\ncorrelation matrix of the fit parameters:\n\n"); */
|
||||
/* Dblf(" "); */
|
||||
|
||||
/* for (j = 0; j < num_params; j++) */
|
||||
/* Dblf2("%-6.6s ", par_name[j]); */
|
||||
|
||||
/* Dblf("\n"); */
|
||||
/* for (i = 0; i < num_params; i++) { */
|
||||
/* Dblf2("%-15.15s", par_name[i]); */
|
||||
/* for (j = 0; j <= i; j++) { */
|
||||
/* /\* Only print lower triangle of symmetric matrix *\/ */
|
||||
/* Dblf2("%6.3f ", covar[i][j]); */
|
||||
/* } */
|
||||
/* Dblf("\n"); */
|
||||
/* } */
|
||||
|
||||
/* free(dpar); */
|
||||
/* } */
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
display actual state of the fit
|
||||
*****************************************************************/
|
||||
/* static void show_fit(i, chisq, last_chisq, a, lambda, device) */
|
||||
/* int i; */
|
||||
/* double chisq; */
|
||||
/* double last_chisq; */
|
||||
/* double *a; */
|
||||
/* double lambda; */
|
||||
/* FILE *device; */
|
||||
//{
|
||||
/*
|
||||
int k;
|
||||
|
||||
fprintf(device, "\n\n\
|
||||
Iteration %d\n\
|
||||
WSSR : %-15g delta(WSSR)/WSSR : %g\n\
|
||||
delta(WSSR) : %-15g limit for stopping : %g\n\
|
||||
lambda : %g\n\n%s parameter values\n\n",
|
||||
i, chisq, chisq > NEARLY_ZERO ? (chisq - last_chisq) / chisq : 0.0,
|
||||
chisq - last_chisq, epsilon, lambda,
|
||||
(i > 0 ? "resultant" : "initial set of free"));
|
||||
for (k = 0; k < num_params; k++)
|
||||
fprintf(device, "%-15.15s = %g\n", par_name[k], a[k]);
|
||||
*/
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
Interface to scheme
|
||||
*****************************************************************/
|
||||
MZ_DLLEXPORT
|
||||
double * do_fit(void * function,
|
||||
int n_values,
|
||||
double * x_values,
|
||||
double * y_values,
|
||||
double * z_values,
|
||||
double * errors,
|
||||
int n_parameters,
|
||||
double * parameters) {
|
||||
|
||||
/* reset lambda and other parameters if desired */
|
||||
int i;
|
||||
current_fun = function;
|
||||
|
||||
num_data = n_values;
|
||||
fit_x = x_values;
|
||||
fit_y = y_values;
|
||||
fit_z = z_values; /* value is stored in z */
|
||||
err_data = errors;
|
||||
|
||||
a = parameters;
|
||||
num_params = n_parameters;
|
||||
|
||||
/* redim_vec(&a, num_params); */
|
||||
/* par_name = (fixstr *) gp_realloc(par_name, (num_params + 1) * sizeof(fixstr), "fit param"); */
|
||||
|
||||
/* avoid parameters being equal to zero */
|
||||
for (i = 0; i < num_params; i++) {
|
||||
if (a[i] == 0) {
|
||||
a[i] = NEARLY_ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
if(regress(a)) {
|
||||
gc_cleanup();
|
||||
return a;
|
||||
}
|
||||
else { /* something went wrong */
|
||||
gc_cleanup();
|
||||
return NULL;
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/* $Id: fit.h,v 1.5 2005/03/15 23:19:40 eli Exp $ */
|
||||
|
||||
/* GNUPLOT - fit.h */
|
||||
|
||||
/* NOTICE: Change of Copyright Status
|
||||
*
|
||||
* The author of this module, Carsten Grammes, has expressed in
|
||||
* personal email that he has no more interest in this code, and
|
||||
* doesn't claim any copyright. He has agreed to put this module
|
||||
* into the public domain.
|
||||
*
|
||||
* Lars Hecking 15-02-1999
|
||||
*/
|
||||
|
||||
/*
|
||||
* Header file: public functions in fit.c
|
||||
*
|
||||
*
|
||||
* Copyright of this module: Carsten Grammes, 1993
|
||||
* Experimental Physics, University of Saarbruecken, Germany
|
||||
*
|
||||
* Internet address: cagr@rz.uni-sb.de
|
||||
*
|
||||
* Permission to use, copy, and distribute this software and its
|
||||
* documentation for any purpose with or without fee is hereby granted,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation.
|
||||
*
|
||||
* This software is provided "as is" without express or implied warranty.
|
||||
*/
|
||||
|
||||
#include "../dllexport.h"
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define UNUSED __attribute__((unused))
|
||||
#else
|
||||
# define UNUSED
|
||||
#endif
|
||||
|
||||
MZ_DLLEXPORT
|
||||
double * do_fit(void * function,
|
||||
int n_values,
|
||||
double * x_values,
|
||||
double * y_values,
|
||||
double * z_values,
|
||||
double * errors,
|
||||
int n_parameters,
|
||||
double * parameters);
|
||||
|
||||
|
||||
MZ_DLLEXPORT
|
||||
double get_rms();
|
||||
|
||||
MZ_DLLEXPORT
|
||||
double get_varience();
|
||||
|
||||
MZ_DLLEXPORT
|
||||
double * get_asym_error();
|
||||
|
||||
MZ_DLLEXPORT
|
||||
double * get_asym_error_percent();
|
|
@ -1,315 +0,0 @@
|
|||
/* NOTICE: Change of Copyright Status
|
||||
*
|
||||
* The author of this module, Carsten Grammes, has expressed in
|
||||
* personal email that he has no more interest in this code, and
|
||||
* doesn't claim any copyright. He has agreed to put this module
|
||||
* into the public domain.
|
||||
*
|
||||
* Lars Hecking 15-02-1999
|
||||
*/
|
||||
|
||||
/*
|
||||
* Matrix algebra, part of
|
||||
*
|
||||
* Nonlinear least squares fit according to the
|
||||
* Marquardt-Levenberg-algorithm
|
||||
*
|
||||
* added as Patch to Gnuplot (v3.2 and higher)
|
||||
* by Carsten Grammes
|
||||
* Experimental Physics, University of Saarbruecken, Germany
|
||||
*
|
||||
* Internet address: cagr@rz.uni-sb.de
|
||||
*
|
||||
* Copyright of this module: Carsten Grammes, 1993
|
||||
*
|
||||
* Permission to use, copy, and distribute this software and its
|
||||
* documentation for any purpose with or without fee is hereby granted,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation.
|
||||
*
|
||||
* This software is provided "as is" without express or implied warranty.
|
||||
*/
|
||||
|
||||
#define NULL 0
|
||||
#define null 0
|
||||
|
||||
#include "fit.h"
|
||||
#include "matrix.h"
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// create a simple gc malloc...
|
||||
typedef struct Node {
|
||||
struct Node * next;
|
||||
void * ptr;
|
||||
} Node;
|
||||
|
||||
Node * head = null;
|
||||
|
||||
void * my_gc_malloc(int size) {
|
||||
void * ptr = malloc(size);
|
||||
Node * n = (Node *)malloc(sizeof (Node));
|
||||
n->ptr = ptr;
|
||||
n->next = head;
|
||||
head = n;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void gc_cleanup(){
|
||||
while(head) {
|
||||
Node * current = head;
|
||||
head = current->next;
|
||||
free(current->ptr);
|
||||
free(current);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
#define Swap(a,b) {double temp = (a); (a) = (b); (b) = temp;}
|
||||
#define WINZIG 1e-30
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
internal prototypes
|
||||
*****************************************************************/
|
||||
|
||||
static int fsign (double x);
|
||||
|
||||
/*****************************************************************
|
||||
first straightforward vector and matrix allocation functions
|
||||
*****************************************************************/
|
||||
MZ_DLLEXPORT
|
||||
double *vec (n)
|
||||
int n;
|
||||
{
|
||||
/* allocates a double vector with n elements */
|
||||
double *dp;
|
||||
if( n < 1 )
|
||||
return (double *) NULL;
|
||||
dp = (double *) my_gc_malloc (n * sizeof(double));
|
||||
return dp;
|
||||
}
|
||||
|
||||
|
||||
MZ_DLLEXPORT
|
||||
double **matr (rows, cols)
|
||||
int rows;
|
||||
int cols;
|
||||
{
|
||||
/* allocates a double matrix */
|
||||
|
||||
register int i;
|
||||
register double **m;
|
||||
|
||||
if ( rows < 1 || cols < 1 )
|
||||
return NULL;
|
||||
m = (double **) my_gc_malloc (rows * sizeof(double *));
|
||||
m[0] = (double *) my_gc_malloc (rows * cols * sizeof(double));
|
||||
for ( i = 1; i<rows ; i++ )
|
||||
m[i] = m[i-1] + cols;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
void free_matr (m)
|
||||
double **m;
|
||||
{
|
||||
free (m[0]);
|
||||
free (m);
|
||||
}
|
||||
|
||||
|
||||
MZ_DLLEXPORT
|
||||
double *redim_vec (v, n)
|
||||
double **v;
|
||||
int n;
|
||||
{
|
||||
if ( n < 1 )
|
||||
*v = NULL;
|
||||
else
|
||||
*v = (double *) my_gc_malloc( n * sizeof(double));
|
||||
return *v;
|
||||
}
|
||||
|
||||
MZ_DLLEXPORT
|
||||
void redim_ivec (v, n)
|
||||
int **v;
|
||||
int n;
|
||||
{
|
||||
if ( n < 1 ) {
|
||||
*v = NULL;
|
||||
return;
|
||||
}
|
||||
*v = (int *) my_gc_malloc ( n * sizeof(int));
|
||||
}
|
||||
|
||||
|
||||
/* HBB: TODO: is there a better value for 'epsilon'? how to specify
|
||||
* 'inline'? is 'fsign' really not available elsewhere? use
|
||||
* row-oriented version (p. 309) instead?
|
||||
*/
|
||||
|
||||
static int fsign(x)
|
||||
double x;
|
||||
{
|
||||
return( x>0 ? 1 : (x < 0) ? -1 : 0) ;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
|
||||
Solve least squares Problem C*x+d = r, |r| = min!, by Given rotations
|
||||
(QR-decomposition). Direct implementation of the algorithm
|
||||
presented in H.R.Schwarz: Numerische Mathematik, 'equation'
|
||||
number (7.33)
|
||||
|
||||
If 'd == NULL', d is not accesed: the routine just computes the QR
|
||||
decomposition of C and exits.
|
||||
|
||||
If 'want_r == 0', r is not rotated back (\hat{r} is returned
|
||||
instead).
|
||||
|
||||
*****************************************************************/
|
||||
|
||||
MZ_DLLEXPORT
|
||||
void Givens (C, d, x, r, N, n, want_r)
|
||||
double **C;
|
||||
double *d;
|
||||
double *x;
|
||||
double *r;
|
||||
int N;
|
||||
int n;
|
||||
int want_r;
|
||||
{
|
||||
int i, j, k;
|
||||
double w, gamma, sigma, rho, temp;
|
||||
double epsilon = 1e-5; /* FIXME (?)*/
|
||||
|
||||
/*
|
||||
* First, construct QR decomposition of C, by 'rotating away'
|
||||
* all elements of C below the diagonal. The rotations are
|
||||
* stored in place as Givens coefficients rho.
|
||||
* Vector d is also rotated in this same turn, if it exists
|
||||
*/
|
||||
for (j = 0; j<n; j++)
|
||||
for (i = j+1; i<N; i++)
|
||||
if (C[i][j]) {
|
||||
if (fabs(C[j][j])<epsilon*fabs(C[i][j])) { /* find the rotation parameters */
|
||||
w = -C[i][j];
|
||||
gamma = 0;
|
||||
sigma = 1;
|
||||
rho = 1;
|
||||
} else {
|
||||
w = fsign(C[j][j])*sqrt(C[j][j]*C[j][j] + C[i][j]*C[i][j]);
|
||||
if (w == 0) {
|
||||
// Eex3 ( "w = 0 in Givens(); Cjj = %g, Cij = %g", C[j][j], C[i][j]);
|
||||
}
|
||||
gamma = C[j][j]/w;
|
||||
sigma = -C[i][j]/w;
|
||||
rho = (fabs(sigma)<gamma) ? sigma : fsign(sigma)/gamma;
|
||||
}
|
||||
C[j][j] = w;
|
||||
C[i][j] = rho; /* store rho in place, for later use */
|
||||
for (k = j+1; k<n; k++) { /* rotation on index pair (i,j) */
|
||||
temp = gamma*C[j][k] - sigma*C[i][k];
|
||||
C[i][k] = sigma*C[j][k] + gamma*C[i][k];
|
||||
C[j][k] = temp;
|
||||
|
||||
}
|
||||
if (d) { /* if no d vector given, don't use it */
|
||||
temp = gamma*d[j] - sigma*d[i]; /* rotate d */
|
||||
d[i] = sigma*d[j] + gamma*d[i];
|
||||
d[j] = temp;
|
||||
}
|
||||
}
|
||||
if (!d) /* stop here if no d was specified */
|
||||
return;
|
||||
|
||||
for (i = n-1; i >= 0; i--) { /* solve R*x+d = 0, by backsubstitution */
|
||||
double s = d[i];
|
||||
r[i] = 0; /* ... and also set r[i] = 0 for i<n */
|
||||
for (k = i+1; k<n; k++)
|
||||
s += C[i][k]*x[k];
|
||||
if (C[i][i] == 0) {
|
||||
//Eex ( "Singular matrix in Givens()");
|
||||
}
|
||||
x[i] = - s / C[i][i];
|
||||
}
|
||||
for (i = n; i < N; i++)
|
||||
r[i] = d[i]; /* set the other r[i] to d[i] */
|
||||
|
||||
if (!want_r) /* if r isn't needed, stop here */
|
||||
return;
|
||||
|
||||
/* rotate back the r vector */
|
||||
for (j = n-1; j >= 0; j--)
|
||||
for (i = N-1; i >= 0; i--) {
|
||||
if ((rho = C[i][j]) == 1) { /* reconstruct gamma, sigma from stored rho */
|
||||
gamma = 0;
|
||||
sigma = 1;
|
||||
} else if (fabs(rho)<1) {
|
||||
sigma = rho;
|
||||
gamma = sqrt(1-sigma*sigma);
|
||||
} else {
|
||||
gamma = 1/fabs(rho);
|
||||
sigma = fsign(rho)*sqrt(1-gamma*gamma);
|
||||
}
|
||||
temp = gamma*r[j] + sigma*r[i]; /* rotate back indices (i,j) */
|
||||
r[i] = -sigma*r[j] + gamma*r[i];
|
||||
r[j] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Given a triangular Matrix R, compute (R^T * R)^(-1), by forward
|
||||
* then back substitution
|
||||
*
|
||||
* R, I are n x n Matrices, I is for the result. Both must already be
|
||||
* allocated.
|
||||
*
|
||||
* Will only calculate the lower triangle of I, as it is symmetric
|
||||
*/
|
||||
|
||||
MZ_DLLEXPORT
|
||||
void Invert_RtR ( R, I, n)
|
||||
double **R;
|
||||
double **I;
|
||||
int n;
|
||||
{
|
||||
int i, j, k;
|
||||
|
||||
/* fill in the I matrix, and check R for regularity : */
|
||||
|
||||
for (i = 0; i<n; i++) {
|
||||
for (j = 0; j<i; j++) /* upper triangle isn't needed */
|
||||
I[i][j] = 0;
|
||||
I[i][i] = 1;
|
||||
if (! R[i][i])
|
||||
{
|
||||
// Eex ("Singular matrix in Invert_RtR");
|
||||
}
|
||||
}
|
||||
|
||||
/* Forward substitution: Solve R^T * B = I, store B in place of I */
|
||||
|
||||
for (k = 0; k<n; k++)
|
||||
for (i = k; i<n; i++) { /* upper half needn't be computed */
|
||||
double s = I[i][k];
|
||||
for (j = k; j<i; j++) /* for j<k, I[j][k] always stays zero! */
|
||||
s -= R[j][i] * I[j][k];
|
||||
I[i][k] = s / R[i][i];
|
||||
}
|
||||
|
||||
/* Backward substitution: Solve R * A = B, store A in place of B */
|
||||
|
||||
for (k = 0; k<n; k++)
|
||||
for (i = n-1; i >= k; i--) { /* don't compute upper triangle of A */
|
||||
double s = I[i][k];
|
||||
for (j = i+1; j<n; j++)
|
||||
s -= R[i][j] * I[j][k];
|
||||
I[i][k] = s / R[i][i];
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/* $Id: matrix.h,v 1.5 2005/03/15 23:23:56 eli Exp $ */
|
||||
|
||||
/* GNUPLOT - matrix.h */
|
||||
|
||||
/* NOTICE: Change of Copyright Status
|
||||
*
|
||||
* The author of this module, Carsten Grammes, has expressed in
|
||||
* personal email that he has no more interest in this code, and
|
||||
* doesn't claim any copyright. He has agreed to put this module
|
||||
* into the public domain.
|
||||
*
|
||||
* Lars Hecking 15-02-1999
|
||||
*/
|
||||
|
||||
/*
|
||||
* Header file: public functions in matrix.c
|
||||
*
|
||||
*
|
||||
* Copyright of this module: Carsten Grammes, 1993
|
||||
* Experimental Physics, University of Saarbruecken, Germany
|
||||
*
|
||||
* Internet address: cagr@rz.uni-sb.de
|
||||
*
|
||||
* Permission to use, copy, and distribute this software and its
|
||||
* documentation for any purpose with or without fee is hereby granted,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation.
|
||||
*
|
||||
* This software is provided "as is" without express or implied warranty.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MATRIX_H
|
||||
#define MATRIX_H
|
||||
|
||||
#include "../dllexport.h"
|
||||
|
||||
|
||||
#ifdef EXT
|
||||
#undef EXT
|
||||
#endif
|
||||
|
||||
#ifdef MATRIX_MAIN
|
||||
#define EXT
|
||||
#else
|
||||
#define EXT extern
|
||||
#endif
|
||||
|
||||
|
||||
/******* public functions ******/
|
||||
|
||||
MZ_DLLEXPORT
|
||||
EXT double *vec (int n);
|
||||
MZ_DLLEXPORT
|
||||
EXT int *ivec (int n);
|
||||
MZ_DLLEXPORT
|
||||
EXT double **matr (int r, int c);
|
||||
MZ_DLLEXPORT
|
||||
EXT double *redim_vec (double **v, int n);
|
||||
MZ_DLLEXPORT
|
||||
EXT void redim_ivec (int **v, int n);
|
||||
EXT void solve (double **a, int n, double **b, int m);
|
||||
MZ_DLLEXPORT
|
||||
EXT void Givens (double **C, double *d, double *x, double *r, int N, int n, int want_r);
|
||||
MZ_DLLEXPORT
|
||||
EXT void Invert_RtR (double **R, double **I, int n);
|
||||
|
||||
#endif
|
||||
|
||||
// a kludgy version of a malloc
|
||||
|
||||
void * my_gc_malloc(int size);
|
||||
void gc_cleanup();
|
||||
|
|
@ -1,266 +0,0 @@
|
|||
/*
|
||||
Device driver whose handlers are inplemented in Racket
|
||||
using dc<%>.
|
||||
*/
|
||||
|
||||
#include "plDevs.h"
|
||||
#include "plplotP.h"
|
||||
#include "drivers.h"
|
||||
|
||||
/* Device info */
|
||||
char* plD_DEVICE_INFO_dc = "dc:dc<%>:0:dc:50:dc";
|
||||
|
||||
void plD_init_dc (PLStream *);
|
||||
void plD_line_dc (PLStream *, short, short, short, short);
|
||||
void plD_polyline_dc (PLStream *, short *, short *, PLINT);
|
||||
void plD_eop_dc (PLStream *);
|
||||
void plD_eop_jpeg (PLStream *);
|
||||
void plD_bop_dc (PLStream *);
|
||||
void plD_tidy_dc (PLStream *);
|
||||
void plD_state_dc (PLStream *, PLINT);
|
||||
void plD_esc_dc (PLStream *, PLINT, void *);
|
||||
|
||||
typedef struct {
|
||||
void *p;
|
||||
void (*drawLine)(void *p, short x1a, short y1a, short x2a, short y2a);
|
||||
void (*drawLines)(void *p, short *xa, short *ya, PLINT npts);
|
||||
void (*fillPoly)(void *p, short *xa, short *ya, PLINT npts);
|
||||
void (*setWidth)(void *p, int w);
|
||||
void (*setColor)(void *p, short i);
|
||||
void (*setColorRGB)(void *p, short r, short g, short b);
|
||||
void (*startPage)(void *p);
|
||||
void (*endPage)(void *p);
|
||||
void (*endDoc)(void *p);
|
||||
} dc_Dev;
|
||||
|
||||
void plD_dispatch_init_dc( PLDispatchTable *pdt )
|
||||
{
|
||||
pdt->pl_MenuStr = "drawing context";
|
||||
pdt->pl_DevName = "dc<%>";
|
||||
pdt->pl_type = plDevType_FileOriented;
|
||||
pdt->pl_seq = 50;
|
||||
pdt->pl_init = (plD_init_fp) plD_init_dc;
|
||||
pdt->pl_line = (plD_line_fp) plD_line_dc;
|
||||
pdt->pl_polyline = (plD_polyline_fp) plD_polyline_dc;
|
||||
pdt->pl_eop = (plD_eop_fp) plD_eop_dc;
|
||||
pdt->pl_bop = (plD_bop_fp) plD_bop_dc;
|
||||
pdt->pl_tidy = (plD_tidy_fp) plD_tidy_dc;
|
||||
pdt->pl_state = (plD_state_fp) plD_state_dc;
|
||||
pdt->pl_esc = (plD_esc_fp) plD_esc_dc;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plD_init_dc_Dev()
|
||||
*
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
plD_init_dc_Dev(PLStream *pls)
|
||||
{
|
||||
/* Allocate and initialize device-specific data */
|
||||
dc_Dev *dev;
|
||||
|
||||
if (pls->dev != NULL)
|
||||
free((void *) pls->dev);
|
||||
|
||||
pls->dev = calloc(1, (size_t) sizeof(dc_Dev));
|
||||
if (pls->dev == NULL)
|
||||
plexit("plD_init_dc_Dev: Out of memory.");
|
||||
|
||||
dev = (dc_Dev *) pls->dev;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* plD_init_dc()
|
||||
*
|
||||
* Initialize device.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void plD_init_dc(PLStream *pls)
|
||||
{
|
||||
dc_Dev *dev;
|
||||
|
||||
pls->termin = 0; /* Not an interactive device */
|
||||
pls->icol0 = 1;
|
||||
pls->bytecnt = 0;
|
||||
pls->page = 0;
|
||||
pls->dev_fill0 = 1; /* Can do solid fills */
|
||||
|
||||
if (!pls->colorset)
|
||||
pls->color = 1; /* Is a color device */
|
||||
|
||||
/* Initialize family file info */
|
||||
plFamInit(pls);
|
||||
|
||||
/* Allocate and initialize device-specific data */
|
||||
plD_init_dc_Dev(pls);
|
||||
dev=(dc_Dev *)pls->dev;
|
||||
|
||||
if (pls->xlength <= 0 || pls->ylength <=0)
|
||||
{
|
||||
/* use default width, height of 800x600 if not specifed by -geometry option
|
||||
* or plspage */
|
||||
plspage(0., 0., 800, 600, 0, 0);
|
||||
}
|
||||
|
||||
pls->graphx = GRAPHICS_MODE;
|
||||
|
||||
if (pls->xdpi<=0)
|
||||
{
|
||||
/* This corresponds to a typical monitor resolution of 4 pixels/mm. */
|
||||
plspage(4.*25.4, 4.*25.4, 0, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
pls->ydpi=pls->xdpi; /* Set X and Y dpi's to the same value */
|
||||
}
|
||||
/* Convert DPI to pixels/mm */
|
||||
plP_setpxl(1*pls->xdpi/25.4,1*pls->ydpi/25.4);
|
||||
|
||||
plP_setphy(0, 1*(pls->xlength - 1), 0, 1*(pls->ylength - 1));
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* plD_line_dc()
|
||||
*
|
||||
* Draw a line in the current color from (x1,y1) to (x2,y2).
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plD_line_dc(PLStream *pls, short x1a, short y1a, short x2a, short y2a)
|
||||
{
|
||||
dc_Dev *dev=(dc_Dev *)pls->dev;
|
||||
|
||||
if (dev->drawLine)
|
||||
dev->drawLine(dev->p, x1a, y1a, x2a, y2a);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* plD_polyline_dc()
|
||||
*
|
||||
* Draw a polyline in the current color.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plD_polyline_dc(PLStream *pls, short *xa, short *ya, PLINT npts)
|
||||
{
|
||||
dc_Dev *dev=(dc_Dev *)pls->dev;
|
||||
|
||||
if (dev->drawLines)
|
||||
dev->drawLines(dev->p, xa, ya, npts);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* fill_polygon()
|
||||
*
|
||||
* Fill polygon described in points pls->dev_x[] and pls->dev_y[].
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
fill_polygon(PLStream *pls)
|
||||
{
|
||||
dc_Dev *dev=(dc_Dev *)pls->dev;
|
||||
|
||||
if (dev->fillPoly)
|
||||
dev->fillPoly(dev->p, pls->dev_x, pls->dev_y, pls->dev_npts);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* plD_state_dc()
|
||||
*
|
||||
* Handle change in PLStream state (color, pen width, fill attribute, etc).
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plD_state_dc(PLStream *pls, PLINT op)
|
||||
{
|
||||
dc_Dev *dev=(dc_Dev *)pls->dev;
|
||||
|
||||
switch (op) {
|
||||
|
||||
case PLSTATE_WIDTH:
|
||||
if (dev->setWidth)
|
||||
dev->setWidth(dev->p, pls->width);
|
||||
break;
|
||||
|
||||
case PLSTATE_COLOR0:
|
||||
|
||||
if (pls->icol0 == PL_RGB_COLOR) {
|
||||
if (dev->setColorRGB)
|
||||
dev->setColorRGB(dev->p, pls->curcolor.r, pls->curcolor.g, pls->curcolor.b);
|
||||
} else {
|
||||
if (dev->setColor)
|
||||
dev->setColor(dev->p, pls->icol0);
|
||||
}
|
||||
break;
|
||||
|
||||
case PLSTATE_COLOR1:
|
||||
if (dev->setColorRGB)
|
||||
dev->setColorRGB(dev->p, pls->curcolor.r, pls->curcolor.g, pls->curcolor.b);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* plD_esc_dc()
|
||||
*
|
||||
* Escape function.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void plD_esc_dc(PLStream *pls, PLINT op, void *ptr)
|
||||
{
|
||||
switch (op) {
|
||||
|
||||
case PLESC_FILL: /* fill */
|
||||
fill_polygon(pls);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* plD_bop_dc()
|
||||
*
|
||||
* Set up for the next page.
|
||||
* Advance to next family file if necessary (file output).
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void plD_bop_dc(PLStream *pls)
|
||||
{
|
||||
dc_Dev *dev=(dc_Dev *)pls->dev;
|
||||
|
||||
if (dev->startPage)
|
||||
dev->startPage(dev->p);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* plD_tidy_dc()
|
||||
*
|
||||
* Close graphics file or otherwise clean up.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void plD_tidy_dc(PLStream *pls)
|
||||
{
|
||||
dc_Dev *dev=(dc_Dev *)pls->dev;
|
||||
|
||||
if (dev->endDoc)
|
||||
dev->endDoc(dev->p);
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* plD_eop_dc()
|
||||
*
|
||||
* End of page.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void plD_eop_dc(PLStream *pls)
|
||||
{
|
||||
dc_Dev *dev=(dc_Dev *)pls->dev;
|
||||
|
||||
if (dev->endPage)
|
||||
dev->endPage(dev->p);
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/* $Id: disptab.h,v 1.1 2004/03/01 20:54:46 cozmic Exp $
|
||||
|
||||
Defines the data structure which holds the driver functions.
|
||||
*/
|
||||
|
||||
#ifndef __DISPATCH_H__
|
||||
#define __DISPATCH_H__
|
||||
|
||||
#include "plConfig.h"
|
||||
|
||||
struct PLStream_struct;
|
||||
|
||||
enum {
|
||||
plDevType_FileOriented = 0,
|
||||
plDevType_Interactive = 1,
|
||||
plDevType_Null = -1
|
||||
};
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Define structure containing pointers to device dependent functions.
|
||||
*
|
||||
* pl_MenuStr Pointer to string that is printed in device menu.
|
||||
*
|
||||
* pl_DevName A short device "name" for device selection by name.
|
||||
*
|
||||
* pl_type 0 for file-oriented device, 1 for interactive
|
||||
* (the null driver uses -1 here)
|
||||
*
|
||||
* pl_seq The sequence number for ordering the presentation list of the
|
||||
* available drivers. This is an ordering only, not an absolute
|
||||
* position in the list.
|
||||
*
|
||||
* pl_init Initialize device. This routine may also prompt the user
|
||||
* for certain device parameters or open a graphics file
|
||||
* (see note). Called only once to set things up. Certain
|
||||
* options such as familying and resolution (dots/mm) should
|
||||
* be set up before calling this routine (note: some drivers
|
||||
* ignore these).
|
||||
*
|
||||
* pl_line Draws a line between two points.
|
||||
*
|
||||
* pl_polyline Draws a polyline (no broken segments).
|
||||
*
|
||||
* pl_eop Finishes out current page (see note).
|
||||
*
|
||||
* pl_bop Set up for plotting on a new page. May also open a new
|
||||
* a new graphics file (see note).
|
||||
*
|
||||
* pl_tidy Tidy up. May close graphics file (see note).
|
||||
*
|
||||
* pl_state Handle change in PLStream state
|
||||
* (color, pen width, fill attribute, etc).
|
||||
*
|
||||
* pl_esc Escape function for driver-specific commands.
|
||||
*
|
||||
*
|
||||
* Notes:
|
||||
*
|
||||
* Most devices allow multi-page plots to be stored in a single graphics
|
||||
* file, in which case the graphics file should be opened in the pl_init()
|
||||
* routine, closed in pl_tidy(), and page advances done by calling pl_eop
|
||||
* and pl_bop() in sequence. If multi-page plots need to be stored in
|
||||
* different files then pl_bop() should open the file and pl_eop() should
|
||||
* close it. Do NOT open files in both pl_init() and pl_bop() or close
|
||||
* files in both pl_eop() and pl_tidy().
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
typedef void (*plD_init_fp) (struct PLStream_struct *);
|
||||
typedef void (*plD_line_fp) (struct PLStream_struct *, short, short, short, short);
|
||||
typedef void (*plD_polyline_fp)(struct PLStream_struct *, short *, short *, PLINT);
|
||||
typedef void (*plD_eop_fp) (struct PLStream_struct *);
|
||||
typedef void (*plD_bop_fp) (struct PLStream_struct *);
|
||||
typedef void (*plD_tidy_fp) (struct PLStream_struct *);
|
||||
typedef void (*plD_state_fp) (struct PLStream_struct *, PLINT);
|
||||
typedef void (*plD_esc_fp) (struct PLStream_struct *, PLINT, void *);
|
||||
|
||||
typedef struct {
|
||||
char *pl_MenuStr;
|
||||
char *pl_DevName;
|
||||
int pl_type;
|
||||
int pl_seq;
|
||||
plD_init_fp pl_init;
|
||||
plD_line_fp pl_line;
|
||||
plD_polyline_fp pl_polyline;
|
||||
plD_eop_fp pl_eop;
|
||||
plD_bop_fp pl_bop;
|
||||
plD_tidy_fp pl_tidy;
|
||||
plD_state_fp pl_state;
|
||||
plD_esc_fp pl_esc;
|
||||
} PLDispatchTable;
|
||||
|
||||
#endif /* __DISPATCH_H__ */
|
|
@ -1,81 +0,0 @@
|
|||
/* $Id: drivers.h,v 1.1 2004/03/01 20:54:46 cozmic Exp $
|
||||
|
||||
Contains all prototypes for driver functions.
|
||||
*/
|
||||
|
||||
#ifndef __DRIVERS_H__
|
||||
#define __DRIVERS_H__
|
||||
|
||||
#include "pdf.h"
|
||||
#include "plstrm.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void plD_dispatch_init_mac8 ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_mac1 ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_nx ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_os2 ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_xw ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_gnome ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_tk ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_vga ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_mgr ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_win3 ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_vga ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_vga ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_vga ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_tiff ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_jpg ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_jpeg ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_bmp ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_vga ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_xterm ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_tekt ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_tek4107t ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_mskermit ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_versaterm( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_vlt ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_conex ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_dg ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_plm ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_tekf ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_tek4107f ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_psm ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_psc ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_xfig ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_ljiip ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_ljii ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_hp7470 ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_hp7580 ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_hpgl ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_imp ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_pbm ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_png ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_cgm ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_null ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_tkwin ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_pstex ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_ntk ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_mem ( PLDispatchTable *pdt );
|
||||
void plD_dispatch_init_dc ( PLDispatchTable *pdt );
|
||||
|
||||
/* Prototypes for plot buffer calls. */
|
||||
|
||||
void plbuf_init (PLStream *);
|
||||
void plbuf_line (PLStream *, short, short, short, short);
|
||||
void plbuf_polyline (PLStream *, short *, short *, PLINT);
|
||||
void plbuf_eop (PLStream *);
|
||||
void plbuf_bop (PLStream *);
|
||||
void plbuf_tidy (PLStream *);
|
||||
void plbuf_state (PLStream *, PLINT);
|
||||
void plbuf_esc (PLStream *, PLINT, void *);
|
||||
|
||||
void plRemakePlot (PLStream *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __DRIVERS_H__ */
|
|
@ -1,72 +0,0 @@
|
|||
/* $Id: metadefs.h,v 1.1 2004/03/01 20:54:50 cozmic Exp $
|
||||
|
||||
Geoffrey Furnish
|
||||
5 May 1991
|
||||
|
||||
This file contains definitions of constants and structures which
|
||||
are needed by the PLplot metafile writer and renderer.
|
||||
*/
|
||||
|
||||
/*
|
||||
* PLMETA_HEADER holds the magic string at head of metafile.
|
||||
* PLMETA_VERSION holds the version number (year & letter).
|
||||
*
|
||||
* Note: All strings written into the file header are limited to a maximum
|
||||
* of 80 characters.
|
||||
*/
|
||||
|
||||
#define PLMETA_HEADER "PLPLOT"
|
||||
#define PLMETA_VERSION "1993c"
|
||||
|
||||
/* These are used by the TK driver client/server code */
|
||||
|
||||
#define PLSERV_HEADER "PLPLOT"
|
||||
#define PLSERV_VERSION "1993b"
|
||||
|
||||
/* Symbolic constants for old metafile versions (prior to 1992a). */
|
||||
/* Now these are stored in the metafile header. */
|
||||
|
||||
#define PLMETA_X_OLD 10000
|
||||
#define PLMETA_Y_OLD 10000
|
||||
|
||||
/* Virtual dots/mm for our virtual display space. */
|
||||
|
||||
#define PIXEL_RES_X_OLD 42
|
||||
#define PIXEL_RES_Y_OLD 56
|
||||
|
||||
/* Macros to make it easier to abort on nonzero return code */
|
||||
/* Can't call plexit on a write failure since that would be circular */
|
||||
|
||||
#define plm_wr(code) \
|
||||
if (code) { fprintf(stderr, "Unable to write to MetaFile\n"); exit(1); }
|
||||
|
||||
#define plm_rd(code) \
|
||||
if (code) plexit( "Unable to read from MetaFile" )
|
||||
|
||||
/*
|
||||
Metafile commands.
|
||||
|
||||
*** NOTICE !!! ***
|
||||
If you change ANY of the following, you will wreck backward
|
||||
backward compatibility with old metafiles. You may add, but do
|
||||
NOT delete !!!
|
||||
*/
|
||||
|
||||
#define INITIALIZE 1
|
||||
#define CLOSE 2
|
||||
#define SWITCH_TO_TEXT 3 /* Obsolete, replaced by ESCAPE */
|
||||
#define SWITCH_TO_GRAPH 4 /* Obsolete, replaced by ESCAPE */
|
||||
#define EOP 5
|
||||
#define BOP 6
|
||||
#define NEW_COLOR 7 /* Obsolete, replaced by CHANGE_STATE */
|
||||
#define NEW_WIDTH 8 /* Obsolete, replaced by CHANGE_STATE */
|
||||
#define LINE 9
|
||||
#define LINETO 10
|
||||
#define ESCAPE 11
|
||||
#define ADVANCE 12 /* Obsolete, BOP/EOP used instead */
|
||||
#define POLYLINE 13
|
||||
#define NEW_COLOR0 NEW_COLOR
|
||||
#define NEW_COLOR1 14
|
||||
#define CHANGE_STATE 15
|
||||
#define BOP0 16 /* First BOP in a file */
|
||||
#define END_OF_FIELD 255
|
|
@ -1,33 +0,0 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* File: nan.h
|
||||
*
|
||||
* Created: 18/10/2001
|
||||
*
|
||||
* Author: Pavel Sakov
|
||||
* CSIRO Marine Research
|
||||
*
|
||||
* Purpose: NaN definition
|
||||
*
|
||||
* Description: Should cover 64 bit machines or other machines with GCC
|
||||
*
|
||||
* Revisions: None
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#if !defined(_NAN_H)
|
||||
#define _NAN_H
|
||||
|
||||
#if defined(__GNUC__)
|
||||
static const double NaN = 0.0 / 0.0;
|
||||
#elif defined(BIG_ENDIAN)
|
||||
static const long long lNaN = 0x7fffffffffffffff;
|
||||
|
||||
#define NaN (*(double*)&lNaN)
|
||||
#else
|
||||
static const long lNaN = 0xfff8000000000000;
|
||||
|
||||
#define NaN (*(double*)&lNaN)
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,107 +0,0 @@
|
|||
/* $Id: pdf.h,v 1.1 2004/03/01 20:54:50 cozmic Exp $
|
||||
|
||||
Copyright (C) 1992 by Maurice J. LeBrun
|
||||
|
||||
Macros and prototypes for the PDF package.
|
||||
|
||||
This software may be freely copied, modified and redistributed without
|
||||
fee provided that this copyright notice is preserved intact on all
|
||||
copies and modified copies.
|
||||
|
||||
There is no warranty or other guarantee of fitness of this software.
|
||||
It is provided solely "as is". The author(s) disclaim(s) all
|
||||
responsibility and liability with respect to this software's usage or
|
||||
its effect upon hardware or computer systems.
|
||||
*/
|
||||
|
||||
#ifndef __PDF_H__
|
||||
#define __PDF_H__
|
||||
|
||||
/* Some unsigned types */
|
||||
|
||||
#ifndef U_CHAR
|
||||
#define U_CHAR unsigned char
|
||||
#endif
|
||||
|
||||
#ifndef U_SHORT
|
||||
#define U_SHORT unsigned short
|
||||
#endif
|
||||
|
||||
#ifndef U_INT
|
||||
#define U_INT unsigned int
|
||||
#endif
|
||||
|
||||
#ifndef U_LONG
|
||||
#define U_LONG unsigned long
|
||||
#endif
|
||||
|
||||
#ifdef PLPLOT_USE_TCL_CHANNELS
|
||||
#include <tcl.h>
|
||||
#endif
|
||||
|
||||
/* PDFstrm definition */
|
||||
/* The low level PDF i/o routines use the transfer method appropriate for */
|
||||
/* the first non-null type below */
|
||||
|
||||
typedef struct {
|
||||
FILE *file; /* Filesystem */
|
||||
unsigned char *buffer; /* Memory buffer */
|
||||
#ifdef PLPLOT_USE_TCL_CHANNELS
|
||||
Tcl_Channel tclChan; /* Tcl channel */
|
||||
#endif
|
||||
long bp, bufmax; /* Buffer pointer and max size */
|
||||
} PDFstrm;
|
||||
|
||||
/* Info for the i/o device. Only used by Tcl/TK/dp drivers for now */
|
||||
|
||||
typedef struct {
|
||||
int fd; /* I/O device file descriptor */
|
||||
FILE *file; /* File handle */
|
||||
char *fileName; /* Fifo or socket name (if needed) */
|
||||
char *fileHandle; /* Handle for use from interpreter */
|
||||
int type; /* Communication channel type */
|
||||
char *typeName; /* As above, but in string form */
|
||||
} PLiodev;
|
||||
|
||||
/* Error numbers */
|
||||
|
||||
#define PDF_ERROR 1 /* Unknown error */
|
||||
#define PDF_FNOPEN 2 /* File not open */
|
||||
#define PDF_FAOPEN 3 /* File already open */
|
||||
#define PDF_BADUN 4 /* Bad unit number */
|
||||
#define PDF_BADNBITS 5 /* Invalid # of bits */
|
||||
#define PDF_RDERR 6 /* Read error */
|
||||
#define PDF_WRERR 7 /* Write error */
|
||||
#define PDF_NOTPDF 8 /* Not a valid PDF file */
|
||||
|
||||
/* Prototypes */
|
||||
/* Use a wrapper for the prototypes for use from K&R C */
|
||||
|
||||
void pdf_set PLARGS((char *option, int value));
|
||||
PDFstrm *pdf_fopen PLARGS((char *fileName, char *mode));
|
||||
PDFstrm *pdf_bopen PLARGS((U_CHAR *buffer, long bufmax));
|
||||
PDFstrm *pdf_finit PLARGS((FILE *file));
|
||||
PDFstrm *plLibOpenPdfstrm PLARGS((char *fn));
|
||||
int pdf_close PLARGS((PDFstrm *pdfs));
|
||||
|
||||
int pdf_putc PLARGS((int c, PDFstrm *pdfs));
|
||||
int pdf_getc PLARGS((PDFstrm *pdfs));
|
||||
int pdf_ungetc PLARGS((int c, PDFstrm *pdfs));
|
||||
int pdf_rdx PLARGS((U_CHAR *x, long nitems, PDFstrm *pdfs));
|
||||
|
||||
int pdf_rd_header PLARGS((PDFstrm *pdfs, char *header));
|
||||
int pdf_wr_header PLARGS((PDFstrm *pdfs, char *header));
|
||||
int pdf_wr_string PLARGS((PDFstrm *pdfs, const char *string));
|
||||
int pdf_rd_string PLARGS((PDFstrm *pdfs, char *string, int nmax));
|
||||
int pdf_wr_1byte PLARGS((PDFstrm *pdfs, U_CHAR s));
|
||||
int pdf_rd_1byte PLARGS((PDFstrm *pdfs, U_CHAR *ps));
|
||||
int pdf_wr_2bytes PLARGS((PDFstrm *pdfs, U_SHORT s));
|
||||
int pdf_rd_2bytes PLARGS((PDFstrm *pdfs, U_SHORT *ps));
|
||||
int pdf_wr_2nbytes PLARGS((PDFstrm *pdfs, U_SHORT *s, PLINT n));
|
||||
int pdf_rd_2nbytes PLARGS((PDFstrm *pdfs, U_SHORT *s, PLINT n));
|
||||
int pdf_wr_4bytes PLARGS((PDFstrm *pdfs, U_LONG s));
|
||||
int pdf_rd_4bytes PLARGS((PDFstrm *pdfs, U_LONG *ps));
|
||||
int pdf_wr_ieeef PLARGS((PDFstrm *pdfs, float f));
|
||||
int pdf_rd_ieeef PLARGS((PDFstrm *pdfs, float *pf));
|
||||
|
||||
#endif /* __PDF_H__ */
|
|
@ -1,917 +0,0 @@
|
|||
/* $Id: pdfutils.c,v 1.1 2004/03/01 20:54:50 cozmic Exp $
|
||||
|
||||
pdf_utils.c
|
||||
|
||||
Copyright (C) 1992, 1993, 1994, 1995
|
||||
Maurice LeBrun mjl@dino.ph.utexas.edu
|
||||
Institute for Fusion Studies University of Texas at Austin
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
|
||||
These functions do the low-level reading/writing of portable data files.
|
||||
Data can be written to/read from either a file handle or memory buffer.
|
||||
*/
|
||||
|
||||
#define NEED_PLDEBUG
|
||||
#include "plplotP.h"
|
||||
|
||||
static void print_ieeef (void *, void *);
|
||||
static int pdf_wrx (const U_CHAR *x, long nitems, PDFstrm *pdfs);
|
||||
|
||||
static int debug = 0;
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void pdf_set (string, value)
|
||||
*
|
||||
* Set an option. Pretty sparse right now but you never know.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
pdf_set(char *option, int value)
|
||||
{
|
||||
if ( ! strcmp(option, "debug"))
|
||||
debug = value;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* pdf_fopen()
|
||||
*
|
||||
* Initializes a PDFstrm for a file oriented device.
|
||||
* Used exactly like fopen().
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
PDFstrm *
|
||||
pdf_fopen(char *filename, char *mode)
|
||||
{
|
||||
PDFstrm *pdfs;
|
||||
|
||||
dbug_enter("pdf_fopen");
|
||||
|
||||
pdfs = (PDFstrm *) malloc(sizeof(PDFstrm));
|
||||
|
||||
if (pdfs != NULL) {
|
||||
pdfs->buffer = NULL;
|
||||
pdfs->file = NULL;
|
||||
#ifdef PLPLOT_USE_TCL_CHANNELS
|
||||
pdfs->tclChan = NULL;
|
||||
if (1) {
|
||||
char new_mode[3];
|
||||
int binary = 0;
|
||||
char *m, *p;
|
||||
|
||||
/* Copy over the mode, removing 'b' if needed */
|
||||
for (m = mode, p = new_mode; *m != 0; m++) {
|
||||
if (*m == 'b') {
|
||||
binary = 1;
|
||||
} else {
|
||||
*p = *m;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
*p = 0;
|
||||
|
||||
pdfs->tclChan = Tcl_OpenFileChannel(NULL, filename, new_mode, 0);
|
||||
if (pdfs->tclChan == NULL) {
|
||||
pdf_close(pdfs);
|
||||
pdfs = NULL;
|
||||
} else {
|
||||
if (binary) {
|
||||
Tcl_SetChannelOption(NULL, pdfs->tclChan, "-translation",
|
||||
"binary");
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
pdfs->file = fopen(filename, mode);
|
||||
if (pdfs->file == NULL) {
|
||||
pdf_close(pdfs);
|
||||
pdfs = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return pdfs;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* pdf_bopen()
|
||||
*
|
||||
* Initializes a PDFstrm for reading/writing to a memory buffer.
|
||||
* If buffer is NULL, a standard buffer is allocated.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
PDFstrm *
|
||||
pdf_bopen(U_CHAR *buffer, long bufmax)
|
||||
{
|
||||
PDFstrm *pdfs;
|
||||
|
||||
dbug_enter("pdf_bopen");
|
||||
|
||||
pdfs = (PDFstrm *) malloc(sizeof(PDFstrm));
|
||||
|
||||
if (pdfs != NULL) {
|
||||
pdfs->file = NULL;
|
||||
#ifdef PLPLOT_USE_TCL_CHANNELS
|
||||
pdfs->tclChan = NULL;
|
||||
#endif
|
||||
pdfs->bp = 0;
|
||||
|
||||
if (buffer == NULL) {
|
||||
if (bufmax > 0)
|
||||
pdfs->bufmax = bufmax;
|
||||
else
|
||||
pdfs->bufmax = 2048;
|
||||
|
||||
pdfs->buffer = (U_CHAR *) malloc(pdfs->bufmax);
|
||||
if (pdfs->buffer == NULL) {
|
||||
pdf_close(pdfs);
|
||||
pdfs = NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
pdfs->bufmax = bufmax;
|
||||
pdfs->buffer = buffer;
|
||||
}
|
||||
}
|
||||
|
||||
return pdfs;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* pdf_finit()
|
||||
*
|
||||
* Initializes a PDFstrm for a file oriented device.
|
||||
* Like pdf_fopen() but an existing file handle is specified.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
PDFstrm *
|
||||
pdf_finit(FILE *file)
|
||||
{
|
||||
PDFstrm *pdfs;
|
||||
|
||||
dbug_enter("pdf_finit");
|
||||
|
||||
pdfs = (PDFstrm *) malloc(sizeof(PDFstrm));
|
||||
|
||||
if (pdfs != NULL) {
|
||||
pdfs->buffer = NULL;
|
||||
pdfs->file = file;
|
||||
#ifdef PLPLOT_USE_TCL_CHANNELS
|
||||
pdfs->tclChan = NULL;
|
||||
#endif
|
||||
pdfs->bp = 0;
|
||||
}
|
||||
|
||||
return pdfs;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* pdf_close()
|
||||
*
|
||||
* Closes a PDFstrm.
|
||||
* Used exactly like fclose().
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_close(PDFstrm *pdfs)
|
||||
{
|
||||
dbug_enter("pdf_close");
|
||||
|
||||
if (pdfs != NULL) {
|
||||
if (pdfs->file != NULL) {
|
||||
fclose(pdfs->file);
|
||||
#ifdef PLPLOT_USE_TCL_CHANNELS
|
||||
} else if (pdfs->tclChan != NULL) {
|
||||
Tcl_Close(NULL, pdfs->tclChan);
|
||||
#endif
|
||||
} else if (pdfs->buffer != NULL) {
|
||||
free ((void *) pdfs->buffer);
|
||||
}
|
||||
free((void *) pdfs);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* int pdf_putc()
|
||||
*
|
||||
* Writes a single character.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_putc(int c, PDFstrm *pdfs)
|
||||
{
|
||||
int result = EOF;
|
||||
|
||||
if (pdfs->file != NULL) {
|
||||
result = putc(c, pdfs->file);
|
||||
pdfs->bp++;
|
||||
#ifdef PLPLOT_USE_TCL_CHANNELS
|
||||
} else if (pdfs->tclChan != NULL) {
|
||||
result = Tcl_WriteChars(pdfs->tclChan, &c, 1);
|
||||
pdfs->bp++;
|
||||
#endif
|
||||
} else if (pdfs->buffer != NULL) {
|
||||
if (pdfs->bp >= pdfs->bufmax) {
|
||||
pldebug("pdf_putc",
|
||||
"Increasing buffer to %d bytes\n", pdfs->bufmax);
|
||||
pdfs->bufmax += 512;
|
||||
pdfs->buffer = (U_CHAR *)
|
||||
realloc((void *) pdfs->buffer, pdfs->bufmax);
|
||||
}
|
||||
pdfs->buffer[pdfs->bp++] = c;
|
||||
result = c;
|
||||
}
|
||||
else
|
||||
plexit("pdf_putc: Illegal operation");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* int pdf_getc()
|
||||
*
|
||||
* Reads a single character.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_getc(PDFstrm *pdfs)
|
||||
{
|
||||
int result = EOF;
|
||||
|
||||
if (pdfs->file != NULL) {
|
||||
result = getc(pdfs->file);
|
||||
pdfs->bp++;
|
||||
#ifdef PLPLOT_USE_TCL_CHANNELS
|
||||
} else if (pdfs->tclChan != NULL) {
|
||||
result = Tcl_Read(pdfs->tclChan, &result, 1);
|
||||
pdfs->bp++;
|
||||
#endif
|
||||
} else if (pdfs->buffer != NULL) {
|
||||
if (pdfs->bp < pdfs->bufmax)
|
||||
result = pdfs->buffer[pdfs->bp++];
|
||||
}
|
||||
else
|
||||
plexit("pdf_getc: Illegal operation");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* int pdf_ungetc()
|
||||
*
|
||||
* Push back the last command read.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_ungetc(int c, PDFstrm *pdfs)
|
||||
{
|
||||
int result = EOF;
|
||||
|
||||
if (pdfs->file != NULL) {
|
||||
result = ungetc(c, pdfs->file);
|
||||
if (pdfs->bp > 0)
|
||||
pdfs->bp--;
|
||||
#ifdef PLPLOT_USE_TCL_CHANNELS
|
||||
} else if (pdfs->tclChan != NULL) {
|
||||
result = Tcl_Ungets(pdfs->tclChan, &c, 1, 0);
|
||||
if (pdfs->bp > 0)
|
||||
pdfs->bp--;
|
||||
#endif
|
||||
} else if (pdfs->buffer != NULL) {
|
||||
if (pdfs->bp > 0) {
|
||||
pdfs->buffer[--pdfs->bp] = c;
|
||||
result = c;
|
||||
}
|
||||
}
|
||||
else
|
||||
plexit("pdf_ungetc: Illegal operation");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* int pdf_wrx()
|
||||
*
|
||||
* Writes a record.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static int
|
||||
pdf_wrx(const U_CHAR *x, long nitems, PDFstrm *pdfs)
|
||||
{
|
||||
int i, result = 0;
|
||||
|
||||
if (pdfs->file != NULL) {
|
||||
result = fwrite(x, 1, nitems, pdfs->file);
|
||||
pdfs->bp += nitems;
|
||||
#ifdef PLPLOT_USE_TCL_CHANNELS
|
||||
} else if (pdfs->tclChan != NULL) {
|
||||
result = Tcl_Write(pdfs->tclChan, x, nitems);
|
||||
pdfs->bp += nitems;
|
||||
#endif
|
||||
} else if (pdfs->buffer != NULL) {
|
||||
for (i = 0; i < nitems; i++) {
|
||||
if (pdfs->bp >= pdfs->bufmax) {
|
||||
pldebug("pdf_wrx",
|
||||
"Increasing buffer to %d bytes\n", pdfs->bufmax);
|
||||
pdfs->bufmax += 512;
|
||||
pdfs->buffer = (U_CHAR *)
|
||||
realloc((void *) (pdfs->buffer), pdfs->bufmax);
|
||||
}
|
||||
pdfs->buffer[pdfs->bp++] = x[i];
|
||||
}
|
||||
result = i;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* int pdf_rdx()
|
||||
*
|
||||
* Reads a record.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_rdx(U_CHAR *x, long nitems, PDFstrm *pdfs)
|
||||
{
|
||||
int i, result = 0;
|
||||
|
||||
if (pdfs->file != NULL) {
|
||||
result = fread(x, 1, nitems, pdfs->file);
|
||||
pdfs->bp += nitems;
|
||||
#ifdef PLPLOT_USE_TCL_CHANNELS
|
||||
} else if (pdfs->tclChan != NULL) {
|
||||
result = Tcl_ReadRaw(pdfs->tclChan, x, nitems);
|
||||
pdfs->bp += nitems;
|
||||
#endif
|
||||
} else if (pdfs->buffer != NULL) {
|
||||
for (i = 0; i < nitems; i++) {
|
||||
if (pdfs->bp > pdfs->bufmax)
|
||||
break;
|
||||
x[i] = pdfs->buffer[pdfs->bp++];
|
||||
}
|
||||
result = i;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* pdf_wr_header()
|
||||
*
|
||||
* Writes a header string. Input string must be NULL-terminated. The
|
||||
* written string is terminated by a new-line, not a NULL. This is done
|
||||
* so you can type e.g. "% strings <file> | head" and get sensible output.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_wr_header(PDFstrm *pdfs, char *header)
|
||||
{
|
||||
int i;
|
||||
|
||||
dbug_enter("pdf_wr_header");
|
||||
|
||||
for (i = 0; i < 79; i++) {
|
||||
if (header[i] == '\0')
|
||||
break;
|
||||
if (pdf_putc(header[i], pdfs) == EOF)
|
||||
return PDF_WRERR;
|
||||
}
|
||||
if (pdf_putc('\n', pdfs) == EOF)
|
||||
return PDF_WRERR;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* int pdf_rd_header
|
||||
*
|
||||
* Reads a newline-terminated header string from PDFstrm *pdfs, and
|
||||
* converts to a usual NULL-terminated string. 80 chars maximum assumed.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_rd_header(PDFstrm *pdfs, char *header)
|
||||
{
|
||||
int i, c;
|
||||
|
||||
dbug_enter("pdf_rd_header");
|
||||
|
||||
for (i = 0; i < 79; i++) {
|
||||
if ((c = pdf_getc(pdfs)) == EOF)
|
||||
return PDF_RDERR;
|
||||
|
||||
header[i] = c;
|
||||
if (header[i] == '\n')
|
||||
break;
|
||||
}
|
||||
header[i] = '\0'; /* NULL terminate */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* pdf_wr_string()
|
||||
*
|
||||
* Writes a null-terminated string.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_wr_string(PDFstrm *pdfs, const char *string)
|
||||
{
|
||||
int i;
|
||||
|
||||
dbug_enter("pdf_wr_string");
|
||||
|
||||
for (i = 0; i <= strlen(string); i++) {
|
||||
if (pdf_putc(string[i], pdfs) == EOF)
|
||||
return PDF_WRERR;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* int pdf_rd_string
|
||||
*
|
||||
* Reads a null-terminated string from PDFstrm *pdfs.
|
||||
* A max of nmax chars are read.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_rd_string(PDFstrm *pdfs, char *string, int nmax)
|
||||
{
|
||||
int i, c;
|
||||
|
||||
dbug_enter("pdf_rd_string");
|
||||
|
||||
for (i = 0; i < nmax; i++) {
|
||||
if ((c = pdf_getc(pdfs)) == EOF)
|
||||
return PDF_RDERR;
|
||||
|
||||
string[i] = c;
|
||||
if (c == '\0')
|
||||
break;
|
||||
}
|
||||
string[i] = '\0'; /* handle boundary case */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* int pdf_wr_1byte()
|
||||
*
|
||||
* Writes a U_CHAR as a single byte.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_wr_1byte(PDFstrm *pdfs, U_CHAR s)
|
||||
{
|
||||
U_CHAR x[1];
|
||||
|
||||
x[0] = s;
|
||||
if (pdf_wrx(x, 1, pdfs) != 1)
|
||||
return PDF_WRERR;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* int pdf_rd_1byte()
|
||||
*
|
||||
* Reads a single byte, storing into a U_CHAR.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_rd_1byte(PDFstrm *pdfs, U_CHAR *ps)
|
||||
{
|
||||
U_CHAR x[1];
|
||||
|
||||
if ( ! pdf_rdx(x, 1, pdfs))
|
||||
return PDF_RDERR;
|
||||
|
||||
*ps = ((U_CHAR) x[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* pdf_wr_2bytes()
|
||||
*
|
||||
* Writes a U_SHORT as two single bytes, low end first.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_wr_2bytes(PDFstrm *pdfs, U_SHORT s)
|
||||
{
|
||||
U_CHAR x[2];
|
||||
|
||||
x[0] = (U_CHAR) ((U_LONG) (s & (U_LONG) 0x00FF));
|
||||
x[1] = (U_CHAR) ((U_LONG) (s & (U_LONG) 0xFF00) >> 8);
|
||||
|
||||
if (pdf_wrx(x, 2, pdfs) != 2)
|
||||
return PDF_WRERR;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* pdf_rd_2bytes()
|
||||
*
|
||||
* Reads a U_SHORT from two single bytes, low end first.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_rd_2bytes(PDFstrm *pdfs, U_SHORT *ps)
|
||||
{
|
||||
U_CHAR x[2];
|
||||
|
||||
if ( ! pdf_rdx(x, 2, pdfs))
|
||||
return PDF_RDERR;
|
||||
|
||||
*ps = 0;
|
||||
*ps |= (U_LONG) x[0];
|
||||
*ps |= (U_LONG) x[1] << 8;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* pdf_wr_2nbytes()
|
||||
*
|
||||
* Writes n U_SHORT's as 2n single bytes, low end first.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_wr_2nbytes(PDFstrm *pdfs, U_SHORT *s, PLINT n)
|
||||
{
|
||||
PLINT i;
|
||||
U_CHAR x[2];
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
x[0] = (U_CHAR) ((U_LONG) (s[i] & (U_LONG) 0x00FF));
|
||||
x[1] = (U_CHAR) ((U_LONG) (s[i] & (U_LONG) 0xFF00) >> 8);
|
||||
|
||||
if (pdf_wrx(x, 2, pdfs) != 2)
|
||||
return PDF_WRERR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* pdf_rd_2nbytes()
|
||||
*
|
||||
* Reads n U_SHORT's from 2n single bytes, low end first.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_rd_2nbytes(PDFstrm *pdfs, U_SHORT *s, PLINT n)
|
||||
{
|
||||
PLINT i;
|
||||
U_CHAR x[2];
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if ( ! pdf_rdx(x, 2, pdfs))
|
||||
return PDF_RDERR;
|
||||
|
||||
s[i] = 0;
|
||||
s[i] |= (U_SHORT) x[0];
|
||||
s[i] |= (U_SHORT) x[1] << 8;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* pdf_wr_4bytes()
|
||||
*
|
||||
* Writes an unsigned long as four single bytes, low end first.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_wr_4bytes(PDFstrm *pdfs, U_LONG s)
|
||||
{
|
||||
U_CHAR x[4];
|
||||
|
||||
x[0] = (U_CHAR) ((s & (U_LONG) 0x000000FF));
|
||||
x[1] = (U_CHAR) ((s & (U_LONG) 0x0000FF00) >> 8);
|
||||
x[2] = (U_CHAR) ((s & (U_LONG) 0x00FF0000) >> 16);
|
||||
x[3] = (U_CHAR) ((s & (U_LONG) 0xFF000000) >> 24);
|
||||
|
||||
if (pdf_wrx(x, 4, pdfs) != 4)
|
||||
return PDF_WRERR;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* pdf_rd_4bytes()
|
||||
*
|
||||
* Reads an unsigned long from 4 single bytes, low end first.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_rd_4bytes(PDFstrm *pdfs, U_LONG *ps)
|
||||
{
|
||||
U_CHAR x[4];
|
||||
|
||||
if ( ! pdf_rdx(x, 4, pdfs))
|
||||
return PDF_RDERR;
|
||||
|
||||
*ps = 0;
|
||||
*ps |= (U_LONG) x[0];
|
||||
*ps |= (U_LONG) x[1] << 8;
|
||||
*ps |= (U_LONG) x[2] << 16;
|
||||
*ps |= (U_LONG) x[3] << 24;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Here is the IEEE floating point specification in both 32 bit and 64 bit
|
||||
* precisions, from page 9 of "IEEE Standard for Binary Floating-Point
|
||||
* Arithmetic", copyright 1985, IEEE Std 754-1985:
|
||||
*
|
||||
*
|
||||
* Single Format
|
||||
*
|
||||
* msb means most significant bit
|
||||
* lsb means least significant bit
|
||||
*
|
||||
* 1 8 23
|
||||
* _____________________________________________________________________
|
||||
* | | | |
|
||||
* | s | e | f |
|
||||
* |___|________________|______________________________________________|
|
||||
* msb lsb msb lsb
|
||||
*
|
||||
*
|
||||
*
|
||||
* Double Format
|
||||
*
|
||||
* msb means most significant bit
|
||||
* lsb means least significant bit
|
||||
*
|
||||
* 1 11 52
|
||||
* _____________________________________________________________________
|
||||
* | | | |
|
||||
* | s | e | f |
|
||||
* |___|________________|______________________________________________|
|
||||
* msb lsb msb lsb
|
||||
*
|
||||
*
|
||||
* (Thanks to: Andy Mai (mai@ncar.ucar.edu))
|
||||
*
|
||||
*
|
||||
* According to "inmos: Transputer instruction set" the IEEE standard
|
||||
* specifies the floating format as:
|
||||
*
|
||||
* s exp frac
|
||||
*
|
||||
* Where: s = sign bit (1 bit)
|
||||
* exp = exponent (8 bits for 32 bit float / 11 bits for 64 bit float)
|
||||
* frac = fraction (23 bits for 32 bit float / 52 bits for 64 bit float)
|
||||
*
|
||||
* value of (s exp frac) = (-1)^s * 1.frac * 2^(exp-bias) ; if exp not 0
|
||||
* (-1)^s * 0.frac * 2^(1-bias) ; if exp = 0
|
||||
*
|
||||
* where bias = 127 for 32 bit float
|
||||
* bias = 1023 for 64 bit float
|
||||
*
|
||||
* (Thanks to: Tom Bjorkholm(TBJORKHOLM@abo.fi))
|
||||
*
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* int pdf_wr_ieeef()
|
||||
*
|
||||
* Writes a float in IEEE single precision (32 bit) format.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_wr_ieeef(PDFstrm *pdfs, float f)
|
||||
{
|
||||
double fdbl, fmant, f_new;
|
||||
float fsgl, f_tmp;
|
||||
int istat, exp, e_new, e_off, bias = 127;
|
||||
U_LONG value, s_ieee, e_ieee, f_ieee;
|
||||
|
||||
if (f == 0.0) {
|
||||
value = 0;
|
||||
return (pdf_wr_4bytes(pdfs, value));
|
||||
}
|
||||
fsgl = fdbl = f;
|
||||
fmant = frexp(fdbl, &exp);
|
||||
|
||||
if (fmant < 0)
|
||||
s_ieee = 1;
|
||||
else
|
||||
s_ieee = 0;
|
||||
|
||||
fmant = fabs(fmant);
|
||||
f_new = 2 * fmant;
|
||||
e_new = exp - 1;
|
||||
|
||||
if (e_new < 1 - bias) {
|
||||
e_off = e_new - (1 - bias);
|
||||
e_ieee = 0;
|
||||
f_tmp = f_new * pow((double) 2.0, (double) e_off);
|
||||
}
|
||||
else {
|
||||
e_ieee = e_new + bias;
|
||||
f_tmp = f_new - 1;
|
||||
}
|
||||
f_ieee = f_tmp * 8388608; /* multiply by 2^23 */
|
||||
|
||||
if (e_ieee > 255) {
|
||||
if (debug)
|
||||
fprintf(stderr, "pdf_wr_ieeef: Warning -- overflow\n");
|
||||
e_ieee = 255;
|
||||
}
|
||||
|
||||
s_ieee = s_ieee << 31;
|
||||
e_ieee = e_ieee << 23;
|
||||
|
||||
value = s_ieee | e_ieee | f_ieee;
|
||||
|
||||
if ((istat = pdf_wr_4bytes(pdfs, value)))
|
||||
return (istat);
|
||||
|
||||
if (debug) {
|
||||
fprintf(stderr, "Float value (written): %g\n", fsgl);
|
||||
print_ieeef(&fsgl, &value);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* int pdf_rd_ieeef()
|
||||
*
|
||||
* Reads a float from a IEEE single precision (32 bit) format.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
pdf_rd_ieeef(PDFstrm *pdfs, float *pf)
|
||||
{
|
||||
double f_new, f_tmp;
|
||||
float fsgl;
|
||||
int istat, exp, bias = 127;
|
||||
U_LONG value, s_ieee, e_ieee, f_ieee;
|
||||
|
||||
if ((istat = pdf_rd_4bytes(pdfs, &value)))
|
||||
return (istat);
|
||||
|
||||
s_ieee = (value & (U_LONG) 0x80000000) >> 31;
|
||||
e_ieee = (value & (U_LONG) 0x7F800000) >> 23;
|
||||
f_ieee = (value & (U_LONG) 0x007FFFFF);
|
||||
|
||||
f_tmp = (double) f_ieee / 8388608.0; /* divide by 2^23 */
|
||||
|
||||
if (e_ieee == 0) {
|
||||
exp = 1 - bias;
|
||||
f_new = f_tmp;
|
||||
}
|
||||
else {
|
||||
exp = (int) e_ieee - bias;
|
||||
f_new = 1.0 + f_tmp;
|
||||
}
|
||||
|
||||
fsgl = f_new * pow(2.0, (double) exp);
|
||||
if (s_ieee == 1)
|
||||
fsgl = -fsgl;
|
||||
|
||||
*pf = fsgl;
|
||||
|
||||
if (debug) {
|
||||
fprintf(stderr, "Float value (read): %g\n", fsgl);
|
||||
print_ieeef(&fsgl, &value);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* print_ieeef()
|
||||
*
|
||||
* Prints binary representation for numbers pointed to by arguments.
|
||||
* The first argument is the original float, the second is the
|
||||
* IEEE representation. They should be the same on any machine that
|
||||
* uses IEEE floats.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
print_ieeef(void *vx, void *vy)
|
||||
{
|
||||
int i;
|
||||
U_LONG f, *x = (U_LONG *) vx, *y = (U_LONG *) vy;
|
||||
char bitrep[33];
|
||||
|
||||
bitrep[32] = '\0';
|
||||
|
||||
f = *x;
|
||||
for (i = 0; i < 32; i++) {
|
||||
if (f & 1)
|
||||
bitrep[32 - i - 1] = '1';
|
||||
else
|
||||
bitrep[32 - i - 1] = '0';
|
||||
f = f >> 1;
|
||||
}
|
||||
fprintf(stderr, "Binary representation: ");
|
||||
fprintf(stderr, "%s\n", bitrep);
|
||||
|
||||
f = *y;
|
||||
for (i = 0; i < 32; i++) {
|
||||
if (f & 1)
|
||||
bitrep[32 - i - 1] = '1';
|
||||
else
|
||||
bitrep[32 - i - 1] = '0';
|
||||
f = f >> 1;
|
||||
}
|
||||
fprintf(stderr, "Converted representation: ");
|
||||
fprintf(stderr, "%s\n\n", bitrep);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plAlloc2dGrid()
|
||||
*
|
||||
* Allocates a block of memory for use as a 2-d grid of PLFLT's.
|
||||
* Resulting array can be indexed as f[i][j] anywhere. This is to be used
|
||||
* instead of PLFLT f[nx][ny], which is less useful. Note that this type
|
||||
* of allocation is required by the PLplot functions which take a 2-d
|
||||
* grids of PLFLT's as an argument, such as plcont() and plot3d().
|
||||
* Example usage:
|
||||
*
|
||||
* PLFLT **z;
|
||||
*
|
||||
* Alloc2dGrid(&z, XPTS, YPTS);
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plAlloc2dGrid(PLFLT ***f, PLINT nx, PLINT ny)
|
||||
{
|
||||
PLINT i;
|
||||
|
||||
if ((*f = (PLFLT **) calloc(nx, sizeof(PLFLT *)))==NULL)
|
||||
plexit("Memory allocation error in \"plAlloc2dGrid\"");
|
||||
|
||||
for (i = 0; i < nx; i++) {
|
||||
if (((*f)[i] = (PLFLT *) calloc(ny ,sizeof(PLFLT)))==NULL)
|
||||
plexit("Memory allocation error in \"plAlloc2dGrid\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Free2dGrid()
|
||||
*
|
||||
* Frees a block of memory allocated with Alloc2dGrid().
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plFree2dGrid(PLFLT **f, PLINT nx, PLINT ny)
|
||||
{
|
||||
PLINT i;
|
||||
|
||||
for (i = 0; i < nx; i++)
|
||||
free((void *) f[i]);
|
||||
|
||||
free((void *) f);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* MinMax2dGrid()
|
||||
*
|
||||
* Finds the maximum and minimum of a 2d matrix allocated with plAllc2dGrid().
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plMinMax2dGrid(PLFLT **f, PLINT nx, PLINT ny, PLFLT *fmax, PLFLT *fmin)
|
||||
{
|
||||
int i, j;
|
||||
PLFLT m, M;
|
||||
|
||||
M = m = f[0][0];
|
||||
|
||||
for (i = 0; i < nx; i++) {
|
||||
for (j = 0; j < ny; j++) {
|
||||
if (f[i][j] > M) M = f[i][j];
|
||||
if (f[i][j] < m) m = f[i][j];
|
||||
}
|
||||
}
|
||||
*fmax = M;
|
||||
*fmin = m;
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
#ifndef __PLCONFIG_H__
|
||||
#define __PLCONFIG_H__
|
||||
#define LIB_DIR "..\\..\\..\\lib"
|
||||
#define BIN_DIR "..\\..\\..\\bin"
|
||||
#define DATA_DIR "..\\..\\..\\lib"
|
||||
#define DRV_DIR "..\\..\\..\\lib"
|
||||
#define VERSION "5.2.1"
|
||||
#define PL_DOUBLE
|
||||
#endif
|
|
@ -1,2 +0,0 @@
|
|||
#define PLD_null
|
||||
|
|
@ -1,724 +0,0 @@
|
|||
/* $Id: plbuf.c,v 1.1 2004/03/01 20:54:50 cozmic Exp $
|
||||
|
||||
Handle plot buffer.
|
||||
|
||||
Copyright 1992
|
||||
Maurice LeBrun
|
||||
|
||||
This software may be freely copied, modified and redistributed without
|
||||
fee provided that this copyright notice is preserved intact on all
|
||||
copies and modified copies.
|
||||
|
||||
There is no warranty or other guarantee of fitness of this software.
|
||||
It is provided solely "as is". The author(s) disclaim(s) all
|
||||
responsibility and liability with respect to this software's usage or
|
||||
its effect upon hardware or computer systems.
|
||||
*/
|
||||
|
||||
#define NEED_PLDEBUG
|
||||
#include "plplotP.h"
|
||||
#include "drivers.h"
|
||||
#include "metadefs.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* Function prototypes */
|
||||
|
||||
static int rd_command (PLStream *pls, U_CHAR *p_c);
|
||||
static int wr_command (PLStream *pls, U_CHAR c);
|
||||
static void plbuf_control (PLStream *pls, U_CHAR c);
|
||||
|
||||
static void rdbuf_init (PLStream *pls);
|
||||
static void rdbuf_line (PLStream *pls);
|
||||
static void rdbuf_polyline (PLStream *pls);
|
||||
static void rdbuf_eop (PLStream *pls);
|
||||
static void rdbuf_bop (PLStream *pls);
|
||||
static void rdbuf_state (PLStream *pls);
|
||||
static void rdbuf_esc (PLStream *pls);
|
||||
|
||||
static void plbuf_fill (PLStream *pls);
|
||||
static void rdbuf_fill (PLStream *pls);
|
||||
static void plbuf_swin (PLStream *pls, PLWindow *plwin);
|
||||
static void rdbuf_swin (PLStream *pls);
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plbuf_init()
|
||||
*
|
||||
* Initialize device.
|
||||
* Actually just disables writes if plot buffer is already open (occurs
|
||||
* when one stream is cloned, as in printing).
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plbuf_init(PLStream *pls)
|
||||
{
|
||||
dbug_enter("plbuf_init");
|
||||
|
||||
pls->plbuf_read = FALSE;
|
||||
if (pls->plbufFile != NULL)
|
||||
pls->plbuf_write = FALSE;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plbuf_line()
|
||||
*
|
||||
* Draw a line in the current color from (x1,y1) to (x2,y2).
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plbuf_line(PLStream *pls, short x1a, short y1a, short x2a, short y2a)
|
||||
{
|
||||
short xpl[2], ypl[2];
|
||||
|
||||
dbug_enter("plbuf_line");
|
||||
|
||||
wr_command(pls, (U_CHAR) LINE);
|
||||
|
||||
xpl[0] = x1a;
|
||||
xpl[1] = x2a;
|
||||
ypl[0] = y1a;
|
||||
ypl[1] = y2a;
|
||||
|
||||
fwrite(xpl, sizeof(short), 2, pls->plbufFile);
|
||||
fwrite(ypl, sizeof(short), 2, pls->plbufFile);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plbuf_polyline()
|
||||
*
|
||||
* Draw a polyline in the current color.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plbuf_polyline(PLStream *pls, short *xa, short *ya, PLINT npts)
|
||||
{
|
||||
dbug_enter("plbuf_polyline");
|
||||
|
||||
wr_command(pls, (U_CHAR) POLYLINE);
|
||||
fwrite(&npts, sizeof(PLINT), 1, pls->plbufFile);
|
||||
|
||||
fwrite(xa, sizeof(short), npts, pls->plbufFile);
|
||||
fwrite(ya, sizeof(short), npts, pls->plbufFile);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plbuf_eop()
|
||||
*
|
||||
* End of page.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plbuf_eop(PLStream *pls)
|
||||
{
|
||||
dbug_enter("plbuf_eop");
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plbuf_bop()
|
||||
*
|
||||
* Set up for the next page.
|
||||
* To avoid problems redisplaying partially filled pages, on each BOP the
|
||||
* old file is thrown away and a new one is obtained. This way we can just
|
||||
* read up to EOF to get everything on the current page.
|
||||
*
|
||||
* Also write state information to ensure the next page is correct.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plbuf_bop(PLStream *pls)
|
||||
{
|
||||
dbug_enter("plbuf_bop");
|
||||
|
||||
plbuf_tidy(pls);
|
||||
|
||||
pls->plbufFile = tmpfile();
|
||||
if (pls->plbufFile == NULL)
|
||||
plexit("plbuf_init: Error opening plot data storage file.");
|
||||
|
||||
wr_command(pls, (U_CHAR) BOP);
|
||||
plbuf_state(pls, PLSTATE_COLOR0);
|
||||
plbuf_state(pls, PLSTATE_WIDTH);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plbuf_tidy()
|
||||
*
|
||||
* Close graphics file
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plbuf_tidy(PLStream *pls)
|
||||
{
|
||||
dbug_enter("plbuf_tidy");
|
||||
|
||||
if (pls->plbufFile == NULL)
|
||||
return;
|
||||
|
||||
fclose(pls->plbufFile);
|
||||
pls->plbufFile = NULL;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plbuf_state()
|
||||
*
|
||||
* Handle change in PLStream state (color, pen width, fill attribute, etc).
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plbuf_state(PLStream *pls, PLINT op)
|
||||
{
|
||||
dbug_enter("plbuf_state");
|
||||
|
||||
wr_command(pls, (U_CHAR) CHANGE_STATE);
|
||||
wr_command(pls, (U_CHAR) op);
|
||||
|
||||
switch (op) {
|
||||
|
||||
case PLSTATE_WIDTH: {
|
||||
U_CHAR width = pls->width;
|
||||
|
||||
fwrite(&width, sizeof(U_CHAR), 1, pls->plbufFile);
|
||||
break;
|
||||
}
|
||||
|
||||
case PLSTATE_COLOR0: {
|
||||
U_CHAR icol0 = pls->icol0;
|
||||
U_CHAR r = pls->curcolor.r;
|
||||
U_CHAR g = pls->curcolor.g;
|
||||
U_CHAR b = pls->curcolor.b;
|
||||
|
||||
fwrite(&icol0, sizeof(U_CHAR), 1, pls->plbufFile);
|
||||
if (icol0 == PL_RGB_COLOR) {
|
||||
fwrite(&r, sizeof(U_CHAR), 1, pls->plbufFile);
|
||||
fwrite(&g, sizeof(U_CHAR), 1, pls->plbufFile);
|
||||
fwrite(&b, sizeof(U_CHAR), 1, pls->plbufFile);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case PLSTATE_COLOR1: {
|
||||
U_CHAR icol1 = pls->icol1;
|
||||
|
||||
fwrite(&icol1, sizeof(U_CHAR), 1, pls->plbufFile);
|
||||
break;
|
||||
}
|
||||
|
||||
case PLSTATE_FILL:{
|
||||
signed char patt = pls->patt;
|
||||
|
||||
fwrite(&patt, sizeof(signed char), 1, pls->plbufFile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plbuf_image()
|
||||
*
|
||||
* write image described in points pls->dev_x[], pls->dev_y[], pls->dev_z[].
|
||||
* pls->nptsX, pls->nptsY.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
plbuf_image(PLStream *pls, IMG_DT *img_dt)
|
||||
{
|
||||
PLINT npts = pls->dev_nptsX * pls->dev_nptsY;
|
||||
|
||||
dbug_enter("plbuf_image");
|
||||
|
||||
fwrite(&pls->dev_nptsX, sizeof(PLINT), 1, pls->plbufFile);
|
||||
fwrite(&pls->dev_nptsY, sizeof(PLINT), 1, pls->plbufFile);
|
||||
|
||||
fwrite(&img_dt->xmin, sizeof(PLFLT), 1, pls->plbufFile);
|
||||
fwrite(&img_dt->ymin, sizeof(PLFLT), 1, pls->plbufFile);
|
||||
fwrite(&img_dt->dx, sizeof(PLFLT), 1, pls->plbufFile);
|
||||
fwrite(&img_dt->dy, sizeof(PLFLT), 1, pls->plbufFile);
|
||||
|
||||
fwrite(&pls->dev_zmin, sizeof(short), 1, pls->plbufFile);
|
||||
fwrite(&pls->dev_zmax, sizeof(short), 1, pls->plbufFile);
|
||||
|
||||
fwrite(pls->dev_ix, sizeof(short), npts, pls->plbufFile);
|
||||
fwrite(pls->dev_iy, sizeof(short), npts, pls->plbufFile);
|
||||
fwrite(pls->dev_z, sizeof(unsigned short), (pls->dev_nptsX-1)*(pls->dev_nptsY-1), pls->plbufFile);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plbuf_esc()
|
||||
*
|
||||
* Escape function. Note that any data written must be in device
|
||||
* independent form to maintain the transportability of the metafile.
|
||||
*
|
||||
* Functions:
|
||||
*
|
||||
* PLESC_FILL Fill polygon
|
||||
* PLESC_SWIN Set plot window parameters
|
||||
* PLESC_IMAGE Draw image
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plbuf_esc(PLStream *pls, PLINT op, void *ptr)
|
||||
{
|
||||
dbug_enter("plbuf_esc");
|
||||
|
||||
wr_command(pls, (U_CHAR) ESCAPE);
|
||||
wr_command(pls, (U_CHAR) op);
|
||||
|
||||
switch (op) {
|
||||
case PLESC_FILL:
|
||||
plbuf_fill(pls);
|
||||
break;
|
||||
case PLESC_SWIN:
|
||||
plbuf_swin(pls, (PLWindow *) ptr);
|
||||
break;
|
||||
case PLESC_IMAGE:
|
||||
plbuf_image(pls, (IMG_DT *) ptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plbuf_fill()
|
||||
*
|
||||
* Fill polygon described in points pls->dev_x[] and pls->dev_y[].
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
plbuf_fill(PLStream *pls)
|
||||
{
|
||||
dbug_enter("plbuf_fill");
|
||||
|
||||
fwrite(&pls->dev_npts, sizeof(PLINT), 1, pls->plbufFile);
|
||||
fwrite(pls->dev_x, sizeof(short), pls->dev_npts, pls->plbufFile);
|
||||
fwrite(pls->dev_y, sizeof(short), pls->dev_npts, pls->plbufFile);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plbuf_swin()
|
||||
*
|
||||
* Set up plot window parameters.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
plbuf_swin(PLStream *pls, PLWindow *plwin)
|
||||
{
|
||||
fwrite(&plwin->dxmi, sizeof(PLFLT), 1, pls->plbufFile);
|
||||
fwrite(&plwin->dxma, sizeof(PLFLT), 1, pls->plbufFile);
|
||||
fwrite(&plwin->dymi, sizeof(PLFLT), 1, pls->plbufFile);
|
||||
fwrite(&plwin->dyma, sizeof(PLFLT), 1, pls->plbufFile);
|
||||
|
||||
fwrite(&plwin->wxmi, sizeof(PLFLT), 1, pls->plbufFile);
|
||||
fwrite(&plwin->wxma, sizeof(PLFLT), 1, pls->plbufFile);
|
||||
fwrite(&plwin->wymi, sizeof(PLFLT), 1, pls->plbufFile);
|
||||
fwrite(&plwin->wyma, sizeof(PLFLT), 1, pls->plbufFile);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Routines to read from & process the plot buffer.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* rdbuf_init()
|
||||
*
|
||||
* Initialize device.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
rdbuf_init(PLStream *pls)
|
||||
{
|
||||
dbug_enter("rdbuf_init");
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* rdbuf_line()
|
||||
*
|
||||
* Draw a line in the current color from (x1,y1) to (x2,y2).
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
rdbuf_line(PLStream *pls)
|
||||
{
|
||||
short xpl[2], ypl[2];
|
||||
PLINT npts = 2;
|
||||
|
||||
dbug_enter("rdbuf_line");
|
||||
|
||||
if (npts != fread(xpl, sizeof(short), npts, pls->plbufFile)) return;
|
||||
if (npts != fread(ypl, sizeof(short), npts, pls->plbufFile)) return;
|
||||
|
||||
plP_line(xpl, ypl);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* rdbuf_polyline()
|
||||
*
|
||||
* Draw a polyline in the current color.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
rdbuf_polyline(PLStream *pls)
|
||||
{
|
||||
short xpl[PL_MAXPOLY], ypl[PL_MAXPOLY];
|
||||
PLINT npts;
|
||||
|
||||
dbug_enter("rdbuf_polyline");
|
||||
|
||||
if (1 != fread(&npts, sizeof(PLINT), 1, pls->plbufFile)) return;
|
||||
if (npts != fread(xpl, sizeof(short), npts, pls->plbufFile)) return;
|
||||
if (npts != fread(ypl, sizeof(short), npts, pls->plbufFile)) return;
|
||||
|
||||
plP_polyline(xpl, ypl, npts);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* rdbuf_eop()
|
||||
*
|
||||
* End of page.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
rdbuf_eop(PLStream *pls)
|
||||
{
|
||||
dbug_enter("rdbuf_eop");
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* rdbuf_bop()
|
||||
*
|
||||
* Set up for the next page.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
rdbuf_bop(PLStream *pls)
|
||||
{
|
||||
dbug_enter("rdbuf_bop");
|
||||
|
||||
pls->nplwin = 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* rdbuf_state()
|
||||
*
|
||||
* Handle change in PLStream state (color, pen width, fill attribute, etc).
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
rdbuf_state(PLStream *pls)
|
||||
{
|
||||
U_CHAR op;
|
||||
|
||||
dbug_enter("rdbuf_state");
|
||||
|
||||
if (1 != fread(&op, sizeof(U_CHAR), 1, pls->plbufFile)) return;
|
||||
|
||||
switch (op) {
|
||||
|
||||
case PLSTATE_WIDTH:{
|
||||
U_CHAR width;
|
||||
|
||||
if (1 != fread(&width, sizeof(U_CHAR), 1, pls->plbufFile)) return;
|
||||
pls->width = width;
|
||||
plP_state(PLSTATE_WIDTH);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case PLSTATE_COLOR0:{
|
||||
U_CHAR icol0, r, g, b;
|
||||
|
||||
if (1 != fread(&icol0, sizeof(U_CHAR), 1, pls->plbufFile)) return;
|
||||
if (icol0 == PL_RGB_COLOR) {
|
||||
if (1 != fread(&r, sizeof(U_CHAR), 1, pls->plbufFile)) return;
|
||||
if (1 != fread(&g, sizeof(U_CHAR), 1, pls->plbufFile)) return;
|
||||
if (1 != fread(&b, sizeof(U_CHAR), 1, pls->plbufFile)) return;
|
||||
}
|
||||
else {
|
||||
if ((int) icol0 > 15) {
|
||||
plwarn("rdbuf_state: Color map 0 entry hosed");
|
||||
icol0 = 1;
|
||||
}
|
||||
r = pls->cmap0[icol0].r;
|
||||
g = pls->cmap0[icol0].g;
|
||||
b = pls->cmap0[icol0].b;
|
||||
}
|
||||
pls->icol0 = icol0;
|
||||
pls->curcolor.r = r;
|
||||
pls->curcolor.g = g;
|
||||
pls->curcolor.b = b;
|
||||
|
||||
plP_state(PLSTATE_COLOR0);
|
||||
break;
|
||||
}
|
||||
|
||||
case PLSTATE_COLOR1: {
|
||||
U_CHAR icol1;
|
||||
|
||||
if (1 != fread(&icol1, sizeof(U_CHAR), 1, pls->plbufFile)) return;
|
||||
|
||||
pls->icol1 = icol1;
|
||||
pls->curcolor.r = pls->cmap1[icol1].r;
|
||||
pls->curcolor.g = pls->cmap1[icol1].g;
|
||||
pls->curcolor.b = pls->cmap1[icol1].b;
|
||||
|
||||
plP_state(PLSTATE_COLOR1);
|
||||
break;
|
||||
}
|
||||
|
||||
case PLSTATE_FILL: {
|
||||
signed char patt;
|
||||
|
||||
if (1 != fread(&patt, sizeof(signed char), 1, pls->plbufFile)) return;
|
||||
|
||||
pls->patt = patt;
|
||||
plP_state(PLSTATE_FILL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* rdbuf_esc()
|
||||
*
|
||||
* Escape function.
|
||||
* Must fill data structure with whatever data that was written,
|
||||
* then call escape function.
|
||||
*
|
||||
* Note: it is best to only call the escape function for op-codes that
|
||||
* are known to be supported.
|
||||
*
|
||||
* Functions:
|
||||
*
|
||||
* PLESC_FILL Fill polygon
|
||||
* PLESC_SWIN Set plot window parameters
|
||||
* PLESC_IMAGE Draw image
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
rdbuf_image(PLStream *pls);
|
||||
|
||||
static void
|
||||
rdbuf_esc(PLStream *pls)
|
||||
{
|
||||
U_CHAR op;
|
||||
|
||||
dbug_enter("rdbuf_esc");
|
||||
|
||||
if (1 != fread(&op, sizeof(U_CHAR), 1, pls->plbufFile)) return;
|
||||
|
||||
switch (op) {
|
||||
case PLESC_FILL:
|
||||
rdbuf_fill(pls);
|
||||
break;
|
||||
case PLESC_SWIN:
|
||||
rdbuf_swin(pls);
|
||||
break;
|
||||
case PLESC_IMAGE:
|
||||
rdbuf_image(pls);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* rdbuf_fill()
|
||||
*
|
||||
* Fill polygon described by input points.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
rdbuf_fill(PLStream *pls)
|
||||
{
|
||||
short xpl[PL_MAXPOLY], ypl[PL_MAXPOLY];
|
||||
PLINT npts;
|
||||
|
||||
dbug_enter("rdbuf_fill");
|
||||
|
||||
if (1 != fread(&npts, sizeof(PLINT), 1, pls->plbufFile)) return;
|
||||
if (npts != fread(xpl, sizeof(short), npts, pls->plbufFile)) return;
|
||||
if (npts != fread(ypl, sizeof(short), npts, pls->plbufFile)) return;
|
||||
|
||||
plP_fill(xpl, ypl, npts);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* rdbuf_image()
|
||||
*
|
||||
* .
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
rdbuf_image(PLStream *pls)
|
||||
{
|
||||
short *dev_ix, *dev_iy;
|
||||
unsigned short *dev_z, dev_zmin, dev_zmax;
|
||||
PLINT nptsX,nptsY, npts;
|
||||
PLFLT xmin, ymin, dx, dy;
|
||||
|
||||
dbug_enter("rdbuf_image");
|
||||
|
||||
if (1 != fread(&nptsX, sizeof(PLINT), 1, pls->plbufFile)) return;
|
||||
if (1 != fread(&nptsY, sizeof(PLINT), 1, pls->plbufFile)) return;
|
||||
npts = nptsX*nptsY;
|
||||
|
||||
if (1 != fread(&xmin, sizeof(PLFLT), 1, pls->plbufFile)) return;
|
||||
if (1 != fread(&ymin, sizeof(PLFLT), 1, pls->plbufFile)) return;
|
||||
if (1 != fread(&dx, sizeof(PLFLT), 1, pls->plbufFile)) return;
|
||||
if (1 != fread(&dy, sizeof(PLFLT), 1, pls->plbufFile)) return;
|
||||
|
||||
if (1 != fread(&dev_zmin, sizeof(short), 1, pls->plbufFile)) return;
|
||||
if (1 != fread(&dev_zmax, sizeof(short), 1, pls->plbufFile)) return;
|
||||
|
||||
dev_ix=(short *)malloc(npts*sizeof(short));
|
||||
if (!dev_ix) return;
|
||||
dev_iy=(short *)malloc(npts*sizeof(short));
|
||||
if (!dev_iy) goto end_y;
|
||||
dev_z=(unsigned short *)malloc((nptsX-1)*(nptsY-1)*sizeof(unsigned short));
|
||||
if (!dev_z) goto end_z;
|
||||
|
||||
if (npts != fread(dev_ix, sizeof(short), npts, pls->plbufFile)) goto end;
|
||||
if (npts != fread(dev_iy, sizeof(short), npts, pls->plbufFile)) goto end;
|
||||
if ((nptsX-1)*(nptsY-1) != fread(dev_z, sizeof(unsigned short), (nptsX-1)*(nptsY-1), pls->plbufFile)) goto end;
|
||||
|
||||
plP_image(dev_ix, dev_iy, dev_z, nptsX, nptsY, xmin, ymin, dx, dy, dev_zmin, dev_zmax);
|
||||
|
||||
end:
|
||||
free(dev_z);
|
||||
end_z:
|
||||
free(dev_iy);
|
||||
end_y:
|
||||
free(dev_ix);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* rdbuf_swin()
|
||||
*
|
||||
* Set up plot window parameters.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
rdbuf_swin(PLStream *pls)
|
||||
{
|
||||
PLWindow plwin;
|
||||
|
||||
if (1 != fread(&plwin.dxmi, sizeof(PLFLT), 1, pls->plbufFile)) return;
|
||||
if (1 != fread(&plwin.dxma, sizeof(PLFLT), 1, pls->plbufFile)) return;
|
||||
if (1 != fread(&plwin.dymi, sizeof(PLFLT), 1, pls->plbufFile)) return;
|
||||
if (1 != fread(&plwin.dyma, sizeof(PLFLT), 1, pls->plbufFile)) return;
|
||||
|
||||
if (1 != fread(&plwin.wxmi, sizeof(PLFLT), 1, pls->plbufFile)) return;
|
||||
if (1 != fread(&plwin.wxma, sizeof(PLFLT), 1, pls->plbufFile)) return;
|
||||
if (1 != fread(&plwin.wymi, sizeof(PLFLT), 1, pls->plbufFile)) return;
|
||||
if (1 != fread(&plwin.wyma, sizeof(PLFLT), 1, pls->plbufFile)) return;
|
||||
|
||||
plP_swin(&plwin);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plRemakePlot()
|
||||
*
|
||||
* Rebuilds plot from plot buffer, usually in response to a window
|
||||
* resize or exposure event.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plRemakePlot(PLStream *pls)
|
||||
{
|
||||
U_CHAR c;
|
||||
int plbuf_status;
|
||||
|
||||
dbug_enter("plRemakePlot");
|
||||
|
||||
if (pls->plbufFile == NULL)
|
||||
return;
|
||||
|
||||
rewind(pls->plbufFile);
|
||||
|
||||
plbuf_status = pls->plbuf_write;
|
||||
pls->plbuf_write = FALSE;
|
||||
pls->plbuf_read = TRUE;
|
||||
while (rd_command(pls, &c)) {
|
||||
plbuf_control(pls, c);
|
||||
}
|
||||
|
||||
pls->plbuf_read = FALSE;
|
||||
pls->plbuf_write = plbuf_status;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plbuf_control()
|
||||
*
|
||||
* Processes commands read from the plot buffer.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
plbuf_control(PLStream *pls, U_CHAR c)
|
||||
{
|
||||
static U_CHAR c_old = 0;
|
||||
|
||||
dbug_enter("plbuf_control");
|
||||
|
||||
switch ((int) c) {
|
||||
|
||||
case INITIALIZE:
|
||||
rdbuf_init(pls);
|
||||
break;
|
||||
|
||||
case EOP:
|
||||
rdbuf_eop(pls);
|
||||
break;
|
||||
|
||||
case BOP:
|
||||
rdbuf_bop(pls);
|
||||
break;
|
||||
|
||||
case CHANGE_STATE:
|
||||
rdbuf_state(pls);
|
||||
break;
|
||||
|
||||
case LINE:
|
||||
rdbuf_line(pls);
|
||||
break;
|
||||
|
||||
case POLYLINE:
|
||||
rdbuf_polyline(pls);
|
||||
break;
|
||||
|
||||
case ESCAPE:
|
||||
rdbuf_esc(pls);
|
||||
break;
|
||||
|
||||
default:
|
||||
pldebug("plbuf_control", "Unrecognized command %d, previous %d\n", c, c_old);
|
||||
}
|
||||
c_old = c;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* rd_command()
|
||||
*
|
||||
* Read & return the next command
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static int
|
||||
rd_command(PLStream *pls, U_CHAR *p_c)
|
||||
{
|
||||
int count;
|
||||
|
||||
count = fread(p_c, sizeof(U_CHAR), 1, pls->plbufFile);
|
||||
return (count);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* wr_command()
|
||||
*
|
||||
* Write the next command
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static int
|
||||
wr_command(PLStream *pls, U_CHAR c)
|
||||
{
|
||||
U_CHAR c1 = c;
|
||||
int count;
|
||||
|
||||
count = fwrite(&c1, sizeof(U_CHAR), 1, pls->plbufFile);
|
||||
return (count);
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
/* $Id: plcdemos.h,v 1.1 2004/03/01 20:54:51 cozmic Exp $
|
||||
|
||||
Everything needed by the C demo programs.
|
||||
Created to avoid junking up plplot.h with this stuff.
|
||||
*/
|
||||
|
||||
#ifndef __PLCDEMOS_H__
|
||||
#define __PLCDEMOS_H__
|
||||
|
||||
#include "plConfig.h"
|
||||
#include "plplot.h"
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/* define PI if not defined by math.h */
|
||||
|
||||
#ifndef PI
|
||||
#define PI 3.1415926535897932384
|
||||
#endif
|
||||
|
||||
/* various utility macros */
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef ROUND
|
||||
#define ROUND(a) (PLINT)((a)<0. ? ((a)-.5) : ((a)+.5))
|
||||
#endif
|
||||
|
||||
#endif /* __PLCDEMOS_H__ */
|
|
@ -1,253 +0,0 @@
|
|||
/* $Id: plcore.h,v 1.1 2004/03/01 20:54:51 cozmic Exp $
|
||||
|
||||
Contains declarations for core plplot data structures. This file
|
||||
should be included only by plcore.c.
|
||||
*/
|
||||
|
||||
#ifndef __PLCORE_H__
|
||||
#define __PLCORE_H__
|
||||
|
||||
#include "plplotP.h"
|
||||
#include "drivers.h"
|
||||
#include "plDevs.h"
|
||||
#include "disptab.h"
|
||||
|
||||
#ifdef ENABLE_DYNDRIVERS
|
||||
#include <ltdl.h>
|
||||
typedef lt_ptr (*PLDispatchInit)( PLDispatchTable *pdt );
|
||||
#else
|
||||
typedef void (*PLDispatchInit)( PLDispatchTable *pdt );
|
||||
#endif
|
||||
|
||||
/* Static function prototypes */
|
||||
|
||||
static void grline (short *, short *, PLINT);
|
||||
static void grpolyline (short *, short *, PLINT);
|
||||
static void grfill (short *, short *, PLINT);
|
||||
static void plSelectDev (void);
|
||||
static void pldi_ini (void);
|
||||
static void calc_diplt (void);
|
||||
static void calc_didev (void);
|
||||
static void calc_diori (void);
|
||||
static void calc_dimap (void);
|
||||
static void plgdevlst (char **, char **, int *, int);
|
||||
|
||||
static void plInitDispatchTable (void);
|
||||
|
||||
static void plLoadDriver (void);
|
||||
|
||||
/* Static variables */
|
||||
|
||||
static PLINT xscl[PL_MAXPOLY], yscl[PL_MAXPOLY];
|
||||
|
||||
static PLINT initfont = 1; /* initial font: extended by default */
|
||||
|
||||
static PLINT lib_initialized = 0;
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Allocate a PLStream data structure (defined in plstrm.h).
|
||||
*
|
||||
* This struct contains a copy of every variable that is stream dependent.
|
||||
* Only the first [index=0] stream is statically allocated; the rest
|
||||
* are dynamically allocated when you switch streams (yes, it is legal
|
||||
* to only initialize the first element of the array of pointers).
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static PLStream pls0; /* preallocated stream */
|
||||
static PLINT ipls; /* current stream number */
|
||||
|
||||
static PLStream *pls[PL_NSTREAMS] = {&pls0}; /* Array of stream pointers */
|
||||
|
||||
/* Current stream pointer. Global, for easier access to state info */
|
||||
|
||||
PLStream *plsc = &pls0;
|
||||
|
||||
/* Only now can we include this */
|
||||
|
||||
#include "pldebug.h"
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Initialize dispatch table.
|
||||
*
|
||||
* Each device is selected by the appropriate define, passed in from the
|
||||
* makefile. When installing plplot you may wish to exclude devices not
|
||||
* present on your system in order to reduce screen clutter.
|
||||
*
|
||||
* If you hit a <CR> in response to the plinit() prompt, you get the FIRST
|
||||
* one active below, so arrange them accordingly for your system (i.e. all
|
||||
* the system-specific ones should go first, since they won't appear on
|
||||
* most systems.)
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static PLDispatchTable **dispatch_table = 0;
|
||||
static int npldrivers = 0;
|
||||
|
||||
static PLDispatchInit static_device_initializers[] = {
|
||||
#ifdef PLD_mac
|
||||
plD_dispatch_init_mac8,
|
||||
plD_dispatch_init_mac1,
|
||||
#endif
|
||||
#ifdef PLD_next
|
||||
plD_dispatch_init_nx,
|
||||
#endif
|
||||
#ifdef PLD_os2pm
|
||||
plD_dispatch_init_os2,
|
||||
#endif
|
||||
#if defined(PLD_xwin) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_xw,
|
||||
#endif
|
||||
#if defined(PLD_gnome) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_gnome,
|
||||
#endif
|
||||
#if defined(PLD_tk) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_tk,
|
||||
#endif
|
||||
#if defined(PLD_linuxvga) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_vga,
|
||||
#endif
|
||||
#ifdef PLD_mgr
|
||||
plD_dispatch_init_mgr,
|
||||
#endif
|
||||
#ifdef PLD_win3
|
||||
plD_dispatch_init_win3,
|
||||
#endif
|
||||
#if defined (_MSC_VER) && defined (VGA) /* graphics for msc */
|
||||
plD_dispatch_init_vga,
|
||||
#endif
|
||||
#ifdef PLD_bgi
|
||||
plD_dispatch_init_vga,
|
||||
#endif
|
||||
#ifdef PLD_gnusvga
|
||||
plD_dispatch_init_vga,
|
||||
#endif
|
||||
#ifdef PLD_tiff
|
||||
plD_dispatch_init_tiff,
|
||||
#endif
|
||||
#if defined(PLD_jpg)
|
||||
plD_dispatch_init_jpg,
|
||||
#endif
|
||||
#if defined(PLD_bmp) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_bmp,
|
||||
#endif
|
||||
#ifdef PLD_emxvga /* graphics for emx+gcc */
|
||||
plD_dispatch_init_vga,
|
||||
#endif
|
||||
#if defined(PLD_xterm) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_xterm,
|
||||
#endif
|
||||
#if defined(PLD_tek4010) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_tekt,
|
||||
#endif
|
||||
#if defined(PLD_tek4107) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_tek4107t,
|
||||
#endif
|
||||
#if defined(PLD_mskermit) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_mskermit,
|
||||
#endif
|
||||
#if defined(PLD_versaterm) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_versaterm,
|
||||
#endif
|
||||
#if defined(PLD_vlt) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_vlt,
|
||||
#endif
|
||||
#if defined(PLD_conex) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_conex,
|
||||
#endif
|
||||
#if defined(PLD_dg300) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_dg,
|
||||
#endif
|
||||
#if defined(PLD_plmeta) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_plm,
|
||||
#endif
|
||||
#if defined(PLD_tek4010f) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_tekf,
|
||||
#endif
|
||||
#if defined(PLD_tek4107f) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_tek4107f,
|
||||
#endif
|
||||
#if defined(PLD_ps) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_psm,
|
||||
plD_dispatch_init_psc,
|
||||
#endif
|
||||
#if defined(PLD_xfig) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_xfig,
|
||||
#endif
|
||||
#if defined(PLD_ljiip) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_ljiip,
|
||||
#endif
|
||||
#if defined(PLD_ljii) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_ljii,
|
||||
#endif
|
||||
#if defined( PLD_hp7470) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_hp7470,
|
||||
#endif
|
||||
#if defined( PLD_hp7580) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_hp7580,
|
||||
#endif
|
||||
#if defined( PLD_lj_hpgl) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_hpgl,
|
||||
#endif
|
||||
#if defined( PLD_imp) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_imp,
|
||||
#endif
|
||||
#if defined( PLD_pbm) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_pbm,
|
||||
#endif
|
||||
#if defined(PLD_png) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_png,
|
||||
#endif
|
||||
#if defined(PLD_jpeg) && !defined(ENABLE_DYNDRIVERS)
|
||||
//plD_dispatch_init_jpeg,
|
||||
#endif
|
||||
#if defined(PLD_pstex) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_pstex,
|
||||
#endif
|
||||
#if defined(PLD_ntk) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_ntk,
|
||||
#endif
|
||||
#if defined(PLD_cgm) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_cgm,
|
||||
#endif
|
||||
#if defined(PLD_mem) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_mem,
|
||||
#endif
|
||||
#if defined(PLD_null) && !defined(ENABLE_DYNDRIVERS)
|
||||
//plD_dispatch_init_null,
|
||||
#endif
|
||||
#if defined(PLD_tkwin) && !defined(ENABLE_DYNDRIVERS)
|
||||
plD_dispatch_init_tkwin,
|
||||
#endif
|
||||
plD_dispatch_init_dc,
|
||||
NULL
|
||||
};
|
||||
|
||||
static int nplstaticdevices = ( sizeof(static_device_initializers) /
|
||||
sizeof(PLDispatchInit) ) - 1;
|
||||
static int npldynamicdevices = 0;
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Stuff to support the loadable device drivers.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef ENABLE_DYNDRIVERS
|
||||
typedef struct {
|
||||
char *devnam;
|
||||
char *description;
|
||||
char *drvnam;
|
||||
char *tag;
|
||||
int drvidx;
|
||||
} PLLoadableDevice;
|
||||
|
||||
typedef struct {
|
||||
char *drvnam;
|
||||
lt_dlhandle dlhand;
|
||||
|
||||
} PLLoadableDriver;
|
||||
|
||||
static PLLoadableDevice *loadable_device_list;
|
||||
static PLLoadableDriver *loadable_driver_list;
|
||||
#endif
|
||||
|
||||
static UNUSED int nloadabledrivers = 0;
|
||||
|
||||
#endif /* __PLCORE_H__ */
|
|
@ -1,205 +0,0 @@
|
|||
/* $Id: plcvt.c,v 1.1 2004/03/01 20:54:51 cozmic Exp $
|
||||
|
||||
Coordinate transformation routines.
|
||||
*/
|
||||
|
||||
#include "plplotP.h"
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Transformations returning physical coordinates.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
/* device coords to physical coords (x) */
|
||||
|
||||
PLINT
|
||||
plP_dcpcx(PLFLT x)
|
||||
{
|
||||
return (ROUND(plsc->phyxmi + plsc->phyxlen * x));
|
||||
}
|
||||
|
||||
/* device coords to physical coords (y) */
|
||||
|
||||
PLINT
|
||||
plP_dcpcy(PLFLT y)
|
||||
{
|
||||
return (ROUND(plsc->phyymi + plsc->phyylen * y));
|
||||
}
|
||||
|
||||
/* millimeters from bottom left-hand corner to physical coords (x) */
|
||||
|
||||
PLINT
|
||||
plP_mmpcx(PLFLT x)
|
||||
{
|
||||
return (ROUND(plsc->phyxmi + plsc->xpmm * x));
|
||||
}
|
||||
|
||||
/* millimeters from bottom left-hand corner to physical coords (y) */
|
||||
|
||||
PLINT
|
||||
plP_mmpcy(PLFLT y)
|
||||
{
|
||||
return (ROUND(plsc->phyymi + plsc->ypmm * y));
|
||||
}
|
||||
|
||||
/* world coords to physical coords (x) */
|
||||
|
||||
PLINT
|
||||
plP_wcpcx(PLFLT x)
|
||||
{
|
||||
return (ROUND(plsc->wpxoff + plsc->wpxscl * x));
|
||||
}
|
||||
|
||||
/* world coords to physical coords (y) */
|
||||
|
||||
PLINT
|
||||
plP_wcpcy(PLFLT y)
|
||||
{
|
||||
return (ROUND(plsc->wpyoff + plsc->wpyscl * y));
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Transformations returning device coordinates.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
/* physical coords to device coords (x) */
|
||||
|
||||
PLFLT
|
||||
plP_pcdcx(PLINT x)
|
||||
{
|
||||
return (PLFLT) ((x - plsc->phyxmi) / (double) plsc->phyxlen);
|
||||
}
|
||||
|
||||
/* physical coords to device coords (y) */
|
||||
|
||||
PLFLT
|
||||
plP_pcdcy(PLINT y)
|
||||
{
|
||||
return (PLFLT) ((y - plsc->phyymi) / (double) plsc->phyylen);
|
||||
}
|
||||
|
||||
/* millimeters from bottom left corner to device coords (x) */
|
||||
|
||||
PLFLT
|
||||
plP_mmdcx(PLFLT x)
|
||||
{
|
||||
return ((PLFLT) (x * plsc->xpmm / ABS(plsc->phyxma - plsc->phyxmi)));
|
||||
}
|
||||
|
||||
/* millimeters from bottom left corner to device coords (y) */
|
||||
|
||||
PLFLT
|
||||
plP_mmdcy(PLFLT y)
|
||||
{
|
||||
return ((PLFLT) (y * plsc->ypmm / ABS(plsc->phyyma - plsc->phyymi)));
|
||||
}
|
||||
|
||||
/* world coords into device coords (x) */
|
||||
|
||||
PLFLT
|
||||
plP_wcdcx(PLFLT x)
|
||||
{
|
||||
return ((PLFLT) (plsc->wdxoff + plsc->wdxscl * x));
|
||||
}
|
||||
|
||||
/* world coords into device coords (y) */
|
||||
|
||||
PLFLT
|
||||
plP_wcdcy(PLFLT y)
|
||||
{
|
||||
return ((PLFLT) (plsc->wdyoff + plsc->wdyscl * y));
|
||||
}
|
||||
|
||||
/* subpage coords to device coords (x) */
|
||||
|
||||
PLFLT
|
||||
plP_scdcx(PLFLT x)
|
||||
{
|
||||
return ((PLFLT) (plsc->spdxmi + (plsc->spdxma - plsc->spdxmi) * x));
|
||||
}
|
||||
|
||||
/* subpage coords to device coords (y) */
|
||||
|
||||
PLFLT
|
||||
plP_scdcy(PLFLT y)
|
||||
{
|
||||
return ((PLFLT) (plsc->spdymi + (plsc->spdyma - plsc->spdymi) * y));
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Transformations returning millimeters.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
/* device coords to millimeters from bottom left-hand corner (x) */
|
||||
|
||||
PLFLT
|
||||
plP_dcmmx(PLFLT x)
|
||||
{
|
||||
return ((PLFLT) (x * ABS(plsc->phyxma - plsc->phyxmi) / plsc->xpmm));
|
||||
}
|
||||
|
||||
/* device coords to millimeters from bottom left-hand corner (y) */
|
||||
|
||||
PLFLT
|
||||
plP_dcmmy(PLFLT y)
|
||||
{
|
||||
return ((PLFLT) (y * ABS(plsc->phyyma - plsc->phyymi) / plsc->ypmm));
|
||||
}
|
||||
|
||||
/* world coords into millimeters (x) */
|
||||
|
||||
PLFLT
|
||||
plP_wcmmx(PLFLT x)
|
||||
{
|
||||
return ((PLFLT) (plsc->wmxoff + plsc->wmxscl * x));
|
||||
}
|
||||
|
||||
/* world coords into millimeters (y) */
|
||||
|
||||
PLFLT
|
||||
plP_wcmmy(PLFLT y)
|
||||
{
|
||||
return ((PLFLT) (plsc->wmyoff + plsc->wmyscl * y));
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Transformations returning subpage coordinates.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
/* device coords to subpage coords (x) */
|
||||
|
||||
PLFLT
|
||||
plP_dcscx(PLFLT x)
|
||||
{
|
||||
return ((PLFLT) ((x - plsc->spdxmi) / (plsc->spdxma - plsc->spdxmi)));
|
||||
}
|
||||
|
||||
/* device coords to subpage coords (y) */
|
||||
|
||||
PLFLT
|
||||
plP_dcscy(PLFLT y)
|
||||
{
|
||||
return ((PLFLT) ((y - plsc->spdymi) / (plsc->spdyma - plsc->spdymi)));
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* 3-d plot transformations.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
/* 3-d coords to 2-d projection (x) */
|
||||
|
||||
PLFLT
|
||||
plP_w3wcx(PLFLT x, PLFLT y, PLFLT z)
|
||||
{
|
||||
return ((PLFLT) ((x - plsc->basecx) * plsc->cxx +
|
||||
(y - plsc->basecy) * plsc->cxy));
|
||||
}
|
||||
|
||||
/* 3-d coords to 2-d projection (y) */
|
||||
|
||||
PLFLT
|
||||
plP_w3wcy(PLFLT x, PLFLT y, PLFLT z)
|
||||
{
|
||||
return ((PLFLT) ((x - plsc->basecx) * plsc->cyx +
|
||||
(y - plsc->basecy) * plsc->cyy +
|
||||
(z - plsc->ranmi) * plsc->cyz));
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
/* $Id: pldebug.h,v 1.1 2004/03/01 20:54:51 cozmic Exp $
|
||||
|
||||
Copyright (C) 1995 by Maurice J. LeBrun
|
||||
|
||||
Debugging support for PLplot.
|
||||
|
||||
This software may be freely copied, modified and redistributed without
|
||||
fee provided that this copyright notice is preserved intact on all
|
||||
copies and modified copies.
|
||||
|
||||
There is no warranty or other guarantee of fitness of this software.
|
||||
It is provided solely "as is". The author(s) disclaim(s) all
|
||||
responsibility and liability with respect to this software's usage or
|
||||
its effect upon hardware or computer systems.
|
||||
*/
|
||||
|
||||
#ifndef __PLDEBUG_H__
|
||||
#define __PLDEBUG_H__
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
/* For the truly desperate debugging task */
|
||||
|
||||
#ifdef DEBUG_ENTER
|
||||
#define dbug_enter(a) \
|
||||
if (plsc->debug) \
|
||||
fprintf(stderr, " entered %s (%s, line %d)\n", a, __FILE__, __LINE__);
|
||||
|
||||
#else
|
||||
#define dbug_enter(a)
|
||||
#endif
|
||||
|
||||
/* If we're using a debugging malloc, include the header file here */
|
||||
|
||||
#ifdef DEBUGGING_MALLOC
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* pldebug()
|
||||
*
|
||||
* Included into every plplot source file to control debugging output. To
|
||||
* enable printing of debugging output, you must #define DEBUG before
|
||||
* including plplotP.h or specify -DDEBUG in the compile line, for each file
|
||||
* that you want to have debug output enabled. When running the program you
|
||||
* must in addition specify -debug. This allows debugging output to tailored
|
||||
* to many different circumstances but otherwise be fairly unobtrusive.
|
||||
*
|
||||
* Note, any file that actually uses pldebug() must also define NEED_PLDEBUG
|
||||
* before the plplotP.h include. This is to eliminate warnings caused by
|
||||
* those files in which this is defined but never referenced. All this could
|
||||
* be much nicer if CPP had the abilities of m4, sigh..
|
||||
*
|
||||
* Syntax:
|
||||
* pldebug(label, format [, arg1, arg2, ...] );
|
||||
*
|
||||
* The label is typically the calling function name.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define UNUSED __attribute__((unused))
|
||||
#else
|
||||
# define UNUSED
|
||||
#endif
|
||||
|
||||
#ifdef NEED_PLDEBUG
|
||||
UNUSED static void
|
||||
pldebug( const char *label, ... )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
va_list args;
|
||||
char *fmt;
|
||||
|
||||
if (plsc->debug) {
|
||||
if (plsc->termin)
|
||||
c_pltext();
|
||||
va_start(args, label);
|
||||
|
||||
/* print out identifying tag */
|
||||
|
||||
fprintf(stderr, "%s: ", label);
|
||||
|
||||
/* print out remainder of message */
|
||||
/* Need to get fmt BEFORE it's used in the vfprintf */
|
||||
|
||||
fmt = (char *) va_arg(args, char *);
|
||||
vfprintf(stderr, fmt, args);
|
||||
|
||||
va_end(args);
|
||||
if (plsc->termin)
|
||||
c_plgra();
|
||||
}
|
||||
#endif /* DEBUG */
|
||||
}
|
||||
#endif /* NEED_PLDEBUG */
|
||||
|
||||
#endif /* __PLDEBUG_H__ */
|
|
@ -1,209 +0,0 @@
|
|||
/* $Id: pldtik.c,v 1.1 2004/03/01 20:54:51 cozmic Exp $
|
||||
|
||||
Determines tick spacing and mode (fixed or floating) of
|
||||
numeric axis labels.
|
||||
*/
|
||||
|
||||
#include "plplotP.h"
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void pldtik()
|
||||
*
|
||||
* Determine tick spacing: works out a "nice" interval (if tick == 0) such
|
||||
* that there are between 3 and 7.5 major tick intervals in the input
|
||||
* range vmin to vmax. The recommended number of subticks is returned in
|
||||
* "nsubt" unless the routine is entered with a non-zero value of "nsubt".
|
||||
* n.b. big change: now returns only positive values of tick and nsubt
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
pldtik(PLFLT vmin, PLFLT vmax, PLFLT *tick, PLINT *nsubt)
|
||||
{
|
||||
PLFLT t1, t2, tick_reasonable;
|
||||
PLINT np, ns;
|
||||
|
||||
/* Magnitude of min/max difference to get tick spacing */
|
||||
|
||||
t1 = (PLFLT) log10(ABS(vmax - vmin));
|
||||
np = (PLINT) floor(t1);
|
||||
t1 = t1 - np;
|
||||
|
||||
/* Get tick spacing. */
|
||||
|
||||
if (t1 > 0.7781512503) {
|
||||
t2 = 2.0;
|
||||
ns = 4;
|
||||
}
|
||||
else if (t1 > 0.4771212549) {
|
||||
t2 = 1.0;
|
||||
ns = 5;
|
||||
}
|
||||
else if (t1 > 0.1760912591) {
|
||||
t2 = 5.0;
|
||||
ns = 5;
|
||||
np = np - 1;
|
||||
}
|
||||
else {
|
||||
t2 = 2.0;
|
||||
ns = 4;
|
||||
np = np - 1;
|
||||
}
|
||||
|
||||
/* Now compute reasonable tick spacing */
|
||||
|
||||
tick_reasonable = t2 * pow(10.0, (double) np);
|
||||
if (*tick == 0) {
|
||||
*tick = t2 * pow(10.0, (double) np);
|
||||
}
|
||||
else {
|
||||
*tick = ABS(*tick);
|
||||
if(*tick < 1.e-4*tick_reasonable) {
|
||||
plexit("pldtik: magnitude of specified tick spacing is much too small");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (*nsubt == 0)
|
||||
*nsubt = ns;
|
||||
|
||||
*nsubt = ABS(*nsubt);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void pldprec()
|
||||
*
|
||||
* Determine precision: the output variable "mode" is set to 0 if labels
|
||||
* are to be written in floating-point format, or to 1 if they are to be
|
||||
* written in scientific format. For mode = 1, the exponent will be
|
||||
* placed at:
|
||||
*
|
||||
* top left for vertical axis on left
|
||||
* top right for vertical axis on right
|
||||
* bottom right for horizontal axis
|
||||
*
|
||||
* The digmax flag can be set by the user, and represents the maximum
|
||||
* number of digits a label may occupy including sign and decimal point.
|
||||
* digmin, calculated internally, is the maximum number of digits
|
||||
* labels at vmin and vmax would occupy if floating point.
|
||||
* If digmax<0, it is disregarded,
|
||||
* and if digmax=0 the default value is used. For digmax>0, mode=1 is
|
||||
* chosen if there is insufficient room for the label within the specified
|
||||
* # of digits (digmin > digfix, where digfix is determined from digmax with
|
||||
* fuzz factors).
|
||||
*
|
||||
* In the case of mode=0, the actual # of digits will become too large
|
||||
* when the magnitude of the labels become too large. The mode=1 case
|
||||
* offers the greatest precision for the smallest field length.
|
||||
*
|
||||
* The determination of maximum length for fixed point quantities is
|
||||
* complicated by the fact that very long fixed point representations look
|
||||
* much worse than the same sized floating point representation. Further,
|
||||
* a fixed point number with a large negative exponent will actually gain
|
||||
* in precision when written as floating point. Thus we use certain fuzz
|
||||
* factors to get 'digfix' from 'digmax', however it will always be true
|
||||
* that digfix<=digmax.
|
||||
*
|
||||
* Finally, if 'digmax' is set, 'prec' is reduced in size if necessary so
|
||||
* that the labels fit the requested field length, where prec is the number of
|
||||
* places after the decimal place.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
#define MIN_FLTDIG 3 /* disregarded if fractional part is 0 */
|
||||
#define MAX_FIXDIG_POS 6
|
||||
#define MAX_FIXDIG_NEG 4
|
||||
#define DIGMAX_DEF 5
|
||||
|
||||
void
|
||||
pldprec(PLFLT vmin, PLFLT vmax, PLFLT tick, PLINT lf,
|
||||
PLINT *mode, PLINT *prec, PLINT digmax, PLINT *scale)
|
||||
{
|
||||
PLFLT chosen, notchosen, vmod, t0;
|
||||
PLINT msd, notmsd, np, digmin, digfix;
|
||||
|
||||
*mode = 0;
|
||||
*scale = 0;
|
||||
|
||||
if (digmax == 0)
|
||||
digmax = DIGMAX_DEF;
|
||||
|
||||
/* Choose vmin or vmax depending on magnitudes of vmin and vmax. */
|
||||
chosen = (ABS(vmax) >= ABS(vmin))? vmax: vmin;
|
||||
notchosen = (ABS(vmax) >= ABS(vmin))? vmin: vmax;
|
||||
/* Magnitute of chosen to get number of significant digits */
|
||||
|
||||
if(ABS(chosen) > 0.) {
|
||||
vmod = ABS(chosen);
|
||||
t0 = (PLFLT) log10(vmod);
|
||||
msd = (PLINT) floor(t0);
|
||||
}
|
||||
else {
|
||||
/* this branch occurs only when 0. --- 0. range put in */
|
||||
vmod = 1.;
|
||||
t0 = (PLFLT) log10(vmod);
|
||||
msd = (PLINT) floor(t0);
|
||||
}
|
||||
|
||||
if(ABS(notchosen) > 0.)
|
||||
notmsd = (PLINT) floor( (PLFLT) log10(ABS(notchosen)));
|
||||
else
|
||||
notmsd = msd;
|
||||
/* Autoselect the mode flag */
|
||||
/* 'digmin' is the minimum number of places taken up by the label */
|
||||
|
||||
if (msd >= 0) {
|
||||
/* n.b. no decimal point in the minimal case */
|
||||
digmin = msd + 1;
|
||||
digfix = MAX_FIXDIG_POS;
|
||||
if (digmax > 0)
|
||||
digfix = MIN(digmax, MAX_FIXDIG_POS);
|
||||
}
|
||||
else {
|
||||
/* adjust digmin to account for leading 0 and decimal point */
|
||||
digmin = -msd + 2;
|
||||
digfix = MAX_FIXDIG_NEG;
|
||||
if (digmax > 0)
|
||||
digfix = MIN(digmax, MAX_FIXDIG_NEG);
|
||||
}
|
||||
/* adjust digmin to account for sign on the chosen end of axis or sign on the
|
||||
* nonchosen end of axis if notmsd = msd or (msd <= 0 and notmsd < 0)
|
||||
* For the latter case the notchosen label starts with "-0."
|
||||
* For checking for the latter case, the notmsd < 0 condition is redundant
|
||||
* since notmsd <= msd always and the equal part is selected by the first
|
||||
* condition.
|
||||
*/
|
||||
if(chosen < 0.||(notchosen < 0. && (notmsd == msd || msd <= 0)))
|
||||
digmin = digmin + 1;
|
||||
|
||||
if (digmin > digfix && !lf) {
|
||||
*mode = 1;
|
||||
*scale = msd;
|
||||
}
|
||||
|
||||
/* Establish precision. */
|
||||
/* It must be fine enough to resolve the tick spacing */
|
||||
|
||||
np = (PLINT) floor(log10(ABS(tick)));
|
||||
|
||||
if (*mode != 0)
|
||||
*prec = msd - np;
|
||||
else
|
||||
*prec = MAX(-np, 0);
|
||||
|
||||
/* One last hack required: if exponent < 0, i.e. number has leading '0.',
|
||||
* it's better to change to floating point form if the number of digits
|
||||
* is insufficient to represent the tick spacing.
|
||||
*/
|
||||
if (*mode == 0 && digmax > 0 && !lf) {
|
||||
if (t0 < 0.0) {
|
||||
if (digmax - 2 - *prec < 0) {
|
||||
*mode = 1;
|
||||
*scale = msd;
|
||||
}
|
||||
}
|
||||
else
|
||||
*prec = MAX(MIN(*prec, digmax - msd - 1), 0);
|
||||
}
|
||||
if (*mode != 0) {
|
||||
*prec = msd - np;
|
||||
*prec = MAX(MIN(*prec, MAX(digmax-1, MIN_FLTDIG)), 0);
|
||||
}
|
||||
}
|
|
@ -1,205 +0,0 @@
|
|||
/* $Id: plevent.h,v 1.1 2004/03/01 20:54:51 cozmic Exp $
|
||||
|
||||
Input event (especially keyboard) definitions for use from plplot
|
||||
event handlers.
|
||||
|
||||
Key definitions are taken from the X11/keysymdef.h include file, with
|
||||
some changes:
|
||||
- only the control keys are retained
|
||||
- the XK prefix has been changed to PLK
|
||||
- control keys with ASCII equivalents use the ASCII code
|
||||
|
||||
By using the ASCII equivalent (if it exists) for all control keys, it
|
||||
is easier to handle keyboard input from any device which is ASCII based.
|
||||
Devices which use some other kind of key encoding must translate the raw
|
||||
keycodes to those used here.
|
||||
*/
|
||||
|
||||
#ifndef __PLEVENT_H__
|
||||
#define __PLEVENT_H__
|
||||
|
||||
/* Key definitions */
|
||||
|
||||
/***********************************************************
|
||||
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
|
||||
and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
|
||||
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee is hereby granted,
|
||||
provided that the above copyright notice appear in all copies and that
|
||||
both that copyright notice and this permission notice appear in
|
||||
supporting documentation, and that the names of Digital or MIT not be
|
||||
used in advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
||||
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
SOFTWARE.
|
||||
|
||||
******************************************************************/
|
||||
|
||||
/* Miscellaneous control keys, those with ASCII equivalents */
|
||||
|
||||
#define PLK_BackSpace 0x08 /* back space, back char */
|
||||
#define PLK_Tab 0x09
|
||||
#define PLK_Linefeed 0x0A /* Linefeed, LF */
|
||||
#define PLK_Return 0x0D /* Return, enter */
|
||||
#define PLK_Escape 0x1B
|
||||
#define PLK_Delete 0xFF /* Delete, rubout */
|
||||
|
||||
/* Those without ASCII equivalents */
|
||||
|
||||
#define PLK_Clear 0xFF0B
|
||||
#define PLK_Pause 0xFF13 /* Pause, hold */
|
||||
#define PLK_Scroll_Lock 0xFF14
|
||||
|
||||
/* Cursor control & motion */
|
||||
|
||||
#define PLK_Home 0xFF50
|
||||
#define PLK_Left 0xFF51 /* Move left, left arrow */
|
||||
#define PLK_Up 0xFF52 /* Move up, up arrow */
|
||||
#define PLK_Right 0xFF53 /* Move right, right arrow */
|
||||
#define PLK_Down 0xFF54 /* Move down, down arrow */
|
||||
#define PLK_Prior 0xFF55 /* Prior, previous (Page Up) */
|
||||
#define PLK_Next 0xFF56 /* Next (Page Down) */
|
||||
#define PLK_End 0xFF57 /* EOL */
|
||||
#define PLK_Begin 0xFF58 /* BOL */
|
||||
|
||||
/* Misc Functions */
|
||||
|
||||
#define PLK_Select 0xFF60 /* Select, mark */
|
||||
#define PLK_Print 0xFF61
|
||||
#define PLK_Execute 0xFF62 /* Execute, run, do */
|
||||
#define PLK_Insert 0xFF63 /* Insert, insert here */
|
||||
#define PLK_Undo 0xFF65 /* Undo, oops */
|
||||
#define PLK_Redo 0xFF66 /* redo, again */
|
||||
#define PLK_Menu 0xFF67
|
||||
#define PLK_Find 0xFF68 /* Find, search */
|
||||
#define PLK_Cancel 0xFF69 /* Cancel, stop, abort, exit */
|
||||
#define PLK_Help 0xFF6A /* Help, ? */
|
||||
#define PLK_Break 0xFF6B
|
||||
#define PLK_Mode_switch 0xFF7E /* Character set switch */
|
||||
#define PLK_script_switch 0xFF7E /* Alias for mode_switch */
|
||||
#define PLK_Num_Lock 0xFF7F
|
||||
|
||||
/* Keypad Functions, keypad numbers cleverly chosen to map to ascii */
|
||||
|
||||
#define PLK_KP_Space 0xFF80 /* space */
|
||||
#define PLK_KP_Tab 0xFF89
|
||||
#define PLK_KP_Enter 0xFF8D /* enter */
|
||||
#define PLK_KP_F1 0xFF91 /* PF1, KP_A, ... */
|
||||
#define PLK_KP_F2 0xFF92
|
||||
#define PLK_KP_F3 0xFF93
|
||||
#define PLK_KP_F4 0xFF94
|
||||
#define PLK_KP_Equal 0xFFBD /* equals */
|
||||
#define PLK_KP_Multiply 0xFFAA
|
||||
#define PLK_KP_Add 0xFFAB
|
||||
#define PLK_KP_Separator 0xFFAC /* separator, often comma */
|
||||
#define PLK_KP_Subtract 0xFFAD
|
||||
#define PLK_KP_Decimal 0xFFAE
|
||||
#define PLK_KP_Divide 0xFFAF
|
||||
|
||||
#define PLK_KP_0 0xFFB0
|
||||
#define PLK_KP_1 0xFFB1
|
||||
#define PLK_KP_2 0xFFB2
|
||||
#define PLK_KP_3 0xFFB3
|
||||
#define PLK_KP_4 0xFFB4
|
||||
#define PLK_KP_5 0xFFB5
|
||||
#define PLK_KP_6 0xFFB6
|
||||
#define PLK_KP_7 0xFFB7
|
||||
#define PLK_KP_8 0xFFB8
|
||||
#define PLK_KP_9 0xFFB9
|
||||
|
||||
/*
|
||||
* Auxilliary Functions; note the duplicate definitions for left and right
|
||||
* function keys; Sun keyboards and a few other manufactures have such
|
||||
* function key groups on the left and/or right sides of the keyboard.
|
||||
* We've not found a keyboard with more than 35 function keys total.
|
||||
*/
|
||||
|
||||
#define PLK_F1 0xFFBE
|
||||
#define PLK_F2 0xFFBF
|
||||
#define PLK_F3 0xFFC0
|
||||
#define PLK_F4 0xFFC1
|
||||
#define PLK_F5 0xFFC2
|
||||
#define PLK_F6 0xFFC3
|
||||
#define PLK_F7 0xFFC4
|
||||
#define PLK_F8 0xFFC5
|
||||
#define PLK_F9 0xFFC6
|
||||
#define PLK_F10 0xFFC7
|
||||
#define PLK_F11 0xFFC8
|
||||
#define PLK_L1 0xFFC8
|
||||
#define PLK_F12 0xFFC9
|
||||
#define PLK_L2 0xFFC9
|
||||
#define PLK_F13 0xFFCA
|
||||
#define PLK_L3 0xFFCA
|
||||
#define PLK_F14 0xFFCB
|
||||
#define PLK_L4 0xFFCB
|
||||
#define PLK_F15 0xFFCC
|
||||
#define PLK_L5 0xFFCC
|
||||
#define PLK_F16 0xFFCD
|
||||
#define PLK_L6 0xFFCD
|
||||
#define PLK_F17 0xFFCE
|
||||
#define PLK_L7 0xFFCE
|
||||
#define PLK_F18 0xFFCF
|
||||
#define PLK_L8 0xFFCF
|
||||
#define PLK_F19 0xFFD0
|
||||
#define PLK_L9 0xFFD0
|
||||
#define PLK_F20 0xFFD1
|
||||
#define PLK_L10 0xFFD1
|
||||
#define PLK_F21 0xFFD2
|
||||
#define PLK_R1 0xFFD2
|
||||
#define PLK_F22 0xFFD3
|
||||
#define PLK_R2 0xFFD3
|
||||
#define PLK_F23 0xFFD4
|
||||
#define PLK_R3 0xFFD4
|
||||
#define PLK_F24 0xFFD5
|
||||
#define PLK_R4 0xFFD5
|
||||
#define PLK_F25 0xFFD6
|
||||
#define PLK_R5 0xFFD6
|
||||
#define PLK_F26 0xFFD7
|
||||
#define PLK_R6 0xFFD7
|
||||
#define PLK_F27 0xFFD8
|
||||
#define PLK_R7 0xFFD8
|
||||
#define PLK_F28 0xFFD9
|
||||
#define PLK_R8 0xFFD9
|
||||
#define PLK_F29 0xFFDA
|
||||
#define PLK_R9 0xFFDA
|
||||
#define PLK_F30 0xFFDB
|
||||
#define PLK_R10 0xFFDB
|
||||
#define PLK_F31 0xFFDC
|
||||
#define PLK_R11 0xFFDC
|
||||
#define PLK_F32 0xFFDD
|
||||
#define PLK_R12 0xFFDD
|
||||
#define PLK_R13 0xFFDE
|
||||
#define PLK_F33 0xFFDE
|
||||
#define PLK_F34 0xFFDF
|
||||
#define PLK_R14 0xFFDF
|
||||
#define PLK_F35 0xFFE0
|
||||
#define PLK_R15 0xFFE0
|
||||
|
||||
/* Modifiers */
|
||||
|
||||
#define PLK_Shift_L 0xFFE1 /* Left shift */
|
||||
#define PLK_Shift_R 0xFFE2 /* Right shift */
|
||||
#define PLK_Control_L 0xFFE3 /* Left control */
|
||||
#define PLK_Control_R 0xFFE4 /* Right control */
|
||||
#define PLK_Caps_Lock 0xFFE5 /* Caps lock */
|
||||
#define PLK_Shift_Lock 0xFFE6 /* Shift lock */
|
||||
|
||||
#define PLK_Meta_L 0xFFE7 /* Left meta */
|
||||
#define PLK_Meta_R 0xFFE8 /* Right meta */
|
||||
#define PLK_Alt_L 0xFFE9 /* Left alt */
|
||||
#define PLK_Alt_R 0xFFEA /* Right alt */
|
||||
#define PLK_Super_L 0xFFEB /* Left super */
|
||||
#define PLK_Super_R 0xFFEC /* Right super */
|
||||
#define PLK_Hyper_L 0xFFED /* Left hyper */
|
||||
#define PLK_Hyper_R 0xFFEE /* Right hyper */
|
||||
|
||||
#endif /* __PLEVENT_H__ */
|
|
@ -1,341 +0,0 @@
|
|||
/* $Id: plfill.c,v 1.2 2005/03/17 21:39:21 eli Exp $
|
||||
|
||||
Polygon pattern fill.
|
||||
*/
|
||||
|
||||
#include "plplotP.h"
|
||||
|
||||
#define DTOR 0.0174533
|
||||
#define BINC 50
|
||||
|
||||
struct point {
|
||||
PLINT x, y;
|
||||
};
|
||||
static PLINT bufferleng, buffersize, *buffer;
|
||||
|
||||
/* Static function prototypes */
|
||||
/* INDENT OFF */
|
||||
|
||||
static int compar (const void *, const void *);
|
||||
static void addcoord (PLINT, PLINT);
|
||||
static void tran (PLINT *, PLINT *, PLFLT, PLFLT);
|
||||
static void buildlist (PLINT, PLINT, PLINT, PLINT, PLINT, PLINT, PLINT);
|
||||
|
||||
/* INDENT ON */
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plfill()
|
||||
*
|
||||
* Pattern fills the polygon bounded by the input points.
|
||||
* If hardware fill is used, a maximum of PL_MAXPOLY-1 vertices is allowed.
|
||||
* The final point is explicitly added if it doesn't match up to the first,
|
||||
* to prevent clipping problems.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
MZ_DLLEXPORT
|
||||
void
|
||||
c_plfill(PLINT n, PLFLT *x, PLFLT *y)
|
||||
{
|
||||
PLINT xpoly[PL_MAXPOLY], ypoly[PL_MAXPOLY];
|
||||
PLINT i;
|
||||
|
||||
if (plsc->level < 3) {
|
||||
plabort("plfill: Please set up window first");
|
||||
return;
|
||||
}
|
||||
if (n < 3) {
|
||||
plabort("plfill: Not enough points in object");
|
||||
return;
|
||||
}
|
||||
if (n > PL_MAXPOLY-1) {
|
||||
plwarn("plfill: too many points in polygon");
|
||||
n = PL_MAXPOLY;
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
xpoly[i] = plP_wcpcx(x[i]);
|
||||
ypoly[i] = plP_wcpcy(y[i]);
|
||||
}
|
||||
|
||||
if (x[0] != x[n-1] || y[0] != y[n-1]) {
|
||||
n++;
|
||||
xpoly[n-1] = plP_wcpcx(x[0]);
|
||||
ypoly[n-1] = plP_wcpcy(y[0]);
|
||||
}
|
||||
|
||||
plP_plfclp(xpoly, ypoly, n, plsc->clpxmi, plsc->clpxma,
|
||||
plsc->clpymi, plsc->clpyma, plP_fill);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plfill3()
|
||||
*
|
||||
* Pattern fills the polygon in 3d bounded by the input points.
|
||||
* If hardware fill is used, a maximum of PL_MAXPOLY-1 vertices is allowed.
|
||||
* The final point is explicitly added if it doesn't match up to the first,
|
||||
* to prevent clipping problems.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plfill3(PLINT n, PLFLT *x, PLFLT *y, PLFLT *z)
|
||||
{
|
||||
PLFLT tx[PL_MAXPOLY], ty[PL_MAXPOLY], tz[PL_MAXPOLY];
|
||||
PLFLT *V[3];
|
||||
PLINT xpoly[PL_MAXPOLY], ypoly[PL_MAXPOLY];
|
||||
PLINT i;
|
||||
PLFLT xmin, xmax, ymin, ymax, zmin, zmax, zscale;
|
||||
|
||||
if (plsc->level < 3) {
|
||||
plabort("plfill3: Please set up window first");
|
||||
return;
|
||||
}
|
||||
if (n < 3) {
|
||||
plabort("plfill3: Not enough points in object");
|
||||
return;
|
||||
}
|
||||
if (n > PL_MAXPOLY-1) {
|
||||
plwarn("plfill3: too many points in polygon");
|
||||
n = PL_MAXPOLY;
|
||||
}
|
||||
|
||||
plP_gdom(&xmin, &xmax, &ymin, &ymax);
|
||||
plP_grange(&zscale, &zmin, &zmax);
|
||||
|
||||
/* copy the vertices so we can clip without corrupting the input */
|
||||
for( i=0; i < n; i++ ) {
|
||||
tx[i] = x[i]; ty[i] = y[i]; tz[i] = z[i];
|
||||
}
|
||||
if (tx[0] != tx[n-1] || ty[0] != ty[n-1] || tz[0] != tz[n-1]) {
|
||||
tx[n] = tx[0]; ty[n] = ty[0]; tz[n] = tz[0];
|
||||
n++;
|
||||
}
|
||||
V[0] = tx; V[1] = ty; V[2] = tz;
|
||||
n = plP_clip_poly(n, V, 0, 1, -xmin);
|
||||
n = plP_clip_poly(n, V, 0, -1, xmax);
|
||||
n = plP_clip_poly(n, V, 1, 1, -ymin);
|
||||
n = plP_clip_poly(n, V, 1, -1, ymax);
|
||||
n = plP_clip_poly(n, V, 2, 1, -zmin);
|
||||
n = plP_clip_poly(n, V, 2, -1, zmax);
|
||||
for( i=0; i < n; i++ ) {
|
||||
xpoly[i] = plP_wcpcx(plP_w3wcx( tx[i], ty[i], tz[i] ));
|
||||
ypoly[i] = plP_wcpcy(plP_w3wcy( tx[i], ty[i], tz[i] ));
|
||||
}
|
||||
|
||||
/* AWI: in the past we have used
|
||||
* plP_fill(xpoly, ypoly, n);
|
||||
* here, but our educated guess is this fill should be done via the clipping
|
||||
* interface instead as below.
|
||||
* No example tests this code so one of our users will end up inadvertently
|
||||
* testing this for us.
|
||||
*
|
||||
* jc: I have checked, and both versions does give the same result, i.e., clipping
|
||||
* to the window boundaries. The reason is that the above plP_clip_poly() does
|
||||
* the clipping. To check this, is enough to diminish the x/y/z min/max arguments in
|
||||
* plw3d() in x08c. But let's keep it, although 10% slower...
|
||||
*/
|
||||
plP_plfclp(xpoly, ypoly, n, plsc->clpxmi, plsc->clpxma,
|
||||
plsc->clpymi, plsc->clpyma, plP_fill);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plfill_soft()
|
||||
*
|
||||
* Pattern fills in software the polygon bounded by the input points.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plfill_soft(short *x, short *y, PLINT n)
|
||||
{
|
||||
PLINT i, j;
|
||||
PLINT xp1, yp1, xp2, yp2, xp3, yp3;
|
||||
PLINT k, dinc;
|
||||
PLFLT ci, si;
|
||||
double temp;
|
||||
|
||||
buffersize = 2 * BINC;
|
||||
buffer = (PLINT *) malloc((size_t) buffersize * sizeof(PLINT));
|
||||
if ( ! buffer) {
|
||||
plabort("plfill: Out of memory");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Loop over sets of lines in pattern */
|
||||
|
||||
for (k = 0; k < plsc->nps; k++) {
|
||||
bufferleng = 0;
|
||||
|
||||
temp = DTOR * plsc->inclin[k] * 0.1;
|
||||
si = sin(temp) * plsc->ypmm;
|
||||
ci = cos(temp) * plsc->xpmm;
|
||||
|
||||
/* normalize: 1 = si*si + ci*ci */
|
||||
|
||||
temp = sqrt((double) (si*si + ci*ci));
|
||||
si /= temp;
|
||||
ci /= temp;
|
||||
|
||||
dinc = plsc->delta[k] * SSQR(plsc->ypmm * ABS(ci),
|
||||
plsc->xpmm * ABS(si)) / 1000.;
|
||||
|
||||
if (dinc < 0) dinc = -dinc;
|
||||
if (dinc == 0) dinc = 1;
|
||||
|
||||
xp1 = x[n-2];
|
||||
yp1 = y[n-2];
|
||||
tran(&xp1, &yp1, (PLFLT) ci, (PLFLT) si);
|
||||
|
||||
xp2 = x[n-1];
|
||||
yp2 = y[n-1];
|
||||
tran(&xp2, &yp2, (PLFLT) ci, (PLFLT) si);
|
||||
|
||||
/* Loop over points in polygon */
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
xp3 = x[i];
|
||||
yp3 = y[i];
|
||||
tran(&xp3, &yp3, (PLFLT) ci, (PLFLT) si);
|
||||
buildlist(xp1, yp1, xp2, yp2, xp3, yp3, dinc);
|
||||
xp1 = xp2;
|
||||
yp1 = yp2;
|
||||
xp2 = xp3;
|
||||
yp2 = yp3;
|
||||
}
|
||||
|
||||
/* Sort list by y then x */
|
||||
|
||||
qsort((void *) buffer, (size_t) bufferleng / 2,
|
||||
(size_t) sizeof(struct point), compar);
|
||||
|
||||
/* OK, now do the hatching */
|
||||
|
||||
i = 0;
|
||||
|
||||
while (i < bufferleng) {
|
||||
xp1 = buffer[i];
|
||||
yp1 = buffer[i + 1];
|
||||
i += 2;
|
||||
xp2 = xp1;
|
||||
yp2 = yp1;
|
||||
tran(&xp1, &yp1, (PLFLT) ci, (PLFLT) (-si));
|
||||
plP_movphy(xp1, yp1);
|
||||
xp1 = buffer[i];
|
||||
yp1 = buffer[i + 1];
|
||||
i += 2;
|
||||
if (yp2 != yp1) {
|
||||
fprintf(stderr, "plfill: oh oh we are lost\n");
|
||||
for (j = 0; j < bufferleng; j+=2) {
|
||||
fprintf(stderr, "plfill: %d %d\n",
|
||||
(int) buffer[j], (int) buffer[j+1]);
|
||||
}
|
||||
continue; /* Uh oh we're lost */
|
||||
}
|
||||
tran(&xp1, &yp1, (PLFLT) ci, (PLFLT) (-si));
|
||||
plP_draphy(xp1, yp1);
|
||||
}
|
||||
}
|
||||
free((void *) buffer);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* Utility functions
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
tran(PLINT *a, PLINT *b, PLFLT c, PLFLT d)
|
||||
{
|
||||
PLINT ta, tb;
|
||||
|
||||
ta = *a;
|
||||
tb = *b;
|
||||
|
||||
*a = floor((double) (ta * c + tb * d + 0.5));
|
||||
*b = floor((double) (tb * c - ta * d + 0.5));
|
||||
}
|
||||
|
||||
static void
|
||||
buildlist(PLINT xp1, PLINT yp1, PLINT xp2, PLINT yp2, PLINT xp3, PLINT yp3,
|
||||
PLINT dinc)
|
||||
{
|
||||
PLINT min_y, max_y;
|
||||
PLINT dx, dy, cstep, nstep, ploty, plotx;
|
||||
|
||||
dx = xp2 - xp1;
|
||||
dy = yp2 - yp1;
|
||||
|
||||
if (dy == 0) {
|
||||
if (yp2 > yp3 && ((yp2 % dinc) == 0))
|
||||
addcoord(xp2, yp2);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dy > 0) {
|
||||
cstep = 1;
|
||||
min_y = yp1;
|
||||
max_y = yp2;
|
||||
}
|
||||
else {
|
||||
cstep = -1;
|
||||
min_y = yp2;
|
||||
max_y = yp1;
|
||||
}
|
||||
|
||||
nstep = (yp3 > yp2 ? 1 : -1);
|
||||
if (yp3 == yp2) nstep = 0;
|
||||
|
||||
/* Build coordinate list */
|
||||
|
||||
ploty = (min_y / dinc) * dinc;
|
||||
if (ploty < min_y) ploty += dinc;
|
||||
|
||||
for (; ploty <= max_y; ploty += dinc) {
|
||||
if (ploty == yp1) continue;
|
||||
if (ploty == yp2) {
|
||||
if (cstep == -nstep) continue;
|
||||
if (yp2 == yp3 && yp1 > yp2) continue;
|
||||
}
|
||||
plotx = xp1 + floor(((double) (ploty - yp1) * dx) / dy + 0.5);
|
||||
addcoord(plotx, ploty);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
addcoord(PLINT xp1, PLINT yp1)
|
||||
{
|
||||
PLINT *temp;
|
||||
|
||||
if (bufferleng + 2 > buffersize) {
|
||||
buffersize += 2 * BINC;
|
||||
temp = (PLINT *) realloc((void *) buffer,
|
||||
(size_t) buffersize * sizeof(PLINT));
|
||||
if (!temp) {
|
||||
free((void *) buffer);
|
||||
plexit("plfill: Out of memory!");
|
||||
}
|
||||
buffer = temp;
|
||||
}
|
||||
|
||||
buffer[bufferleng++] = xp1;
|
||||
buffer[bufferleng++] = yp1;
|
||||
}
|
||||
|
||||
static int
|
||||
compar(const void *pnum1, const void *pnum2)
|
||||
{
|
||||
const struct point *pnt1, *pnt2;
|
||||
|
||||
pnt1 = (const struct point *) pnum1;
|
||||
pnt2 = (const struct point *) pnum2;
|
||||
|
||||
if (pnt1->y < pnt2->y)
|
||||
return -1;
|
||||
else if (pnt1->y > pnt2->y)
|
||||
return 1;
|
||||
|
||||
/* Only reach here if y coords are equal, so sort by x */
|
||||
|
||||
if (pnt1->x < pnt2->x)
|
||||
return -1;
|
||||
else if (pnt1->x > pnt2->x)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,126 +0,0 @@
|
|||
/* $Id: plfreetype.h,v 1.1 2004/03/01 20:54:51 cozmic Exp $
|
||||
*
|
||||
* Header file for Support routines for freetype font engine
|
||||
*
|
||||
* See plfreetype.c for more details
|
||||
*/
|
||||
|
||||
#ifndef __PLFREETY_H__
|
||||
#define __PLFREETY_H__
|
||||
|
||||
#ifdef HAVE_FREETYPE
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_GLYPH_H
|
||||
#include FT_OUTLINE_H
|
||||
|
||||
#define FT_Data _FT_Data_
|
||||
|
||||
typedef void (*plD_pixel_fp) (PLStream *, PLINT, PLINT);
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Define the FT_Data data structure.
|
||||
*
|
||||
* These are the "globalish" variables used by Freetype
|
||||
* They are kept here so they are moderately thread safe, and stream specific
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
typedef struct FT_Data {
|
||||
short x;
|
||||
short y;
|
||||
|
||||
char *textbuf; /* temporary string buffer */
|
||||
|
||||
PLFLT scale;
|
||||
/*
|
||||
* If set to 1, scale won't do anything, but this is an "arbitrary" scale
|
||||
* factor for the transformation between virtual and real coordinates. This
|
||||
* is included to fix up the problem with the "hidden line removal bug" of
|
||||
* the 3D plots, which is fixed by providing a super-scaled image. This
|
||||
* should be a mirror, for example, of dev->scale in the PNG driver. If I
|
||||
* was thinking 12 months ahead, I would have put that scale factor in
|
||||
* "pls", not "dev", but at this late stage, we can just live with it
|
||||
* now...
|
||||
*/
|
||||
|
||||
unsigned char greek;
|
||||
|
||||
unsigned char invert_y;
|
||||
/*
|
||||
* Set "invert_y" to 1 if the y coordinates need to be inverted for
|
||||
* plotting. Most bitmaps will need this.
|
||||
*/
|
||||
|
||||
short ymax;
|
||||
/*
|
||||
* ymax should be equal to, what it says - the maximum y coordinate of the
|
||||
* bitmap. This is used in the process of calculating the inversion of the
|
||||
* bitmap when invert_y is set to 1. If invert_y isn't set, this setting is
|
||||
* ignored.
|
||||
*/
|
||||
|
||||
|
||||
plD_pixel_fp pixel; /* pointer to a function which draws a single pixel */
|
||||
|
||||
|
||||
int want_smooth_text; /* flag to request text smoothing (won't */
|
||||
/* necessarily get it though */
|
||||
int smooth_text; /* Flag to indicate type of anti-aliasing used, if freetype text is active */
|
||||
|
||||
|
||||
char font_name[5][1024];
|
||||
/*
|
||||
* List of font names and paths corresponding to the "predefined" fonts of
|
||||
* plplot. 1024 chars is presumably generous for each one's length, but at
|
||||
* least we probably won't get in trouble this way.
|
||||
*/
|
||||
|
||||
|
||||
PLINT cfont;
|
||||
/*
|
||||
* This is a mirror of pls->cfont and is basically used for detecting when
|
||||
* fonts have been changed .
|
||||
*/
|
||||
|
||||
|
||||
FT_Matrix matrix; /* used for rotating etc... the font. */
|
||||
FT_Vector pos; /* used for calculating offsets of text boxes/sizes */
|
||||
|
||||
|
||||
/*
|
||||
* The next few variables hold the original size of CMAP0, the number of
|
||||
* extra slots added for anti-aliasing, and the "width" of the table used
|
||||
* for anti-aliasing.
|
||||
*/
|
||||
|
||||
PLINT ncol0_org; /* Original number of colours in CMAP0 */
|
||||
PLINT ncol0_xtra; /* number of extra colours defined in CMAP0 for anti-aliasing */
|
||||
PLINT ncol0_width; /* Number of greyscale levels for each of the original colours */
|
||||
PLINT last_icol0; /* Last colour in cmap0, which should be one of the originals */
|
||||
|
||||
|
||||
/*
|
||||
* The rest of the variables should be considered very much PRIVATE, and
|
||||
* more to the point, subject to change.
|
||||
*
|
||||
* Don't rely on them existing in future versions of plplot's freetype
|
||||
* support. If/when the Freetype cache manager is added to plplot, most, if
|
||||
* not all, of these variables will move elsewhere.
|
||||
*/
|
||||
|
||||
FT_Library library; /* pointer to freetype library */
|
||||
FT_Face face; /* pointer to a font face */
|
||||
FT_GlyphSlot slot; /* pointer to a glyph slot */
|
||||
FT_Glyph image; /* bitmap or outline image of font */
|
||||
|
||||
short colour; /* depreciated ?? must check code */
|
||||
|
||||
PLINT shade, col_idx; /* Used for antialiasing */
|
||||
|
||||
} FT_Data;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __PLFREETY_H__ */
|
|
@ -1,843 +0,0 @@
|
|||
|
||||
#include "plplotP.h"
|
||||
|
||||
#ifdef WITH_CSA
|
||||
#include "csa.h"
|
||||
#endif
|
||||
#include "nan.h" /* this is handy */
|
||||
|
||||
#ifdef HAVE_QHULL
|
||||
#include "../lib/nn/nn.h"
|
||||
#include <qhull/qhull_a.h>
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_ISNAN) && !defined(isnan)
|
||||
#define isnan(x) ((x) != (x))
|
||||
#endif
|
||||
|
||||
/* forward declarations */
|
||||
static void
|
||||
grid_nnaidw (PLFLT *x, PLFLT *y, PLFLT *z, int npts,
|
||||
PLFLT *xg, int nptsx, PLFLT *yg, int nptsy, PLFLT **zg);
|
||||
|
||||
static void
|
||||
grid_nnli (PLFLT *x, PLFLT *y, PLFLT *z, int npts,
|
||||
PLFLT *xg, int nptsx, PLFLT *yg, int nptsy, PLFLT **zg,
|
||||
PLFLT threshold);
|
||||
|
||||
static void
|
||||
grid_nnidw (PLFLT *x, PLFLT *y, PLFLT *z, int npts,
|
||||
PLFLT *xg, int nptsx, PLFLT *yg, int nptsy, PLFLT **zg,
|
||||
int knn_order);
|
||||
|
||||
#ifdef WITH_CSA
|
||||
static void
|
||||
grid_csa (PLFLT *x, PLFLT *y, PLFLT *z, int npts,
|
||||
PLFLT *xg, int nptsx, PLFLT *yg, int nptsy, PLFLT **zg);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_QHULL
|
||||
static void
|
||||
grid_nni (PLFLT *x, PLFLT *y, PLFLT *z, int npts,
|
||||
PLFLT *xg, int nptsx, PLFLT *yg, int nptsy, PLFLT **zg,
|
||||
PLFLT wmin);
|
||||
|
||||
static void
|
||||
grid_dtli (PLFLT *x, PLFLT *y, PLFLT *z, int npts,
|
||||
PLFLT *xg, int nptsx, PLFLT *yg, int nptsy, PLFLT **zg);
|
||||
#endif
|
||||
|
||||
static void
|
||||
dist1(PLFLT gx, PLFLT gy, PLFLT *x, PLFLT *y, int npts, int knn_order);
|
||||
static void
|
||||
dist2(PLFLT gx, PLFLT gy, PLFLT *x, PLFLT *y, int npts);
|
||||
|
||||
#define KNN_MAX_ORDER 100
|
||||
|
||||
typedef struct pt{
|
||||
PLFLT dist;
|
||||
int item;
|
||||
}PT;
|
||||
|
||||
static PT items[KNN_MAX_ORDER];
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
*
|
||||
* plgriddata(): grids data from irregularly sampled data.
|
||||
*
|
||||
* Real world data is frequently irregularly sampled, but most 3D plots
|
||||
* require regularly gridded data. This function does exactly this
|
||||
* using several methods:
|
||||
* Irregularly sampled data x[npts], y[npts], z[npts] is gridded into
|
||||
* zg[nptsx, nptsy] according to methode 'type' and grid information
|
||||
* xg[nptsx], yg[nptsy].
|
||||
*
|
||||
* 'type' can be:
|
||||
*
|
||||
* GRID_CSA: Bivariate Cubic Spline approximation (1)
|
||||
* GRID_NNIDW: Nearest Neighbors Inverse Distance Weighted
|
||||
* GRID_NNLI: Nearest Neighbors Linear Interpolation
|
||||
* GRID_NNAIDW: Nearest Neighbors Around Inverse Distance Weighted
|
||||
* GRID_DTLI: Delaunay Triangulation Linear Interpolation (2)
|
||||
* GRID_NNI: Natural Neighbors interpolation (2)
|
||||
*
|
||||
* (1): Copyright 2000-2002 CSIRO Marine Research, Pavel Sakov's csa library
|
||||
* (2): Copyright 2002 CSIRO Marine Research, Pavel Sakov's nn library
|
||||
*
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plgriddata(PLFLT *x, PLFLT *y, PLFLT *z, int npts,
|
||||
PLFLT *xg, int nptsx, PLFLT *yg, int nptsy,
|
||||
PLFLT **zg, int type, PLFLT data)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
if(npts < 1 || nptsx < 1 || nptsy < 1) {
|
||||
plabort("plgriddata: Bad array dimensions");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check that points in xg and in yg are strictly increasing */
|
||||
|
||||
for (i = 0; i < nptsx - 1; i++) {
|
||||
if (xg[i] >= xg[i + 1]) {
|
||||
plabort("plgriddata: xg array must be strictly increasing");
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < nptsy - 1; i++) {
|
||||
if (yg[i] >= yg[i + 1]) {
|
||||
plabort("plgriddata: yg array must be strictly increasing");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* clear array to return */
|
||||
for(i=0; i<nptsx; i++)
|
||||
for(j=0; j<nptsy; j++)
|
||||
zg[i][j] = 0.; /* NaN signals a not processed grid point */
|
||||
|
||||
switch (type) {
|
||||
|
||||
case (GRID_CSA): /* Bivariate Cubic Spline Approximation */
|
||||
#ifdef WITH_CSA
|
||||
grid_csa(x, y, z, npts, xg, nptsx, yg, nptsy, zg);
|
||||
#else
|
||||
plabort("plgriddata(): PLplot was configured to not use GRID_CSA.");
|
||||
#endif
|
||||
break;
|
||||
|
||||
case (GRID_NNIDW): /* Nearest Neighbors Inverse Distance Weighted */
|
||||
grid_nnidw(x, y, z, npts, xg, nptsx, yg, nptsy, zg, (int) data);
|
||||
break;
|
||||
|
||||
case (GRID_NNLI): /* Nearest Neighbors Linear Interpolation */
|
||||
grid_nnli(x, y, z, npts, xg, nptsx, yg, nptsy, zg, data);
|
||||
break;
|
||||
|
||||
case (GRID_NNAIDW): /* Nearest Neighbors "Around" Inverse Distance Weighted */
|
||||
grid_nnaidw(x, y, z, npts, xg, nptsx, yg, nptsy, zg);
|
||||
break;
|
||||
|
||||
case (GRID_DTLI): /* Delaunay Triangulation Linear Interpolation */
|
||||
#ifdef HAVE_QHULL
|
||||
grid_dtli(x, y, z, npts, xg, nptsx, yg, nptsy, zg);
|
||||
#else
|
||||
plabort("plgriddata(): you must have Qhull to use GRID_DTLI.");
|
||||
#endif
|
||||
break;
|
||||
|
||||
case (GRID_NNI): /* Natural Neighbors */
|
||||
#ifdef HAVE_QHULL
|
||||
grid_nni(x, y, z, npts, xg, nptsx, yg, nptsy, zg, data);
|
||||
#else
|
||||
plabort("plgriddata(): you must have Qhull to use GRID_NNI.");
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
plabort("plgriddata: unknown algorithm type");
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WITH_CSA
|
||||
/*
|
||||
* Bivariate Cubic Spline Approximation using Pavel Sakov's csa package
|
||||
*
|
||||
* NaNs are returned where no interpolation can be done.
|
||||
*/
|
||||
|
||||
static void
|
||||
grid_csa (PLFLT *x, PLFLT *y, PLFLT *z, int npts,
|
||||
PLFLT *xg, int nptsx, PLFLT *yg, int nptsy, PLFLT **zg)
|
||||
{
|
||||
PLFLT *xt, *yt, *zt;
|
||||
point *pin, *pgrid, *pt;
|
||||
csa* a = NULL;
|
||||
int i, j, nptsg;
|
||||
|
||||
pin = (point *) malloc(npts * sizeof(point));
|
||||
|
||||
xt = x; yt = y; zt = z; pt = pin;
|
||||
for(i=0; i<npts; i++) {
|
||||
pt->x = (double) *xt++;
|
||||
pt->y = (double) *yt++;
|
||||
pt->z = (double) *zt++;
|
||||
pt++;
|
||||
}
|
||||
|
||||
nptsg = nptsx * nptsy;
|
||||
pgrid = (point *) malloc(nptsg * sizeof(point));
|
||||
|
||||
yt = yg; pt = pgrid;
|
||||
for(j=0; j<nptsy; j++) {
|
||||
xt = xg;
|
||||
for(i=0; i<nptsx; i++) {
|
||||
pt->x = (double) *xt++;
|
||||
pt->y = (double) *yt;
|
||||
pt++;
|
||||
}
|
||||
yt++;
|
||||
}
|
||||
|
||||
a = csa_create();
|
||||
csa_addpoints(a, npts, pin);
|
||||
csa_calculatespline(a);
|
||||
csa_approximate_points(a, nptsg, pgrid);
|
||||
|
||||
for(i=0; i<nptsx; i++) {
|
||||
for(j=0; j<nptsy; j++) {
|
||||
pt = &pgrid[j*nptsx + i];
|
||||
zg[i][j] = (PLFLT) pt->z;
|
||||
}
|
||||
}
|
||||
|
||||
csa_destroy(a);
|
||||
free(pin);
|
||||
free(pgrid);
|
||||
}
|
||||
#endif /* WITH_CSA */
|
||||
|
||||
/* Nearest Neighbors Inverse Distance Weighted, brute force approach.
|
||||
*
|
||||
* The z value at the grid position will be the weighted average
|
||||
* of the z values of the KNN points found. The weigth is the
|
||||
* inverse squared distance between the grid point and each
|
||||
* neighbor.
|
||||
*/
|
||||
|
||||
static void
|
||||
grid_nnidw (PLFLT *x, PLFLT *y, PLFLT *z, int npts,
|
||||
PLFLT *xg, int nptsx, PLFLT *yg, int nptsy, PLFLT **zg,
|
||||
int knn_order)
|
||||
{
|
||||
int i, j, k;
|
||||
PLFLT wi, nt;
|
||||
|
||||
if (knn_order > KNN_MAX_ORDER) {
|
||||
plabort("plgriddata(): GRID_NNIDW: knn_order too big"); /* make sure it is smaller that KNN_MAX_ORDER */
|
||||
return;
|
||||
}
|
||||
|
||||
if (knn_order == 0) {
|
||||
plwarn("plgriddata(): GRID_NNIDW: knn_order must be specified with 'data' arg. Using 15");
|
||||
knn_order = 15;;
|
||||
}
|
||||
|
||||
for (i=0; i<nptsx; i++) {
|
||||
for (j=0; j<nptsy; j++) {
|
||||
dist1(xg[i], yg[j], x, y, npts, knn_order);
|
||||
|
||||
#ifdef GMS /* alternative weight coeficients. I Don't like the results */
|
||||
/* find the maximum distance */
|
||||
md = items[0].dist;
|
||||
for (k=1; k<knn_order; k++)
|
||||
if (items[k].dist > md)
|
||||
md = items[k].dist;
|
||||
#endif
|
||||
zg[i][j] = 0.;
|
||||
nt = 0.;
|
||||
|
||||
for (k=0; k<knn_order; k++) {
|
||||
if(items[k].item == -1) /* not enough neighbors found ?! */
|
||||
continue;
|
||||
#ifdef GMS
|
||||
wi = (md - items[k].dist)/(md * items[k].dist);
|
||||
wi = wi*wi;
|
||||
#else
|
||||
wi = 1./(items[k].dist*items[k].dist);
|
||||
#endif
|
||||
zg[i][j] += wi * z[items[k].item];
|
||||
nt += wi;
|
||||
}
|
||||
if (nt != 0.)
|
||||
zg[i][j] /= nt;
|
||||
else
|
||||
zg[i][j] = NaN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Nearest Neighbors Linear Interpolation
|
||||
*
|
||||
* The z value at the grid position will be interpolated from the
|
||||
* plane passing through the 3 nearest neighbors.
|
||||
*/
|
||||
|
||||
static void
|
||||
grid_nnli (PLFLT *x, PLFLT *y, PLFLT *z, int npts,
|
||||
PLFLT *xg, int nptsx, PLFLT *yg, int nptsy, PLFLT **zg,
|
||||
PLFLT threshold)
|
||||
{
|
||||
PLFLT xx[4], yy[4], zz[4], t, A, B, C, D, d1, d2, d3, max_thick;
|
||||
int i, j, ii, excl, cnt, excl_item;
|
||||
|
||||
if (threshold == 0.) {
|
||||
plwarn("plgriddata(): GRID_NNLI: threshold must be specified with 'data' arg. Using 1.001");
|
||||
threshold = 1.001;
|
||||
} else if ( threshold > 2. || threshold < 1.) {
|
||||
plabort("plgriddata(): GRID_NNLI: 1. < threshold < 2.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i=0; i<nptsx; i++) {
|
||||
for (j=0; j<nptsy; j++) {
|
||||
dist1(xg[i], yg[j], x, y, npts, 3);
|
||||
|
||||
/* see if the triangle is a thin one */
|
||||
for (ii=0; ii<3; ii++) {
|
||||
xx[ii] = x[items[ii].item];
|
||||
yy[ii] = y[items[ii].item];
|
||||
zz[ii] = z[items[ii].item];
|
||||
}
|
||||
|
||||
d1 = sqrt((xx[1]-xx[0])*(xx[1]-xx[0]) + (yy[1]-yy[0])*(yy[1]-yy[0]));
|
||||
d2 = sqrt((xx[2]-xx[1])*(xx[2]-xx[1]) + (yy[2]-yy[1])*(yy[2]-yy[1]));
|
||||
d3 = sqrt((xx[0]-xx[2])*(xx[0]-xx[2]) + (yy[0]-yy[2])*(yy[0]-yy[2]));
|
||||
|
||||
if (d1 == 0. || d2 == 0. || d3 == 0.) { /* coincident points */
|
||||
zg[i][j] = NaN;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* make d1 < d2 */
|
||||
if (d1 > d2) {
|
||||
t = d1; d1 = d2; d2 = t;
|
||||
}
|
||||
|
||||
/* and d2 < d3 */
|
||||
if (d2 > d3) {
|
||||
t = d2; d2 = d3; d3 = t;
|
||||
}
|
||||
|
||||
if ((d1+d2)/d3 < threshold) { /* thin triangle! */
|
||||
zg[i][j] = NaN; /* deal with it latter */
|
||||
} else { /* calculate the plane passing through the three points */
|
||||
|
||||
A = yy[0]*(zz[1]-zz[2]) + yy[1]*(zz[2]-zz[0]) + yy[2]*(zz[0]-zz[1]);
|
||||
B = zz[0]*(xx[1]-xx[2]) + zz[1]*(xx[2]-xx[0]) + zz[2]*(xx[0]-xx[1]);
|
||||
C = xx[0]*(yy[1]-yy[2]) + xx[1]*(yy[2]-yy[0]) + xx[2]*(yy[0]-yy[1]);
|
||||
D = - A*xx[0] - B*yy[0] - C*zz[0];
|
||||
|
||||
/* and interpolate (or extrapolate...) */
|
||||
zg[i][j] = - xg[i]*A/C - yg[j]*B/C - D/C;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* now deal with NaNs resulting from thin triangles. The idea is
|
||||
* to use the 4 KNN points and exclude one at a time, creating
|
||||
* four triangles, evaluating their thickness and choosing the
|
||||
* most thick as the final one from where the interpolating
|
||||
* plane will be build. Now that I'm talking of interpolating,
|
||||
* one should really check that the target point is interior to
|
||||
* the candidate triangle... otherwise one is extrapolating
|
||||
*/
|
||||
|
||||
{
|
||||
for (i=0; i<nptsx; i++) {
|
||||
for (j=0; j<nptsy; j++) {
|
||||
|
||||
if (isnan(zg[i][j])) {
|
||||
dist1(xg[i], yg[j], x, y, npts, 4);
|
||||
|
||||
/* sort by distances. Not really needed!
|
||||
for (ii=3; ii>0; ii--) {
|
||||
for (jj=0; jj<ii; jj++) {
|
||||
if (items[jj].dist > items[jj+1].dist) {
|
||||
t = items[jj].dist;
|
||||
items[jj].dist = items[jj+1].dist;
|
||||
items[jj+1].dist = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
max_thick = 0.; excl_item = -1;
|
||||
for (excl=0; excl<4; excl++) { /* the excluded point */
|
||||
|
||||
cnt = 0;
|
||||
for (ii=0; ii<4; ii++) {
|
||||
if (ii != excl) {
|
||||
xx[cnt] = x[items[ii].item];
|
||||
yy[cnt] = y[items[ii].item];
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
d1 = sqrt((xx[1]-xx[0])*(xx[1]-xx[0]) + (yy[1]-yy[0])*(yy[1]-yy[0]));
|
||||
d2 = sqrt((xx[2]-xx[1])*(xx[2]-xx[1]) + (yy[2]-yy[1])*(yy[2]-yy[1]));
|
||||
d3 = sqrt((xx[0]-xx[2])*(xx[0]-xx[2]) + (yy[0]-yy[2])*(yy[0]-yy[2]));
|
||||
if (d1 == 0. || d2 == 0. || d3 == 0.) /* coincident points */ continue;
|
||||
|
||||
/* make d1 < d2 */
|
||||
if (d1 > d2) {
|
||||
t = d1; d1 = d2; d2 = t;
|
||||
}
|
||||
/* and d2 < d3 */
|
||||
if (d2 > d3) {
|
||||
t = d2; d2 = d3; d3 = t;
|
||||
}
|
||||
|
||||
t = (d1+d2)/d3;
|
||||
if ( t > max_thick) {
|
||||
max_thick = t;
|
||||
excl_item = excl;
|
||||
}
|
||||
}
|
||||
|
||||
if (excl_item == -1) /* all points are coincident? */
|
||||
continue;
|
||||
|
||||
/* one has the thicker triangle constructed from the 4 KNN */
|
||||
cnt = 0;
|
||||
for (ii=0; ii<4; ii++) {
|
||||
if (ii != excl_item) {
|
||||
xx[cnt] = x[items[ii].item];
|
||||
yy[cnt] = y[items[ii].item];
|
||||
zz[cnt] = z[items[ii].item];
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
A = yy[0]*(zz[1]-zz[2]) + yy[1]*(zz[2]-zz[0]) + yy[2]*(zz[0]-zz[1]);
|
||||
B = zz[0]*(xx[1]-xx[2]) + zz[1]*(xx[2]-xx[0]) + zz[2]*(xx[0]-xx[1]);
|
||||
C = xx[0]*(yy[1]-yy[2]) + xx[1]*(yy[2]-yy[0]) + xx[2]*(yy[0]-yy[1]);
|
||||
D = - A*xx[0] - B*yy[0] - C*zz[0];
|
||||
|
||||
/* and interpolate (or extrapolate...) */
|
||||
zg[i][j] = - xg[i]*A/C - yg[j]*B/C - D/C;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Nearest Neighbors "Around" Inverse Distance Weighted, brute force approach.
|
||||
*
|
||||
* This uses the 1-KNN in each quadrant around the grid point, then
|
||||
* Inverse Distance Weighted is used as in GRID_NNIDW.
|
||||
*/
|
||||
|
||||
static void
|
||||
grid_nnaidw (PLFLT *x, PLFLT *y, PLFLT *z, int npts,
|
||||
PLFLT *xg, int nptsx, PLFLT *yg, int nptsy, PLFLT **zg)
|
||||
{
|
||||
PLFLT d, nt;
|
||||
int i, j, k;
|
||||
|
||||
for (i=0; i<nptsx; i++) {
|
||||
for (j=0; j<nptsy; j++) {
|
||||
dist2(xg[i], yg[j], x, y, npts);
|
||||
zg[i][j] = 0.;
|
||||
nt = 0.;
|
||||
for (k=0; k<4; k++) {
|
||||
if (items[k].item != -1) { /* was found */
|
||||
d = 1./(items[k].dist * items[k].dist); /* 1/square distance */
|
||||
zg[i][j] += d * z[items[k].item];
|
||||
nt += d;
|
||||
}
|
||||
}
|
||||
if (nt == 0.) /* no points found?! */
|
||||
zg[i][j] = NaN;
|
||||
else
|
||||
zg[i][j] /= nt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_QHULL
|
||||
/*
|
||||
* Delaunay Triangulation Linear Interpolation using Pavel Sakov's nn package
|
||||
*
|
||||
* The Delaunay Triangulation on the data points is build and for
|
||||
* each grid point the triangle where it is enclosed found and a
|
||||
* linear interpolation performed.
|
||||
*
|
||||
* Points exterior to the convex hull of the data points cannot
|
||||
* be interpolated and are set to NaN.
|
||||
*/
|
||||
|
||||
static void
|
||||
grid_dtli(PLFLT *x, PLFLT *y, PLFLT *z, int npts,
|
||||
PLFLT *xg, int nptsx, PLFLT *yg, int nptsy, PLFLT **zg)
|
||||
{
|
||||
point *pin, *pgrid, *pt;
|
||||
PLFLT *xt, *yt, *zt;
|
||||
int i, j, nptsg;
|
||||
|
||||
if (sizeof(realT) != sizeof(double)) {
|
||||
plabort("plgridata: QHull was compiled for floats instead of doubles");
|
||||
return;
|
||||
}
|
||||
|
||||
pin = (point *) malloc(npts * sizeof(point));
|
||||
|
||||
xt = x; yt = y; zt = z; pt = pin;
|
||||
for(i=0; i<npts; i++) {
|
||||
pt->x = (double) *xt++;
|
||||
pt->y = (double) *yt++;
|
||||
pt->z = (double) *zt++;
|
||||
pt++;
|
||||
}
|
||||
|
||||
nptsg = nptsx * nptsy;
|
||||
pgrid = (point *) malloc(nptsg * sizeof(point));
|
||||
|
||||
yt = yg; pt = pgrid;
|
||||
for(j=0; j<nptsy; j++) {
|
||||
xt = xg;
|
||||
for(i=0; i<nptsx; i++) {
|
||||
pt->x = (double) *xt++;
|
||||
pt->y = (double) *yt;
|
||||
pt++;
|
||||
}
|
||||
yt++;
|
||||
}
|
||||
|
||||
lpi_interpolate_points(npts, pin, nptsg, pgrid);
|
||||
for(i=0; i<nptsx; i++) {
|
||||
for(j=0; j<nptsy; j++) {
|
||||
pt = &pgrid[j*nptsx + i];
|
||||
zg[i][j] = (PLFLT) pt->z;
|
||||
}
|
||||
}
|
||||
|
||||
free(pin);
|
||||
free(pgrid);
|
||||
}
|
||||
|
||||
/*
|
||||
* Natural Neighbors using Pavel Sakov's nn package
|
||||
*
|
||||
* Points exterior to the convex hull of the data points cannot
|
||||
* be interpolated and are set to NaN.
|
||||
*/
|
||||
|
||||
static void
|
||||
grid_nni (PLFLT *x, PLFLT *y, PLFLT *z, int npts,
|
||||
PLFLT *xg, int nptsx, PLFLT *yg, int nptsy, PLFLT **zg,
|
||||
PLFLT wmin)
|
||||
{
|
||||
PLFLT *xt, *yt, *zt;
|
||||
point *pin, *pgrid, *pt;
|
||||
int i, j, nptsg;
|
||||
nn_algorithm = NON_SIBSONIAN;
|
||||
|
||||
if (sizeof(realT) != sizeof(double)) {
|
||||
plabort("plgridata: QHull was compiled for floats instead of doubles");
|
||||
return;
|
||||
}
|
||||
|
||||
if (wmin == 0.) {/* only accept weights greater than wmin */
|
||||
plwarn("plgriddata(): GRID_NNI: wmin must be specified with 'data' arg. Using -PLFLT_MAX");
|
||||
wmin = -PLFLT_MAX;
|
||||
}
|
||||
|
||||
pin = (point *) malloc(npts * sizeof(point));
|
||||
|
||||
xt = x; yt = y; zt = z; pt = pin;
|
||||
for(i=0; i<npts; i++) {
|
||||
pt->x = (double) *xt++;
|
||||
pt->y = (double) *yt++;
|
||||
pt->z = (double) *zt++;
|
||||
pt++;
|
||||
}
|
||||
|
||||
nptsg = nptsx * nptsy;
|
||||
pgrid = (point *) malloc(nptsg * sizeof(point));
|
||||
|
||||
yt = yg; pt = pgrid;
|
||||
for(j=0; j<nptsy; j++) {
|
||||
xt = xg;
|
||||
for(i=0; i<nptsx; i++) {
|
||||
pt->x = (double) *xt++;
|
||||
pt->y = (double) *yt;
|
||||
pt++;
|
||||
}
|
||||
yt++;
|
||||
}
|
||||
|
||||
nnpi_interpolate_points(npts, pin, wmin, nptsg, pgrid);
|
||||
for(i=0; i<nptsx; i++) {
|
||||
for(j=0; j<nptsy; j++) {
|
||||
pt = &pgrid[j*nptsx + i];
|
||||
zg[i][j] = (PLFLT) pt->z;
|
||||
}
|
||||
}
|
||||
|
||||
free(pin);
|
||||
free(pgrid);
|
||||
}
|
||||
#endif /* HAVE_QHULL*/
|
||||
|
||||
/*
|
||||
* this function just calculates the K Nearest Neighbors of grid point
|
||||
* [gx, gy].
|
||||
*/
|
||||
|
||||
static void
|
||||
dist1(PLFLT gx, PLFLT gy, PLFLT *x, PLFLT *y, int npts, int knn_order)
|
||||
{
|
||||
|
||||
PLFLT d, max_dist;
|
||||
int max_slot, i, j;
|
||||
|
||||
max_dist = PLFLT_MAX;
|
||||
max_slot = 0;
|
||||
|
||||
for (i=0; i<knn_order; i++) {
|
||||
items[i].dist = PLFLT_MAX;
|
||||
items[i].item = -1;
|
||||
}
|
||||
|
||||
for (i=0; i<npts; i++) {
|
||||
d = ((gx - x[i])*(gx - x[i]) + (gy - y[i])*(gy - y[i])); /* save sqrt() time */
|
||||
|
||||
if (d < max_dist) {
|
||||
/* found an item with a distance smaller than the
|
||||
* maximum distance found so far. Replace.
|
||||
*/
|
||||
|
||||
items[max_slot].dist = d;
|
||||
items[max_slot].item = i;
|
||||
|
||||
/* find new maximum distance */
|
||||
max_dist = items[0].dist;
|
||||
max_slot = 0;
|
||||
for (j=1; j<knn_order; j++) {
|
||||
if (items[j].dist > max_dist) {
|
||||
max_dist = items[j].dist;
|
||||
max_slot = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (j=0; j<knn_order; j++)
|
||||
items[j].dist = sqrt(items[j].dist); /* now calculate the distance */
|
||||
}
|
||||
|
||||
/*
|
||||
* This function searchs the 1-nearest neighbor in each quadrant around
|
||||
* the grid point.
|
||||
*/
|
||||
|
||||
static void
|
||||
dist2(PLFLT gx, PLFLT gy, PLFLT *x, PLFLT *y, int npts)
|
||||
{
|
||||
|
||||
PLFLT d;
|
||||
int i, quad;
|
||||
|
||||
for (i=0; i<4; i++) {
|
||||
items[i].dist = PLFLT_MAX;
|
||||
items[i].item = -1;
|
||||
}
|
||||
|
||||
for (i=0; i<npts; i++) {
|
||||
d = ((gx - x[i])*(gx - x[i]) + (gy - y[i])*(gy - y[i])); /* save sqrt() time */
|
||||
|
||||
/* trick to quickly compute a quadrant. The determined quadrants will be
|
||||
* miss-assigned, i.e., 1->2, 2->0, 3->1, 4->3, but that is not important,
|
||||
* speed is. */
|
||||
|
||||
quad = 2*(x[i] > gx) + (y[i] < gy);
|
||||
|
||||
/* try to use the octants around the grid point, as it will give smoother
|
||||
* (and slower) results.
|
||||
* Hint: use the quadrant info plus x[i]/y[i] to determine the octant */
|
||||
|
||||
if (d < items[quad].dist) {
|
||||
items[quad].dist = d;
|
||||
items[quad].item = i;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0; i<4; i++)
|
||||
if (items[i].item != -1)
|
||||
items[i].dist = sqrt(items[i].dist); /* now calculate the distance */
|
||||
}
|
||||
|
||||
#ifdef NONN /* another DTLI, based only on QHULL, not nn */
|
||||
static void
|
||||
grid_adtli (PLFLT *x, PLFLT *y, PLFLT *z, int npts,
|
||||
PLFLT *xg, int nptsx, PLFLT *yg, int nptsy, PLFLT **zg)
|
||||
{
|
||||
coordT *points; /* array of coordinates for each point */
|
||||
boolT ismalloc = False; /* True if qhull should free points */
|
||||
char flags[250]; /* option flags for qhull */
|
||||
facetT *facet; /* set by FORALLfacets */
|
||||
vertexT *vertex, **vertexp;
|
||||
facetT *neighbor,**neighborp;
|
||||
int curlong, totlong; /* memory remaining after qh_memfreeshort */
|
||||
FILE *outfile = NULL;
|
||||
FILE *errfile = stderr; /* error messages from qhull code */
|
||||
|
||||
int exitcode;
|
||||
int i, j, k, l;
|
||||
int dim = 2;
|
||||
PLFLT xt[3], yt[3], zt[3];
|
||||
PLFLT A, B, C, D;
|
||||
coordT point[3];
|
||||
boolT isoutside;
|
||||
realT bestdist;
|
||||
int totpart=0;
|
||||
int numfacets, numsimplicial, numridges;
|
||||
int totneighbors, numcoplanars, numtricoplanars;
|
||||
|
||||
plwarn("plgriddata: GRID_DTLI, If you have QHull knowledge, FIXME.");
|
||||
|
||||
/* Could pass extra args to qhull through the 'data' argument of
|
||||
plgriddata() */
|
||||
sprintf(flags, "qhull d Qbb Qt");
|
||||
points = (coordT *) malloc(npts * (dim+1) * sizeof(coordT));
|
||||
|
||||
for (i=0; i<npts; i++) {
|
||||
points[i*dim] = x[i];
|
||||
points[i*dim+1] = y[i];
|
||||
}
|
||||
|
||||
#if 1 /* easy way */
|
||||
exitcode = qh_new_qhull (dim, npts, points, ismalloc,
|
||||
flags, outfile, errfile);
|
||||
#else
|
||||
qh_init_A (stdin, stdout, stderr, 0, NULL);
|
||||
exitcode = setjmp (qh errexit);
|
||||
if (!exitcode) {
|
||||
qh_initflags (flags);
|
||||
qh PROJECTdelaunay = True;
|
||||
qh_init_B (points, npts, dim, ismalloc);
|
||||
qh_qhull();
|
||||
}
|
||||
#endif
|
||||
if (!exitcode) { /* if no error */
|
||||
|
||||
#if 0 /* print the triangles vertices */
|
||||
printf("Triangles\n");
|
||||
FORALLfacets {
|
||||
if (!facet->upperdelaunay) {
|
||||
FOREACHvertex_(facet->vertices)
|
||||
printf (" %d", qh_pointid (vertex->point)); /* vertices index */
|
||||
printf ("\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0 /* print each triangle neighbors */
|
||||
printf("Neigbors\n");
|
||||
|
||||
qh_findgood_all (qh facet_list);
|
||||
qh_countfacets (qh facet_list, NULL, !qh_ALL, &numfacets, &numsimplicial,
|
||||
&totneighbors, &numridges, &numcoplanars, &numtricoplanars);
|
||||
|
||||
FORALLfacets {
|
||||
if (!facet->upperdelaunay) {
|
||||
FOREACHneighbor_(facet)
|
||||
printf (" %d", neighbor->visitid ? neighbor->visitid - 1: - neighbor->id);
|
||||
printf ("\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Without the setjmp(), Qhull will exit() after reporting an error */
|
||||
exitcode = setjmp (qh errexit);
|
||||
if (!exitcode) {
|
||||
qh NOerrexit= False;
|
||||
for(i=0; i<nptsx; i++)
|
||||
for(j=0; j<nptsy; j++){
|
||||
l = 0;
|
||||
point[0] = xg[i];
|
||||
point[1] = yg[j];
|
||||
qh_setdelaunay (3, 1, point);
|
||||
|
||||
|
||||
/* several ways to find the triangle given a point follow.
|
||||
None but brute force works */
|
||||
#if 0
|
||||
facet = qh_findbestfacet (point, qh_ALL, &bestdist, &isoutside);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
facet = qh_findbest (point, qh facet_list, qh_ALL,
|
||||
!qh_ISnewfacets, /*qh_ALL*/ qh_NOupper,
|
||||
&bestdist, &isoutside, &totpart);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
vertex = qh_nearvertex (facet, point, &bestdist);
|
||||
#endif
|
||||
|
||||
/* Until someone implements a working qh_findbestfacet(),
|
||||
* do an exautive search!
|
||||
*
|
||||
* As far as I understand it, qh_findbestfacet() and
|
||||
* qh_findbest() fails when 'point' does not belongs to
|
||||
* the convex hull, i.e., when the search becomes blocked
|
||||
* when a facet is upperdelaunay (although the error
|
||||
* message says that the facet may be upperdelaynay or
|
||||
* flipped, I never found a flipped one).
|
||||
*
|
||||
* Another possibility is to implement the 'walking
|
||||
* triangle algorithm */
|
||||
|
||||
facet = qh_findfacet_all( point, &bestdist, &isoutside, &totpart );
|
||||
|
||||
if (facet->upperdelaunay)
|
||||
zg[i][j] = NaN;
|
||||
else {
|
||||
FOREACHvertex_(facet->vertices) {
|
||||
k = qh_pointid(vertex->point);
|
||||
xt[l] = x[k];
|
||||
yt[l] = y[k];
|
||||
zt[l] = z[k];
|
||||
l++;
|
||||
}
|
||||
|
||||
/* calculate the plane passing through the three points */
|
||||
|
||||
A = yt[0]*(zt[1]-zt[2]) + yt[1]*(zt[2]-zt[0]) + yt[2]*(zt[0]-zt[1]);
|
||||
B = zt[0]*(xt[1]-xt[2]) + zt[1]*(xt[2]-xt[0]) + zt[2]*(xt[0]-xt[1]);
|
||||
C = xt[0]*(yt[1]-yt[2]) + xt[1]*(yt[2]-yt[0]) + xt[2]*(yt[0]-yt[1]);
|
||||
D = - A*xt[0] - B*yt[0] - C*zt[0];
|
||||
|
||||
/* and interpolate */
|
||||
zg[i][j] = - xg[i]*A/C - yg[j]*B/C - D/C;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
qh NOerrexit= True;
|
||||
}
|
||||
|
||||
free(points);
|
||||
qh_freeqhull(!qh_ALL); /* free long memory */
|
||||
qh_memfreeshort (&curlong, &totlong); /* free short memory and memory allocator */
|
||||
if (curlong || totlong)
|
||||
fprintf (errfile,
|
||||
"qhull: did not free %d bytes of long memory (%d pieces)\n",
|
||||
totlong, curlong);
|
||||
}
|
||||
#endif /* NONN */
|
|
@ -1,180 +0,0 @@
|
|||
/* $Id: plhist.c,v 1.1 2004/03/01 20:54:52 cozmic Exp $
|
||||
|
||||
Histogram plotter.
|
||||
*/
|
||||
|
||||
#include "plplotP.h"
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plhist()
|
||||
*
|
||||
* Draws a histogram of n values of a variable in array data[0..n-1] in
|
||||
* the range datmin to datmax using nbin bins. If "flags"'s first bit is 1, the
|
||||
* histogram is plotted in the current window. If not, the routine calls
|
||||
* "plenv" to set up the graphics environment.
|
||||
*
|
||||
* If flags's second bit is set, then items which fall outside the bin
|
||||
* range are ignored.
|
||||
*
|
||||
* If flags's third bit is set, the outside bars are the same size
|
||||
* as the rest. The default old behaviour was for the first and last
|
||||
* bars to expand visually to fill the entire available space.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plhist(PLINT n, PLFLT *data, PLFLT datmin, PLFLT datmax,
|
||||
PLINT nbin, PLINT flags)
|
||||
{
|
||||
PLINT i, bin;
|
||||
PLFLT *x, *y, dx, ymax;
|
||||
|
||||
if (plsc->level < 1) {
|
||||
plabort("plhist: Please call plinit first");
|
||||
return;
|
||||
}
|
||||
if (plsc->level < 3 && (flags & 1)) {
|
||||
plabort("plhist: Please set up window first");
|
||||
return;
|
||||
}
|
||||
if (datmin >= datmax) {
|
||||
plabort("plhist: Data range invalid");
|
||||
return;
|
||||
}
|
||||
if ( ! (x = (PLFLT *) malloc((size_t) nbin * sizeof(PLFLT)))) {
|
||||
plabort("plhist: Out of memory");
|
||||
return;
|
||||
}
|
||||
if ( ! (y = (PLFLT *) malloc((size_t) nbin * sizeof(PLFLT)))) {
|
||||
free((void *) x);
|
||||
plabort("plhist: Out of memory");
|
||||
return;
|
||||
}
|
||||
|
||||
dx = (datmax - datmin) / nbin;
|
||||
for (i = 0; i < nbin; i++) {
|
||||
x[i] = datmin + i * dx;
|
||||
y[i] = 0.0;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
bin = (data[i] - datmin) / dx;
|
||||
if ((flags & 2) == 0) {
|
||||
bin = bin > 0 ? bin : 0;
|
||||
bin = bin < nbin ? bin : nbin - 1;
|
||||
y[bin]++;
|
||||
} else {
|
||||
if(bin >= 0 && bin < nbin) {
|
||||
y[bin]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!(flags & 1)) {
|
||||
ymax = 0.0;
|
||||
for (i = 0; i < nbin; i++)
|
||||
ymax = MAX(ymax, y[i]);
|
||||
|
||||
plenv(datmin, datmax, (PLFLT) 0.0, (PLFLT) (1.1 * ymax), 0, 0);
|
||||
}
|
||||
/* We pass on the highest couple of bits to the 'plbin' routine */
|
||||
plbin(nbin, x, y, (flags & (4+8+16+32)) >> 2);
|
||||
free((void *) x);
|
||||
free((void *) y);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plbin()
|
||||
*
|
||||
* Plot a histogram using the arrays x and y to represent data values
|
||||
* and frequencies respectively. If flags first bit is false, x values
|
||||
* denote the lower edge of the bin, and if it is true, they denote
|
||||
* the center of the bin. If flags second bit is true, then we assume
|
||||
* the edge bins are the same size as the rest (i.e. the edge bins
|
||||
* needn't go as far as the variables vpwxmi, vpwxma below).
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plbin(PLINT nbin, PLFLT *x, PLFLT *y, PLINT flags)
|
||||
{
|
||||
PLINT i;
|
||||
PLFLT xmin, xmax, vpwxmi, vpwxma, vpwymi, vpwyma;
|
||||
|
||||
if (plsc->level < 3) {
|
||||
plabort("plbin: Please set up window first");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check x[i] are in ascending order */
|
||||
|
||||
for (i = 0; i < nbin - 1; i++) {
|
||||
if (x[i] >= x[i + 1]) {
|
||||
plabort("plbin: Elements of x array must be increasing");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
plgvpw(&vpwxmi, &vpwxma, &vpwymi, &vpwyma);
|
||||
if (!(flags & 1)) {
|
||||
for (i = 0; i < nbin - 1; i++) {
|
||||
if (!(flags & 4) || (y[i] != vpwymi)) {
|
||||
pljoin(x[i], vpwymi, x[i], y[i]);
|
||||
pljoin(x[i], y[i], x[i + 1], y[i]);
|
||||
pljoin(x[i + 1], y[i], x[i + 1], vpwymi);
|
||||
}
|
||||
}
|
||||
if (flags & 2) {
|
||||
if (!(flags & 4) || (y[i] != vpwymi)) {
|
||||
int xm = x[i] + (x[i] - x[i-1]);
|
||||
pljoin(x[i], vpwymi, x[i], y[i]);
|
||||
pljoin(x[i], y[i], xm, y[i]);
|
||||
pljoin(xm, y[i], xm, vpwymi);
|
||||
}
|
||||
} else {
|
||||
if (x[i] < vpwxma) {
|
||||
if (!(flags & 4) || (y[i] != vpwymi)) {
|
||||
pljoin(x[i], vpwymi, x[i], y[i]);
|
||||
pljoin(x[i], y[i], vpwxma, y[i]);
|
||||
pljoin(vpwxma, y[i], vpwxma, vpwymi);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (nbin < 2)
|
||||
return;
|
||||
if (flags & 2) {
|
||||
xmin = MAX(vpwxmi, 0.5 * (3 * x[0] - x[1]));
|
||||
} else {
|
||||
xmin = vpwxmi;
|
||||
}
|
||||
/* Vince fixed bug May 1998 */
|
||||
xmax = MAX(0.5 * (x[0] + x[1]), vpwxmi);
|
||||
if (xmin < xmax) {
|
||||
pljoin(xmin, vpwymi, xmin, y[0]);
|
||||
pljoin(xmin, y[0], xmax, y[0]);
|
||||
pljoin(xmax, y[0], xmax, vpwymi);
|
||||
}
|
||||
for (i = 1; i < nbin - 1; i++) {
|
||||
xmin = xmax;
|
||||
xmax = MIN(0.5 * (x[i] + x[i + 1]), vpwxma);
|
||||
if (!(flags & 4) || (y[i] != vpwymi)) {
|
||||
pljoin(xmin, vpwymi, xmin, y[i]);
|
||||
pljoin(xmin, y[i], xmax, y[i]);
|
||||
pljoin(xmax, y[i], xmax, vpwymi);
|
||||
}
|
||||
}
|
||||
xmin = xmax;
|
||||
xmax = vpwxma;
|
||||
if (flags & 2) {
|
||||
xmax = MIN(vpwxma, 0.5 * (3 * x[i] - x[i-1]));
|
||||
} else {
|
||||
xmax = vpwxma;
|
||||
}
|
||||
if (xmin < xmax) {
|
||||
if (!(flags & 4) || (y[i] != vpwymi)) {
|
||||
pljoin(xmin, vpwymi, xmin, y[i]);
|
||||
pljoin(xmin, y[i], xmax, y[i]);
|
||||
pljoin(xmax, y[i], xmax, vpwymi);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,235 +0,0 @@
|
|||
/* plimage()
|
||||
*
|
||||
* Author: Alessandro Mirone, Nov 2001
|
||||
* Adapted: Joao Cardoso
|
||||
*/
|
||||
|
||||
#include "plplotP.h"
|
||||
|
||||
/* Get better names, those are too criptic!
|
||||
*
|
||||
* ZEROW2B: zero writing to buffer ?
|
||||
* ZEROW2D: zero writing to display ?
|
||||
* ONEW2B: set writing to buffer ?
|
||||
* ONEW2D: set writing to display ?
|
||||
*/
|
||||
|
||||
void
|
||||
NoBufferNoPixmap()
|
||||
{
|
||||
PLINT op = ZEROW2B;
|
||||
|
||||
plsc->plbuf_write = 0; /* TODO: store previous state */
|
||||
plP_esc(PLESC_EXPOSE, NULL);
|
||||
plP_esc(PLESC_IMAGEOPS, &op);
|
||||
}
|
||||
|
||||
void
|
||||
RestoreWrite2BufferPixmap()
|
||||
{
|
||||
PLINT op = ONEW2B;
|
||||
|
||||
plsc->plbuf_write = 1; /* TODO: revert from previous state */
|
||||
plP_esc(PLESC_IMAGEOPS, &op);
|
||||
}
|
||||
|
||||
void
|
||||
disabledisplay()
|
||||
{
|
||||
PLINT op = ZEROW2D;
|
||||
|
||||
plP_esc(PLESC_IMAGEOPS, &op);
|
||||
}
|
||||
|
||||
void
|
||||
enabledisplay()
|
||||
{
|
||||
PLINT op = ONEW2D;
|
||||
|
||||
plP_esc(PLESC_IMAGEOPS, &op);
|
||||
plP_esc(PLESC_EXPOSE, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
plimageslow(short *x, short *y, unsigned short *data, PLINT nx, PLINT ny,
|
||||
PLFLT xmin, PLFLT ymin, PLFLT dx, PLFLT dy,
|
||||
unsigned short zmin, unsigned short zmax)
|
||||
{
|
||||
PLINT ix, iy, i;
|
||||
PLFLT xf[4], yf[4];
|
||||
short xs[5], ys[5];
|
||||
int corners[4];
|
||||
unsigned short col;
|
||||
|
||||
for (ix = 0; ix < nx ; ix++) {
|
||||
for (iy = 0; iy < ny ; iy++) {
|
||||
|
||||
col = data[ix*ny+iy];
|
||||
/* only plot points within zmin/zmax range */
|
||||
if (col < zmin || col > zmax)
|
||||
continue;
|
||||
|
||||
plcol1(col/(float)USHRT_MAX);
|
||||
|
||||
if (plsc->plbuf_read == 1) {
|
||||
/* buffer read, is a replot to a slow device. */
|
||||
|
||||
corners[0] = ix*(ny+1)+iy; /* [ix][iy] */
|
||||
corners[1] = (ix+1)*(ny+1)+iy; /* [ix+1][iy] */
|
||||
corners[2] = (ix+1)*(ny+1)+iy+1; /* [ix+1][iy+1] */
|
||||
corners[3] = ix*(ny+1)+iy+1; /* [ix][iy+1] */
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
xs[i] = x[corners[i]];
|
||||
ys[i] = y[corners[i]];
|
||||
}
|
||||
xs[4] = xs[0]; ys[4] = ys[0];
|
||||
plP_fill(xs, ys, 5);
|
||||
|
||||
} else {
|
||||
|
||||
xf[0] = xf[1] = ix;
|
||||
xf[2] = xf[3] = ix+1;
|
||||
yf[0] = yf[3] = iy;
|
||||
yf[1] = yf[2] = iy+1;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
xf[i] = xmin + xf[i]*dx;
|
||||
yf[i] = ymin + yf[i]*dy;
|
||||
}
|
||||
plfill(4, xf, yf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
grimage(short *x, short *y, unsigned short *z, PLINT nx, PLINT ny)
|
||||
{
|
||||
plsc->dev_ix = x;
|
||||
plsc->dev_iy = y;
|
||||
plsc->dev_z = z;
|
||||
plsc->dev_nptsX = nx;
|
||||
plsc->dev_nptsY = ny;
|
||||
|
||||
plP_esc(PLESC_IMAGE, NULL);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* plimage
|
||||
* (***** SUBJECT TO CHANGE ******)
|
||||
*
|
||||
* arguments are
|
||||
* data: array containing image data
|
||||
* nx: dimension of the array in the X axis.
|
||||
* ny: dimension of the array in the Y axis
|
||||
* The array data is indexed like data[ix][iy]
|
||||
*
|
||||
* xmin, xmax, ymin, ymax:
|
||||
* data[0][0] corresponds to (xmin,ymin)
|
||||
* data[nx-1][ny-1] to (xmax,ymax)
|
||||
*
|
||||
* zmin, zmax:
|
||||
* only data within bounds zmin <= data <= zmax will be
|
||||
* plotted. If zmin == zmax, all data will be ploted.
|
||||
*
|
||||
* Dxmin, Dxmax, Dymin, Dymax:
|
||||
* plots only the window of points whose(x,y)'s fall
|
||||
* inside the [Dxmin->Dxmax]X[Dymin->Dymax] window
|
||||
*
|
||||
\*-------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plimage(PLFLT **idata, PLINT nx, PLINT ny,
|
||||
PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
|
||||
PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax)
|
||||
{
|
||||
PLINT nnx, nny, ix, iy, ixx, iyy, xm, ym;
|
||||
PLFLT dx, dy;
|
||||
unsigned short *Zf, szmin, szmax;
|
||||
short *Xf, *Yf;
|
||||
PLFLT lzmin, lzmax, tz;
|
||||
|
||||
if (plsc->level < 3) {
|
||||
plabort("plimage: window must be set up first");
|
||||
return;
|
||||
}
|
||||
|
||||
if (nx <= 0 || ny <= 0) {
|
||||
plabort("plimage: nx and ny must be positive");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Dxmin < xmin || Dxmax > xmax || Dymin < ymin || Dymax > ymax){
|
||||
plabort("plimage: Dxmin or Dxmax or Dymin or Dymax not compatible with xminor xmax or ymin or ymax.");
|
||||
return;
|
||||
}
|
||||
|
||||
dx = (xmax - xmin) / (nx - 1);
|
||||
dy = (ymax - ymin) / (ny - 1);
|
||||
nnx = (Dxmax-Dxmin)/dx + 1;
|
||||
nny = (Dymax-Dymin)/dy + 1;
|
||||
|
||||
Zf = (unsigned short *) malloc(nny*nnx*sizeof(unsigned short));
|
||||
|
||||
xm = floor((Dxmin-xmin)/dx); ym = floor((Dymin-ymin)/dy);
|
||||
lzmin = lzmax = idata[xm][ym];
|
||||
|
||||
for (ix=xm; ix<xm+nnx; ix++) {
|
||||
for (iy=ym; iy<ym+nny; iy++) {
|
||||
tz = idata[ix][iy];
|
||||
if (lzmax < tz)
|
||||
lzmax = tz;
|
||||
if (lzmin > tz)
|
||||
lzmin = tz;
|
||||
}
|
||||
}
|
||||
|
||||
ixx=-1;
|
||||
for (ix=xm; ix<xm+nnx; ix++) {
|
||||
ixx++; iyy=0;
|
||||
for (iy=ym; iy<ym+nny; iy++)
|
||||
Zf[ixx*nny+iyy++] = (idata[ix][iy] - lzmin)/(lzmax-lzmin)*USHRT_MAX;
|
||||
}
|
||||
|
||||
if (zmin == zmax) {
|
||||
zmin = lzmin;
|
||||
zmax = lzmax;
|
||||
} else {
|
||||
if (zmin < lzmin)
|
||||
zmin = lzmin;
|
||||
|
||||
if (zmax > lzmax)
|
||||
zmax = lzmax;
|
||||
}
|
||||
|
||||
szmin = (zmin - lzmin)/(lzmax-lzmin)*USHRT_MAX;
|
||||
szmax = (zmax - lzmin)/(lzmax-lzmin)*USHRT_MAX;
|
||||
|
||||
xmin = Dxmin; xmax = Dxmax;
|
||||
ymin = Dymin; ymax = Dymax;
|
||||
|
||||
/* The X and Y arrays has size nnx*nny */
|
||||
nnx++; nny++;
|
||||
|
||||
Xf = (short *) malloc(nny*nnx*sizeof(short));
|
||||
Yf = (short *) malloc(nny*nnx*sizeof(short));
|
||||
|
||||
/* adjust the step for the X/Y arrays */
|
||||
dx = dx*(nx-1)/nx;
|
||||
dy = dy*(ny-1)/ny;
|
||||
|
||||
for (ix = 0; ix < nnx; ix++)
|
||||
for (iy = 0; iy < nny; iy++) {
|
||||
Xf[ix*nny+iy] = plP_wcpcx(xmin + ix*dx);
|
||||
Yf[ix*nny+iy] = plP_wcpcy(ymin + iy*dy);
|
||||
}
|
||||
|
||||
plP_image(Xf, Yf, Zf, nnx, nny, xmin, ymin, dx, dy, szmin, szmax);
|
||||
|
||||
free(Xf);
|
||||
free(Yf);
|
||||
free(Zf);
|
||||
}
|
|
@ -1,927 +0,0 @@
|
|||
/* $Id: plline.c,v 1.2 2005/03/17 21:39:21 eli Exp $
|
||||
|
||||
Routines dealing with line generation.
|
||||
*/
|
||||
|
||||
#include "plplotP.h"
|
||||
|
||||
#define INSIDE(ix,iy) (BETW(ix,xmin,xmax) && BETW(iy,ymin,ymax))
|
||||
|
||||
static PLINT xline[PL_MAXPOLY], yline[PL_MAXPOLY];
|
||||
|
||||
static PLINT lastx = PL_UNDEFINED, lasty = PL_UNDEFINED;
|
||||
|
||||
/* Function prototypes */
|
||||
|
||||
/* Draws a polyline within the clip limits. */
|
||||
|
||||
static void
|
||||
pllclp(PLINT *x, PLINT *y, PLINT npts);
|
||||
|
||||
/* Get clipped endpoints */
|
||||
|
||||
static int
|
||||
clipline(PLINT *p_x1, PLINT *p_y1, PLINT *p_x2, PLINT *p_y2,
|
||||
PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax);
|
||||
|
||||
/* General line-drawing routine. Takes line styles into account. */
|
||||
|
||||
static void
|
||||
genlin(short *x, short *y, PLINT npts);
|
||||
|
||||
/* Draws a dashed line to the specified point from the previous one. */
|
||||
|
||||
static void
|
||||
grdashline(short *x, short *y);
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void pljoin()
|
||||
*
|
||||
* Draws a line segment from (x1, y1) to (x2, y2).
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
MZ_DLLEXPORT
|
||||
void
|
||||
c_pljoin(PLFLT x1, PLFLT y1, PLFLT x2, PLFLT y2)
|
||||
{
|
||||
plP_movwor(x1, y1);
|
||||
plP_drawor(x2, y2);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plline()
|
||||
*
|
||||
* Draws line segments connecting a series of points.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
MZ_DLLEXPORT
|
||||
void
|
||||
c_plline(PLINT n, PLFLT *x, PLFLT *y)
|
||||
{
|
||||
if (plsc->level < 3) {
|
||||
plabort("plline: Please set up window first");
|
||||
return;
|
||||
}
|
||||
plP_drawor_poly(x, y, n);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plline3(n, x, y, z)
|
||||
*
|
||||
* Draws a line in 3 space. You must first set up the viewport, the
|
||||
* 2d viewing window (in world coordinates), and the 3d normalized
|
||||
* coordinate box. See x18c.c for more info.
|
||||
*
|
||||
* This version adds clipping against the 3d bounding box specified in plw3d
|
||||
|
||||
MZ_DLLEXPORT\*----------------------------------------------------------------------*/
|
||||
void
|
||||
c_plline3(PLINT n, PLFLT *x, PLFLT *y, PLFLT *z)
|
||||
{
|
||||
int i;
|
||||
PLFLT vmin[3], vmax[3], zscale;
|
||||
|
||||
if (plsc->level < 3) {
|
||||
plabort("plline3: Please set up window first");
|
||||
return;
|
||||
}
|
||||
|
||||
/* get the bounding box in 3d */
|
||||
plP_gdom(&vmin[0], &vmax[0], &vmin[1], &vmax[1]);
|
||||
plP_grange(&zscale, &vmin[2], &vmax[2]);
|
||||
|
||||
/* interate over the vertices */
|
||||
for( i=0; i < n-1; i++ ) {
|
||||
PLFLT p0[3], p1[3];
|
||||
int axis;
|
||||
|
||||
/* copy the end points of the segment to allow clipping */
|
||||
p0[0] = x[i]; p0[1] = y[i]; p0[2] = z[i];
|
||||
p1[0] = x[i+1]; p1[1] = y[i+1]; p1[2] = z[i+1];
|
||||
|
||||
/* check against each axis of the bounding box */
|
||||
for(axis = 0; axis < 3; axis++) {
|
||||
if(p0[axis] < vmin[axis]) { /* first out */
|
||||
if(p1[axis] < vmin[axis]) {
|
||||
break; /* both endpoints out so quit */
|
||||
} else {
|
||||
int j;
|
||||
/* interpolate to find intersection with box */
|
||||
PLFLT t = (vmin[axis] - p0[axis]) / (p1[axis] - p0[axis]);
|
||||
p0[axis] = vmin[axis];
|
||||
for(j = 1; j<3; j++) {
|
||||
int k = (axis+j)%3;
|
||||
p0[k] = (1-t)*p0[k] + t*p1[k];
|
||||
}
|
||||
}
|
||||
} else if(p1[axis] < vmin[axis]) { /* second out */
|
||||
int j;
|
||||
/* interpolate to find intersection with box */
|
||||
PLFLT t = (vmin[axis] - p0[axis]) / (p1[axis] - p0[axis]);
|
||||
p1[axis] = vmin[axis];
|
||||
for(j = 1; j<3; j++) {
|
||||
int k = (axis+j)%3;
|
||||
p1[k] = (1-t)*p0[k] + t*p1[k];
|
||||
}
|
||||
}
|
||||
if(p0[axis] > vmax[axis]) { /* first out */
|
||||
if(p1[axis] > vmax[axis]) {
|
||||
break; /* both out so quit */
|
||||
} else {
|
||||
int j;
|
||||
/* interpolate to find intersection with box */
|
||||
PLFLT t = (vmax[axis] - p0[axis]) / (p1[axis] - p0[axis]);
|
||||
p0[axis] = vmax[axis];
|
||||
for(j = 1; j<3; j++) {
|
||||
int k = (axis+j)%3;
|
||||
p0[k] = (1-t)*p0[k] + t*p1[k];
|
||||
}
|
||||
}
|
||||
} else if(p1[axis] > vmax[axis]) { /* second out */
|
||||
int j;
|
||||
/* interpolate to find intersection with box */
|
||||
PLFLT t = (vmax[axis] - p0[axis]) / (p1[axis] - p0[axis]);
|
||||
p1[axis] = vmax[axis];
|
||||
for(j = 1; j<3; j++) {
|
||||
int k = (axis+j)%3;
|
||||
p1[k] = (1-t)*p0[k] + t*p1[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
/* if we made it to here without "break"ing out of the loop, the
|
||||
remaining segment is visible */
|
||||
if( axis == 3 ) { /* not clipped away */
|
||||
PLFLT u0, v0, u1, v1;
|
||||
u0 = plP_wcpcx(plP_w3wcx( p0[0], p0[1], p0[2] ));
|
||||
v0 = plP_wcpcy(plP_w3wcy( p0[0], p0[1], p0[2] ));
|
||||
u1 = plP_wcpcx(plP_w3wcx( p1[0], p1[1], p1[2] ));
|
||||
v1 = plP_wcpcy(plP_w3wcy( p1[0], p1[1], p1[2] ));
|
||||
plP_movphy(u0,v0);
|
||||
plP_draphy(u1,v1);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plpoly3( n, x, y, z, draw, ifcc )
|
||||
*
|
||||
* Draws a polygon in 3 space. This differs from plline3() in that
|
||||
* this attempts to determine if the polygon is viewable. If the back
|
||||
* of polygon is facing the viewer, then it isn't drawn. If this
|
||||
* isn't what you want, then use plline3 instead.
|
||||
*
|
||||
* n specifies the number of points. They are assumed to be in a
|
||||
* plane, and the directionality of the plane is determined from the
|
||||
* first three points. Additional points do not /have/ to lie on the
|
||||
* plane defined by the first three, but if they do not, then the
|
||||
* determiniation of visibility obviously can't be 100% accurate...
|
||||
* So if you're 3 space polygons are too far from planar, consider
|
||||
* breaking them into smaller polygons. "3 points define a plane" :-).
|
||||
*
|
||||
* For ifcc == 1, the directionality of the polygon is determined by assuming
|
||||
* the points are laid out in counter-clockwise order.
|
||||
*
|
||||
* For ifcc == 0, the directionality of the polygon is determined by assuming
|
||||
* the points are laid out in clockwise order.
|
||||
*
|
||||
* BUGS: If one of the first two segments is of zero length, or if
|
||||
* they are colinear, the calculation of visibility has a 50/50 chance
|
||||
* of being correct. Avoid such situations :-). See x18c for an
|
||||
* example of this problem. (Search for "20.1").
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
MZ_DLLEXPORT
|
||||
void
|
||||
c_plpoly3(PLINT n, PLFLT *x, PLFLT *y, PLFLT *z, PLINT *draw, PLINT ifcc)
|
||||
{
|
||||
int i;
|
||||
PLFLT vmin[3], vmax[3], zscale;
|
||||
PLFLT u1, v1, u2, v2, u3, v3;
|
||||
PLFLT c;
|
||||
|
||||
if (plsc->level < 3) {
|
||||
plabort("plpoly3: Please set up window first");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( n < 3 ) {
|
||||
plabort("plpoly3: Must specify at least 3 points");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Now figure out which side this is. */
|
||||
|
||||
u1 = plP_wcpcx(plP_w3wcx( x[0], y[0], z[0] ));
|
||||
v1 = plP_wcpcy(plP_w3wcy( x[0], y[0], z[0] ));
|
||||
|
||||
u2 = plP_wcpcx(plP_w3wcx( x[1], y[1], z[1] ));
|
||||
v2 = plP_wcpcy(plP_w3wcy( x[1], y[1], z[1] ));
|
||||
|
||||
u3 = plP_wcpcx(plP_w3wcx( x[2], y[2], z[2] ));
|
||||
v3 = plP_wcpcy(plP_w3wcy( x[2], y[2], z[2] ));
|
||||
|
||||
c = (u1-u2)*(v3-v2)-(v1-v2)*(u3-u2);
|
||||
|
||||
if ( c *(1 - 2*ifcc) < 0. )
|
||||
return;
|
||||
|
||||
/* get the bounding box in 3d */
|
||||
plP_gdom(&vmin[0], &vmax[0], &vmin[1], &vmax[1]);
|
||||
plP_grange(&zscale, &vmin[2], &vmax[2]);
|
||||
|
||||
/* interate over the vertices */
|
||||
for( i=0; i < n-1; i++ ) {
|
||||
PLFLT p0[3], p1[3];
|
||||
int axis;
|
||||
|
||||
/* copy the end points of the segment to allow clipping */
|
||||
p0[0] = x[i]; p0[1] = y[i]; p0[2] = z[i];
|
||||
p1[0] = x[i+1]; p1[1] = y[i+1]; p1[2] = z[i+1];
|
||||
|
||||
/* check against each axis of the bounding box */
|
||||
for(axis = 0; axis < 3; axis++) {
|
||||
if(p0[axis] < vmin[axis]) { /* first out */
|
||||
if(p1[axis] < vmin[axis]) {
|
||||
break; /* both endpoints out so quit */
|
||||
} else {
|
||||
int j;
|
||||
/* interpolate to find intersection with box */
|
||||
PLFLT t = (vmin[axis] - p0[axis]) / (p1[axis] - p0[axis]);
|
||||
p0[axis] = vmin[axis];
|
||||
for(j = 1; j<3; j++) {
|
||||
int k = (axis+j)%3;
|
||||
p0[k] = (1-t)*p0[k] + t*p1[k];
|
||||
}
|
||||
}
|
||||
} else if(p1[axis] < vmin[axis]) { /* second out */
|
||||
int j;
|
||||
/* interpolate to find intersection with box */
|
||||
PLFLT t = (vmin[axis] - p0[axis]) / (p1[axis] - p0[axis]);
|
||||
p1[axis] = vmin[axis];
|
||||
for(j = 1; j<3; j++) {
|
||||
int k = (axis+j)%3;
|
||||
p1[k] = (1-t)*p0[k] + t*p1[k];
|
||||
}
|
||||
}
|
||||
if(p0[axis] > vmax[axis]) { /* first out */
|
||||
if(p1[axis] > vmax[axis]) {
|
||||
break; /* both out so quit */
|
||||
} else {
|
||||
int j;
|
||||
/* interpolate to find intersection with box */
|
||||
PLFLT t = (vmax[axis] - p0[axis]) / (p1[axis] - p0[axis]);
|
||||
p0[axis] = vmax[axis];
|
||||
for(j = 1; j<3; j++) {
|
||||
int k = (axis+j)%3;
|
||||
p0[k] = (1-t)*p0[k] + t*p1[k];
|
||||
}
|
||||
}
|
||||
} else if(p1[axis] > vmax[axis]) { /* second out */
|
||||
int j;
|
||||
/* interpolate to find intersection with box */
|
||||
PLFLT t = (vmax[axis] - p0[axis]) / (p1[axis] - p0[axis]);
|
||||
p1[axis] = vmax[axis];
|
||||
for(j = 1; j<3; j++) {
|
||||
int k = (axis+j)%3;
|
||||
p1[k] = (1-t)*p0[k] + t*p1[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
/* if we made it to here without "break"ing out of the loop, the
|
||||
remaining segment is visible */
|
||||
if( axis == 3 && draw[i] ) { /* not clipped away */
|
||||
PLFLT u0, v0, u1, v1;
|
||||
u0 = plP_wcpcx(plP_w3wcx( p0[0], p0[1], p0[2] ));
|
||||
v0 = plP_wcpcy(plP_w3wcy( p0[0], p0[1], p0[2] ));
|
||||
u1 = plP_wcpcx(plP_w3wcx( p1[0], p1[1], p1[2] ));
|
||||
v1 = plP_wcpcy(plP_w3wcy( p1[0], p1[1], p1[2] ));
|
||||
plP_movphy(u0,v0);
|
||||
plP_draphy(u1,v1);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plstyl()
|
||||
*
|
||||
* Set up a new line style of "nms" elements, with mark and space
|
||||
* lengths given by arrays "mark" and "space".
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plstyl(PLINT nms, PLINT *mark, PLINT *space)
|
||||
{
|
||||
short int i;
|
||||
|
||||
if (plsc->level < 1) {
|
||||
plabort("plstyl: Please call plinit first");
|
||||
return;
|
||||
}
|
||||
if ((nms < 0) || (nms > 10)) {
|
||||
plabort("plstyl: Broken lines cannot have <0 or >10 elements");
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < nms; i++) {
|
||||
if ((mark[i] < 0) || (space[i] < 0)) {
|
||||
plabort("plstyl: Mark and space lengths must be > 0");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
plsc->nms = nms;
|
||||
for (i = 0; i < nms; i++) {
|
||||
plsc->mark[i] = mark[i];
|
||||
plsc->space[i] = space[i];
|
||||
}
|
||||
|
||||
plsc->curel = 0;
|
||||
plsc->pendn = 1;
|
||||
plsc->timecnt = 0;
|
||||
plsc->alarm = nms > 0 ? mark[0] : 0;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plP_movphy()
|
||||
*
|
||||
* Move to physical coordinates (x,y).
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plP_movphy(PLINT x, PLINT y)
|
||||
{
|
||||
plsc->currx = x;
|
||||
plsc->curry = y;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plP_draphy()
|
||||
*
|
||||
* Draw to physical coordinates (x,y).
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plP_draphy(PLINT x, PLINT y)
|
||||
{
|
||||
xline[0] = plsc->currx;
|
||||
xline[1] = x;
|
||||
yline[0] = plsc->curry;
|
||||
yline[1] = y;
|
||||
|
||||
pllclp(xline, yline, 2);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plP_movwor()
|
||||
*
|
||||
* Move to world coordinates (x,y).
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plP_movwor(PLFLT x, PLFLT y)
|
||||
{
|
||||
plsc->currx = plP_wcpcx(x);
|
||||
plsc->curry = plP_wcpcy(y);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plP_drawor()
|
||||
*
|
||||
* Draw to world coordinates (x,y).
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plP_drawor(PLFLT x, PLFLT y)
|
||||
{
|
||||
xline[0] = plsc->currx;
|
||||
xline[1] = plP_wcpcx(x);
|
||||
yline[0] = plsc->curry;
|
||||
yline[1] = plP_wcpcy(y);
|
||||
|
||||
pllclp(xline, yline, 2);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plP_draphy_poly()
|
||||
*
|
||||
* Draw polyline in physical coordinates.
|
||||
* Need to draw buffers in increments of (PL_MAXPOLY-1) since the
|
||||
* last point must be repeated (for solid lines).
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plP_draphy_poly(PLINT *x, PLINT *y, PLINT n)
|
||||
{
|
||||
PLINT i, j, ib, ilim;
|
||||
|
||||
for (ib = 0; ib < n; ib += PL_MAXPOLY - 1) {
|
||||
ilim = MIN(PL_MAXPOLY, n - ib);
|
||||
|
||||
for (i = 0; i < ilim; i++) {
|
||||
j = ib + i;
|
||||
xline[i] = x[j];
|
||||
yline[i] = y[j];
|
||||
}
|
||||
pllclp(xline, yline, ilim);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plP_drawor_poly()
|
||||
*
|
||||
* Draw polyline in world coordinates.
|
||||
* Need to draw buffers in increments of (PL_MAXPOLY-1) since the
|
||||
* last point must be repeated (for solid lines).
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plP_drawor_poly(PLFLT *x, PLFLT *y, PLINT n)
|
||||
{
|
||||
PLINT i, j, ib, ilim;
|
||||
|
||||
for (ib = 0; ib < n; ib += PL_MAXPOLY - 1) {
|
||||
ilim = MIN(PL_MAXPOLY, n - ib);
|
||||
|
||||
for (i = 0; i < ilim; i++) {
|
||||
j = ib + i;
|
||||
xline[i] = plP_wcpcx(x[j]);
|
||||
yline[i] = plP_wcpcy(y[j]);
|
||||
}
|
||||
pllclp(xline, yline, ilim);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void pllclp()
|
||||
*
|
||||
* Draws a polyline within the clip limits.
|
||||
* Merely a front-end to plP_pllclp().
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
pllclp(PLINT *x, PLINT *y, PLINT npts)
|
||||
{
|
||||
plP_pllclp(x, y, npts, plsc->clpxmi, plsc->clpxma,
|
||||
plsc->clpymi, plsc->clpyma, genlin);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plP_pllclp()
|
||||
*
|
||||
* Draws a polyline within the clip limits.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plP_pllclp(PLINT *x, PLINT *y, PLINT npts,
|
||||
PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax,
|
||||
void (*draw) (short *, short *, PLINT))
|
||||
{
|
||||
PLINT x1, x2, y1, y2;
|
||||
PLINT i, iclp = 0;
|
||||
short xclp[PL_MAXPOLY], yclp[PL_MAXPOLY];
|
||||
int drawable;
|
||||
|
||||
for (i = 0; i < npts - 1; i++) {
|
||||
x1 = x[i];
|
||||
x2 = x[i + 1];
|
||||
y1 = y[i];
|
||||
y2 = y[i + 1];
|
||||
|
||||
drawable = (INSIDE(x1, y1) && INSIDE(x2, y2));
|
||||
if ( ! drawable)
|
||||
drawable = ! clipline(&x1, &y1, &x2, &y2, xmin, xmax, ymin, ymax);
|
||||
|
||||
if (drawable) {
|
||||
|
||||
/* First point of polyline. */
|
||||
|
||||
if (iclp == 0) {
|
||||
xclp[iclp] = x1;
|
||||
yclp[iclp] = y1;
|
||||
iclp++;
|
||||
xclp[iclp] = x2;
|
||||
yclp[iclp] = y2;
|
||||
}
|
||||
|
||||
/* Not first point. Check if first point of this segment matches up to
|
||||
previous point, and if so, add it to the current polyline buffer. */
|
||||
|
||||
else if (x1 == xclp[iclp] && y1 == yclp[iclp]) {
|
||||
iclp++;
|
||||
xclp[iclp] = x2;
|
||||
yclp[iclp] = y2;
|
||||
}
|
||||
|
||||
/* Otherwise it's time to start a new polyline */
|
||||
|
||||
else {
|
||||
if (iclp + 1 >= 2)
|
||||
(*draw)(xclp, yclp, iclp + 1);
|
||||
iclp = 0;
|
||||
xclp[iclp] = x1;
|
||||
yclp[iclp] = y1;
|
||||
iclp++;
|
||||
xclp[iclp] = x2;
|
||||
yclp[iclp] = y2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle remaining polyline */
|
||||
|
||||
if (iclp + 1 >= 2)
|
||||
(*draw)(xclp, yclp, iclp + 1);
|
||||
|
||||
plsc->currx = x[npts-1];
|
||||
plsc->curry = y[npts-1];
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plP_plfclp()
|
||||
*
|
||||
* Fills a polygon within the clip limits.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plP_plfclp(PLINT *x, PLINT *y, PLINT npts,
|
||||
PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax,
|
||||
void (*draw) (short *, short *, PLINT))
|
||||
{
|
||||
PLINT x1, x2, y1, y2;
|
||||
PLINT i, iclp = -1;
|
||||
short xclp[PL_MAXPOLY], yclp[PL_MAXPOLY];
|
||||
int drawable;
|
||||
|
||||
for (i = 0; i < npts - 1; i++) {
|
||||
x1 = x[i];
|
||||
x2 = x[i + 1];
|
||||
y1 = y[i];
|
||||
y2 = y[i + 1];
|
||||
|
||||
drawable = (INSIDE(x1, y1) && INSIDE(x2, y2));
|
||||
if ( ! drawable)
|
||||
drawable = ! clipline(&x1, &y1, &x2, &y2, xmin, xmax, ymin, ymax);
|
||||
|
||||
if (drawable) {
|
||||
|
||||
/* Not first point. If first point of this segment matches up to the
|
||||
previous point, just add it. */
|
||||
|
||||
if (iclp >= 0 && x1 == xclp[iclp] && y1 == yclp[iclp]) {
|
||||
iclp++;
|
||||
xclp[iclp] = x2;
|
||||
yclp[iclp] = y2;
|
||||
}
|
||||
|
||||
/* First point of polyline, OR . */
|
||||
|
||||
/* If not, we need to add both points, to connect the points in the
|
||||
* polygon along the clip boundary. If any of the previous points were
|
||||
* outside one of the 4 corners, assume the corner was encircled and add
|
||||
* it first.
|
||||
*/
|
||||
else {
|
||||
iclp++;
|
||||
xclp[iclp] = x1;
|
||||
yclp[iclp] = y1;
|
||||
|
||||
if ((x1 == xmin && y2 == ymin) ||
|
||||
(x2 == xmin && y1 == ymin)) {
|
||||
iclp++;
|
||||
xclp[iclp] = xmin;
|
||||
yclp[iclp] = ymin;
|
||||
}
|
||||
else if ((x1 == xmax && y2 == ymin) ||
|
||||
(x2 == xmax && y1 == ymin)) {
|
||||
iclp++;
|
||||
xclp[iclp] = xmax;
|
||||
yclp[iclp] = ymin;
|
||||
}
|
||||
else if ((x1 == xmax && y2 == ymax) ||
|
||||
(x2 == xmax && y1 == ymax)) {
|
||||
iclp++;
|
||||
xclp[iclp] = xmax;
|
||||
yclp[iclp] = ymax;
|
||||
}
|
||||
else if ((x1 == xmin && y2 == ymax) ||
|
||||
(x2 == xmin && y1 == ymax)) {
|
||||
iclp++;
|
||||
xclp[iclp] = xmin;
|
||||
yclp[iclp] = ymax;
|
||||
}
|
||||
/* Experimental code from way back.
|
||||
Polygon clipping is HARD.
|
||||
{
|
||||
int j;
|
||||
for (j = 0; j < i; j++) {
|
||||
if (x[j] < xmin && y[j] < ymin) {
|
||||
break;
|
||||
}
|
||||
else if (x[j] < xmin && y[j] > ymax) {
|
||||
iclp++;
|
||||
xclp[iclp] = xmin;
|
||||
yclp[iclp] = ymax;
|
||||
break;
|
||||
}
|
||||
else if (x[j] > xmax && y[j] < ymin) {
|
||||
iclp++;
|
||||
xclp[iclp] = xmax;
|
||||
yclp[iclp] = ymin;
|
||||
break;
|
||||
}
|
||||
else if (x[j] > xmax && y[j] > ymax) {
|
||||
iclp++;
|
||||
xclp[iclp] = xmax;
|
||||
yclp[iclp] = ymax;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
iclp++;
|
||||
xclp[iclp] = x2;
|
||||
yclp[iclp] = y2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw the sucker */
|
||||
|
||||
if (iclp + 1 >= 2) {
|
||||
if ((xclp[0] == xmin && yclp[iclp] == ymin) ||
|
||||
(xclp[iclp] == xmin && yclp[0] == ymin)) {
|
||||
iclp++;
|
||||
xclp[iclp] = xmin;
|
||||
yclp[iclp] = ymin;
|
||||
}
|
||||
else if ((xclp[0] == xmax && yclp[iclp] == ymin) ||
|
||||
(xclp[iclp] == xmax && yclp[0] == ymin)) {
|
||||
iclp++;
|
||||
xclp[iclp] = xmax;
|
||||
yclp[iclp] = ymin;
|
||||
}
|
||||
else if ((xclp[0] == xmax && yclp[iclp] == ymax) ||
|
||||
(xclp[iclp] == xmax && yclp[0] == ymax)) {
|
||||
iclp++;
|
||||
xclp[iclp] = xmax;
|
||||
yclp[iclp] = ymax;
|
||||
}
|
||||
else if ((xclp[0] == xmin && yclp[iclp] == ymax) ||
|
||||
(xclp[iclp] == xmin && yclp[0] == ymax)) {
|
||||
iclp++;
|
||||
xclp[iclp] = xmin;
|
||||
yclp[iclp] = ymax;
|
||||
}
|
||||
}
|
||||
if (iclp + 1 >= 3) {
|
||||
if(draw)
|
||||
(*draw)(xclp, yclp, iclp + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* int clipline()
|
||||
*
|
||||
* Get clipped endpoints
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
static int
|
||||
clipline(PLINT *p_x1, PLINT *p_y1, PLINT *p_x2, PLINT *p_y2,
|
||||
PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax)
|
||||
{
|
||||
PLINT t, dx, dy, flipx, flipy;
|
||||
double dydx = 0, dxdy = 0;
|
||||
|
||||
/* If both points are outside clip region with no hope of intersection,
|
||||
return with an error */
|
||||
|
||||
if ((*p_x1 <= xmin && *p_x2 <= xmin) ||
|
||||
(*p_x1 >= xmax && *p_x2 >= xmax) ||
|
||||
(*p_y1 <= ymin && *p_y2 <= ymin) ||
|
||||
(*p_y1 >= ymax && *p_y2 >= ymax))
|
||||
return 1;
|
||||
|
||||
flipx = 0;
|
||||
flipy = 0;
|
||||
|
||||
if (*p_x2 < *p_x1) {
|
||||
*p_x1 = 2 * xmin - *p_x1;
|
||||
*p_x2 = 2 * xmin - *p_x2;
|
||||
xmax = 2 * xmin - xmax;
|
||||
t = xmax;
|
||||
xmax = xmin;
|
||||
xmin = t;
|
||||
flipx = 1;
|
||||
}
|
||||
|
||||
if (*p_y2 < *p_y1) {
|
||||
*p_y1 = 2 * ymin - *p_y1;
|
||||
*p_y2 = 2 * ymin - *p_y2;
|
||||
ymax = 2 * ymin - ymax;
|
||||
t = ymax;
|
||||
ymax = ymin;
|
||||
ymin = t;
|
||||
flipy = 1;
|
||||
}
|
||||
|
||||
dx = *p_x2 - *p_x1;
|
||||
dy = *p_y2 - *p_y1;
|
||||
|
||||
if (dx != 0 && dy != 0) {
|
||||
dydx = (double) dy / (double) dx;
|
||||
dxdy = 1./ dydx;
|
||||
}
|
||||
|
||||
if (*p_x1 < xmin) {
|
||||
if (dx != 0 && dy != 0)
|
||||
*p_y1 = *p_y1 + ROUND((xmin - *p_x1) * dydx);
|
||||
*p_x1 = xmin;
|
||||
}
|
||||
|
||||
if (*p_y1 < ymin) {
|
||||
if (dx != 0 && dy != 0)
|
||||
*p_x1 = *p_x1 + ROUND((ymin - *p_y1) * dxdy);
|
||||
*p_y1 = ymin;
|
||||
}
|
||||
|
||||
if (*p_x1 >= xmax || *p_y1 >= ymax)
|
||||
return 1;
|
||||
|
||||
if (*p_y2 > ymax) {
|
||||
if (dx != 0 && dy != 0)
|
||||
*p_x2 = *p_x2 - ROUND((*p_y2 - ymax) * dxdy);
|
||||
*p_y2 = ymax;
|
||||
}
|
||||
|
||||
if (*p_x2 > xmax) {
|
||||
if (dx != 0 && dy != 0)
|
||||
*p_y2 = *p_y2 - ROUND((*p_x2 - xmax) * dydx);
|
||||
*p_x2 = xmax;
|
||||
}
|
||||
|
||||
if (flipx) {
|
||||
*p_x1 = 2 * xmax - *p_x1;
|
||||
*p_x2 = 2 * xmax - *p_x2;
|
||||
}
|
||||
|
||||
if (flipy) {
|
||||
*p_y1 = 2 * ymax - *p_y1;
|
||||
*p_y2 = 2 * ymax - *p_y2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void genlin()
|
||||
*
|
||||
* General line-drawing routine. Takes line styles into account.
|
||||
* If only 2 points are in the polyline, it is more efficient to use
|
||||
* plP_line() rather than plP_polyline().
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
genlin(short *x, short *y, PLINT npts)
|
||||
{
|
||||
/* Check for solid line */
|
||||
|
||||
if (plsc->nms == 0) {
|
||||
if (npts== 2)
|
||||
plP_line(x, y);
|
||||
else
|
||||
plP_polyline(x, y, npts);
|
||||
}
|
||||
|
||||
/* Right now dashed lines don't use polyline capability -- this
|
||||
should be improved */
|
||||
|
||||
else {
|
||||
|
||||
PLINT i;
|
||||
|
||||
/* Call escape sequence to draw dashed lines, only for drivers
|
||||
that have this capability */
|
||||
if (plsc->dev_dash) {
|
||||
plsc->dev_npts = npts;
|
||||
plsc->dev_x = x;
|
||||
plsc->dev_y = y;
|
||||
plP_esc(PLESC_DASH, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < npts - 1; i++) {
|
||||
grdashline(x+i, y+i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void grdashline()
|
||||
*
|
||||
* Draws a dashed line to the specified point from the previous one.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
grdashline(short *x, short *y)
|
||||
{
|
||||
PLINT nx, ny, nxp, nyp, incr, temp;
|
||||
PLINT modulo, dx, dy, i, xtmp, ytmp;
|
||||
PLINT tstep, pix_distance, j;
|
||||
int loop_x;
|
||||
short xl[2], yl[2];
|
||||
double nxstep, nystep;
|
||||
|
||||
/* Check if pattern needs to be restarted */
|
||||
|
||||
if (x[0] != lastx || y[0] != lasty) {
|
||||
plsc->curel = 0;
|
||||
plsc->pendn = 1;
|
||||
plsc->timecnt = 0;
|
||||
plsc->alarm = plsc->mark[0];
|
||||
}
|
||||
|
||||
lastx = xtmp = x[0];
|
||||
lasty = ytmp = y[0];
|
||||
|
||||
if (x[0] == x[1] && y[0] == y[1])
|
||||
return;
|
||||
|
||||
nx = x[1] - x[0];
|
||||
dx = (nx > 0) ? 1 : -1;
|
||||
nxp = ABS(nx);
|
||||
|
||||
ny = y[1] - y[0];
|
||||
dy = (ny > 0) ? 1 : -1;
|
||||
nyp = ABS(ny);
|
||||
|
||||
if (nyp > nxp) {
|
||||
modulo = nyp;
|
||||
incr = nxp;
|
||||
loop_x = 0;
|
||||
}
|
||||
else {
|
||||
modulo = nxp;
|
||||
incr = nyp;
|
||||
loop_x = 1;
|
||||
}
|
||||
|
||||
temp = modulo / 2;
|
||||
|
||||
/* Compute the timer step */
|
||||
|
||||
nxstep = nxp * plsc->umx;
|
||||
nystep = nyp * plsc->umy;
|
||||
tstep = sqrt( nxstep * nxstep + nystep * nystep ) / modulo;
|
||||
if (tstep < 1) tstep = 1;
|
||||
|
||||
/* tstep is distance per pixel moved */
|
||||
|
||||
i = 0;
|
||||
while (i < modulo) {
|
||||
pix_distance = (plsc->alarm - plsc->timecnt + tstep - 1) / tstep;
|
||||
i += pix_distance;
|
||||
if (i > modulo)
|
||||
pix_distance -= (i - modulo);
|
||||
plsc->timecnt += pix_distance * tstep;
|
||||
|
||||
temp += pix_distance * incr;
|
||||
j = temp / modulo;
|
||||
temp = temp % modulo;
|
||||
|
||||
if (loop_x) {
|
||||
xtmp += pix_distance * dx;
|
||||
ytmp += j * dy;
|
||||
}
|
||||
else {
|
||||
xtmp += j * dx;
|
||||
ytmp += pix_distance * dy;
|
||||
}
|
||||
if (plsc->pendn != 0) {
|
||||
xl[0] = lastx;
|
||||
yl[0] = lasty;
|
||||
xl[1] = xtmp;
|
||||
yl[1] = ytmp;
|
||||
plP_line(xl, yl);
|
||||
}
|
||||
|
||||
/* Update line style variables when alarm goes off */
|
||||
|
||||
while (plsc->timecnt >= plsc->alarm) {
|
||||
if (plsc->pendn != 0) {
|
||||
plsc->pendn = 0;
|
||||
plsc->timecnt -= plsc->alarm;
|
||||
plsc->alarm = plsc->space[plsc->curel];
|
||||
}
|
||||
else {
|
||||
plsc->pendn = 1;
|
||||
plsc->timecnt -= plsc->alarm;
|
||||
plsc->curel++;
|
||||
if (plsc->curel >= plsc->nms)
|
||||
plsc->curel = 0;
|
||||
plsc->alarm = plsc->mark[plsc->curel];
|
||||
}
|
||||
}
|
||||
lastx = xtmp;
|
||||
lasty = ytmp;
|
||||
}
|
||||
}
|
|
@ -1,312 +0,0 @@
|
|||
/* $Id: plmap.c,v 1.1 2004/03/01 20:54:52 cozmic Exp $
|
||||
|
||||
Continental Outline and Political Boundary Backgrounds
|
||||
|
||||
Some plots need a geographical background such as the global
|
||||
surface temperatures or the population density. The routine
|
||||
plmap() will draw one of the following backgrounds: continental
|
||||
outlines, political boundaries, the United States, and the United
|
||||
States with the continental outlines. The routine plmeridians()
|
||||
will add the latitudes and longitudes to the background. After
|
||||
the background has been drawn, one can use a contour routine or a
|
||||
symbol plotter to finish off the plot.
|
||||
|
||||
Copyright (C) 1991, 1993, 1994 Wesley Ebisuzaki
|
||||
Copyright (C) 1994, 2000, 2001 Maurice LeBrun
|
||||
Copyright (C) 1999 Geoffrey Furnish
|
||||
Copyright (C) 2000, 2001, 2002 Alan W. Irwin
|
||||
Copyright (C) 2001 Andrew Roach
|
||||
Copyright (C) 2001 Rafael Laboissiere
|
||||
Copyright (C) 2002 Vincent Darley
|
||||
Copyright (C) 2003 Joao Cardoso
|
||||
|
||||
This file is part of PLplot.
|
||||
|
||||
PLplot is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Library General Public License
|
||||
as published by the Free Software Foundation; version 2 of the
|
||||
License.
|
||||
|
||||
PLplot is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA
|
||||
|
||||
*/
|
||||
|
||||
#include "plplotP.h"
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plmap(void (*mapform)(PLINT, PLFLT *, PLFLT *), char *type,
|
||||
* PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat);
|
||||
*
|
||||
* plot continental outline in world coordinates
|
||||
*
|
||||
* v1.4: machine independent version
|
||||
* v1.3: replaced plcontinent by plmap, added plmeridians
|
||||
* v1.2: 2 arguments: mapform, type of plot
|
||||
*
|
||||
* mapform(PLINT n, PLFLT *x, PLFLT *y) is a routine to transform the
|
||||
* coordinate longitudes and latitudes to a plot coordinate system. By
|
||||
* using this transform, we can change from a longitude, latitude
|
||||
* coordinate to a polar stereographic project, for example. Initially,
|
||||
* x[0]..[n-1] are the longitudes and y[0]..y[n-1] are the corresponding
|
||||
* latitudes. After the call to mapform(), x[] and y[] should be replaced
|
||||
* by the corresponding plot coordinates. If no transform is desired,
|
||||
* mapform can be replaced by NULL.
|
||||
*
|
||||
* type is a character string. The value of this parameter determines the
|
||||
* type of background. The possible values are,
|
||||
*
|
||||
* "globe" continental outlines
|
||||
* "usa" USA and state boundaries
|
||||
* "cglobe" continental outlines and countries
|
||||
* "usaglobe" USA, state boundaries and continental outlines
|
||||
*
|
||||
* minlong, maxlong are the values of the longitude on the left and right
|
||||
* side of the plot, respectively. The value of minlong must be less than
|
||||
* the values of maxlong, and the values of maxlong-minlong must be less
|
||||
* or equal to 360.
|
||||
*
|
||||
* minlat, maxlat are the minimum and maximum latitudes to be plotted on
|
||||
* the background. One can always use -90.0 and 90.0 as the boundary
|
||||
* outside the plot window will be automatically eliminated. However, the
|
||||
* program will be faster if one can reduce the size of the background
|
||||
* plotted.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
#define MAP_FILE ".map"
|
||||
#define OFFSET (180*100)
|
||||
#define SCALE 100.0
|
||||
#define W_BUFSIZ (32*1024)
|
||||
|
||||
void
|
||||
plmap( void (*mapform)(PLINT, PLFLT *, PLFLT *), char *type,
|
||||
PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat )
|
||||
{
|
||||
PLINT wrap, sign;
|
||||
int i, j;
|
||||
PLFLT bufx[200], bufy[200], x[2], y[2];
|
||||
short int test[400];
|
||||
register PDFstrm *in;
|
||||
char filename[100];
|
||||
|
||||
unsigned char n_buff[2], buff[800];
|
||||
int n;
|
||||
long int t;
|
||||
|
||||
/*
|
||||
* read map outline
|
||||
*/
|
||||
strcpy(filename,type);
|
||||
strcat(filename,MAP_FILE);
|
||||
|
||||
if ((in = plLibOpenPdfstrm(filename)) == NULL)
|
||||
return;
|
||||
|
||||
for (;;) {
|
||||
/* read in # points in segment */
|
||||
if (pdf_rdx(n_buff, sizeof (unsigned char)* 2, in) == 0) break;
|
||||
n = (n_buff[0] << 8) + n_buff[1];
|
||||
if (n == 0) break;
|
||||
|
||||
pdf_rdx(buff, sizeof (unsigned char)*4*n, in);
|
||||
if (n == 1) continue;
|
||||
|
||||
for (j = i = 0; i < n; i++, j += 2) {
|
||||
t = (buff[j] << 8) + buff[j+1];
|
||||
bufx[i] = (t - OFFSET) / SCALE;
|
||||
}
|
||||
for (i = 0; i < n; i++, j += 2) {
|
||||
t = (buff[j] << 8) + buff[j+1];
|
||||
bufy[i] = (t - OFFSET) / SCALE;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
while (bufx[i] < minlong) {
|
||||
bufx[i] += 360.0;
|
||||
}
|
||||
while (bufx[i] > maxlong) {
|
||||
bufx[i] -= 360.0;
|
||||
}
|
||||
}
|
||||
|
||||
/* remove last 2 points if both outside of domain and won't plot */
|
||||
|
||||
/* AR: 18/11/01
|
||||
* I have commented out the next section which supposedly
|
||||
* removes points that do not plot within the domain.
|
||||
*
|
||||
* This code appears at any rate to be superseded by the next
|
||||
* block of code that checks for wrapping problems. Removing
|
||||
* this code seems to have fixed up the problems with mapping
|
||||
* function, but I do not wish to delete it outright just now in
|
||||
* case I have managed to miss something.
|
||||
*/
|
||||
|
||||
/* while (n > 1) {
|
||||
if ((bufx[n-1] < minlong && bufx[n-2] < minlong) ||
|
||||
(bufx[n-1] > maxlong && bufx[n-2] > maxlong) ||
|
||||
(bufy[n-1] < minlat && bufy[n-2] < minlat) ||
|
||||
(bufy[n-1] > maxlat && bufy[n-2] > maxlat)) {
|
||||
n--;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (n <= 1) continue;
|
||||
*/
|
||||
|
||||
if (mapform != NULL) (*mapform)(n,bufx,bufy); /* moved transformation to here */
|
||||
/* so bound-checking worked right */
|
||||
|
||||
wrap = 0;
|
||||
/* check for wrap around problems */
|
||||
for (i = 0; i < n-1; i++) {
|
||||
|
||||
/* jc: this code is wrong, as the bufx/y are floats that are
|
||||
converted to ints before abs() is called. Thus, small
|
||||
differences are masked off. The proof that it is wrong is
|
||||
that when replacing abs() with fabs(), as it should be,
|
||||
the code works the wrong way. What a proof :-)
|
||||
|
||||
test[i] = abs((bufx[i]-bufx[i+1])) > abs(bufy[i]/3);
|
||||
|
||||
If the intended behaviour is *really* that, than an
|
||||
explicit cast should be used to help other programmers, as
|
||||
is done bellow!!!
|
||||
*/
|
||||
|
||||
test[i] = abs((int)(bufx[i]-bufx[i+1])) > abs((int)bufy[i]/3); /* Changed this from 30 degrees so it is now "polar sensitive" */
|
||||
if (test[i]) wrap = 1;
|
||||
}
|
||||
|
||||
if (wrap == 0) {
|
||||
plline(n,bufx,bufy);
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < n-1; i++) {
|
||||
x[0] = bufx[i];
|
||||
x[1] = bufx[i+1];
|
||||
y[0] = bufy[i];
|
||||
y[1] = bufy[i+1];
|
||||
if (test[i] == 0) {
|
||||
plline(2,x,y);
|
||||
}
|
||||
else { /* this code seems to supercede the block commented out above */
|
||||
/* segment goes off the edge */
|
||||
sign = (x[1] > x[0]) ? 1 : -1;
|
||||
x[1] -= sign * 360.0;
|
||||
plline(2,x,y);
|
||||
x[0] = bufx[i];
|
||||
x[1] = bufx[i+1];
|
||||
y[0] = bufy[i];
|
||||
y[1] = bufy[i+1];
|
||||
x[0] += sign * 360.0;
|
||||
plline(2,x,y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plmeridians(void (*mapform)(PLINT, PLFLT *, PLFLT *),
|
||||
* PLFLT dlong, PLFLT dlat, PLFLT minlong, PLFLT maxlong,
|
||||
* PLFLT minlat, PLFLT maxlat);
|
||||
*
|
||||
* Plot the latitudes and longitudes on the background. The lines
|
||||
* are plotted in the current color and line style.
|
||||
*
|
||||
* mapform(PLINT n, PLFLT *x, PLFLT *y) is a routine to transform the
|
||||
* coordinate longitudes and latitudes to a plot coordinate system. By
|
||||
* using this transform, we can change from a longitude, latitude
|
||||
* coordinate to a polar stereographic project, for example. Initially,
|
||||
* x[0]..x[n-1] are the longitudes and y[0]..y[n-1] are the corresponding
|
||||
* latitudes. After the call to mapform(), x[] and y[] should be replaced
|
||||
* by the corresponding plot coordinates. If no transform is desired,
|
||||
* mapform can be replaced by NULL.
|
||||
*
|
||||
* dlat, dlong are the interval in degrees that the latitude and longitude
|
||||
* lines are to be plotted.
|
||||
*
|
||||
* minlong, maxlong are the values of the longitude on the left and right
|
||||
* side of the plot, respectively. The value of minlong must be less than
|
||||
* the values of maxlong, and the values of maxlong-minlong must be less
|
||||
* or equal to 360.
|
||||
*
|
||||
* minlat, maxlat are the minimum and maximum latitudes to be plotted on
|
||||
* the background. One can always use -90.0 and 90.0 as the boundary
|
||||
* outside the plot window will be automatically eliminated. However, the
|
||||
* program will be faster if one can reduce the size of the background
|
||||
* plotted.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
#define NSEG 100
|
||||
|
||||
void
|
||||
plmeridians( void (*mapform)(PLINT, PLFLT *, PLFLT *),
|
||||
PLFLT dlong, PLFLT dlat,
|
||||
PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat )
|
||||
{
|
||||
PLFLT yy, xx, temp, x[2], y[2], dx, dy;
|
||||
|
||||
if (minlong > maxlong) {
|
||||
temp = minlong;
|
||||
minlong = maxlong;
|
||||
maxlong = temp;
|
||||
}
|
||||
if (minlat > maxlat) {
|
||||
temp = minlat;
|
||||
minlat = maxlat;
|
||||
maxlat = temp;
|
||||
}
|
||||
dx = (maxlong - minlong) / NSEG;
|
||||
dy = (maxlat - minlat) / NSEG;
|
||||
|
||||
/* latitudes */
|
||||
|
||||
for (yy = dlat * ceil(minlat/dlat); yy <= maxlat; yy += dlat) {
|
||||
if (mapform == NULL) {
|
||||
y[0] = y[1] = yy;
|
||||
x[0] = minlong;
|
||||
x[1] = maxlong;
|
||||
plline(2,x,y);
|
||||
}
|
||||
else {
|
||||
for (xx = minlong; xx < maxlong; xx += dx) {
|
||||
y[0] = y[1] = yy;
|
||||
x[0] = xx;
|
||||
x[1] = xx + dx;
|
||||
(*mapform)(2,x,y);
|
||||
plline(2,x,y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* longitudes */
|
||||
|
||||
for (xx = dlong * ceil(minlong/dlong); xx <= maxlong; xx += dlong) {
|
||||
if (mapform == NULL) {
|
||||
x[0] = x[1] = xx;
|
||||
y[0] = minlat;
|
||||
y[1] = maxlat;
|
||||
plline(2,x,y);
|
||||
}
|
||||
else {
|
||||
for (yy = minlat; yy < maxlat; yy += dy) {
|
||||
x[0] = x[1] = xx;
|
||||
y[0] = yy;
|
||||
y[1] = yy + dy;
|
||||
(*mapform)(2,x,y);
|
||||
plline(2,x,y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,707 +0,0 @@
|
|||
/* $Id: plmeta.c,v 1.1 2004/03/01 20:54:52 cozmic Exp $
|
||||
|
||||
Copyright 1991, 1992, 1993, 1994, 1995
|
||||
Geoffrey Furnish furnish@dino.ph.utexas.edu
|
||||
Maurice LeBrun mjl@dino.ph.utexas.edu
|
||||
Institute for Fusion Studies University of Texas at Austin
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
|
||||
This is a metafile writer for PLplot.
|
||||
|
||||
*/
|
||||
#include "plDevs.h"
|
||||
|
||||
/*#define DEBUG*/
|
||||
|
||||
#ifdef PLD_plmeta
|
||||
|
||||
#define NEED_PLDEBUG
|
||||
#include "plplotP.h"
|
||||
#include "drivers.h"
|
||||
#include "metadefs.h"
|
||||
#include <string.h>
|
||||
|
||||
/* Device info */
|
||||
char* plD_DEVICE_INFO_plmeta = "plmeta:PLplot Native Meta-File:0:plmeta:26:plm";
|
||||
|
||||
|
||||
void plD_dispatch_init_plm ( PLDispatchTable *pdt );
|
||||
|
||||
void plD_init_plm (PLStream *);
|
||||
void plD_line_plm (PLStream *, short, short, short, short);
|
||||
void plD_polyline_plm (PLStream *, short *, short *, PLINT);
|
||||
void plD_eop_plm (PLStream *);
|
||||
void plD_bop_plm (PLStream *);
|
||||
void plD_tidy_plm (PLStream *);
|
||||
void plD_state_plm (PLStream *, PLINT);
|
||||
void plD_esc_plm (PLStream *, PLINT, void *);
|
||||
|
||||
/* Struct to hold device-specific info. */
|
||||
|
||||
typedef struct {
|
||||
PLFLT pxlx, pxly;
|
||||
PLINT xold, yold;
|
||||
|
||||
PLINT xmin, xmax, xlen;
|
||||
PLINT ymin, ymax, ylen;
|
||||
|
||||
FPOS_T lp_offset, index_offset;
|
||||
|
||||
int notfirst;
|
||||
} PLmDev;
|
||||
|
||||
/* Used for constructing error messages */
|
||||
|
||||
static char buffer[256];
|
||||
|
||||
/* Function prototypes */
|
||||
|
||||
static void WriteFileHeader (PLStream *pls);
|
||||
static void UpdatePrevPagehdr (PLStream *pls);
|
||||
static void WritePageInfo (PLStream *pls, FPOS_T pp_offset);
|
||||
static void UpdateIndex (PLStream *pls, FPOS_T cp_offset);
|
||||
static void plm_fill (PLStream *pls);
|
||||
static void plm_swin (PLStream *pls);
|
||||
|
||||
/* A little function to help with debugging */
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DEBUG_PRINT_LOCATION(a) PrintLocation(pls, a)
|
||||
|
||||
static void PrintLocation(PLStream *pls, char *tag)
|
||||
{
|
||||
int isfile = (pls->output_type == 0);
|
||||
if (isfile) {
|
||||
FILE *file = pls->OutFile;
|
||||
FPOS_T current_offset;
|
||||
|
||||
if (pl_fgetpos(file, ¤t_offset))
|
||||
plexit("PrintLocation (plmeta.c): fgetpos call failed");
|
||||
|
||||
pldebug(tag, "at offset %d in file %s\n",
|
||||
(int) current_offset, pls->FileName);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define DEBUG_PRINT_LOCATION(a)
|
||||
#endif
|
||||
|
||||
void plD_dispatch_init_plm( PLDispatchTable *pdt )
|
||||
{
|
||||
pdt->pl_MenuStr = "PLplot Native Meta-File";
|
||||
pdt->pl_DevName = "plmeta";
|
||||
pdt->pl_type = plDevType_FileOriented;
|
||||
pdt->pl_seq = 26;
|
||||
pdt->pl_init = (plD_init_fp) plD_init_plm;
|
||||
pdt->pl_line = (plD_line_fp) plD_line_plm;
|
||||
pdt->pl_polyline = (plD_polyline_fp) plD_polyline_plm;
|
||||
pdt->pl_eop = (plD_eop_fp) plD_eop_plm;
|
||||
pdt->pl_bop = (plD_bop_fp) plD_bop_plm;
|
||||
pdt->pl_tidy = (plD_tidy_fp) plD_tidy_plm;
|
||||
pdt->pl_state = (plD_state_fp) plD_state_plm;
|
||||
pdt->pl_esc = (plD_esc_fp) plD_esc_plm;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plD_init_plm()
|
||||
*
|
||||
* Initialize device.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plD_init_plm(PLStream *pls)
|
||||
{
|
||||
PLmDev *dev;
|
||||
U_CHAR c = (U_CHAR) INITIALIZE;
|
||||
|
||||
dbug_enter("plD_init_plm");
|
||||
|
||||
pls->color = 1; /* Is a color device */
|
||||
pls->dev_fill0 = 1; /* Handle solid fills */
|
||||
pls->dev_fill1 = 1; /* Handle pattern fills */
|
||||
|
||||
/* Initialize family file info */
|
||||
|
||||
plFamInit(pls);
|
||||
|
||||
/* Prompt for a file name if not already set */
|
||||
|
||||
plOpenFile(pls);
|
||||
pls->pdfs = pdf_finit(pls->OutFile);
|
||||
|
||||
/* Allocate and initialize device-specific data */
|
||||
|
||||
pls->dev = calloc(1, (size_t) sizeof(PLmDev));
|
||||
if (pls->dev == NULL)
|
||||
plexit("plD_init_plm: Out of memory.");
|
||||
|
||||
dev = (PLmDev *) pls->dev;
|
||||
|
||||
dev->xold = PL_UNDEFINED;
|
||||
dev->yold = PL_UNDEFINED;
|
||||
|
||||
dev->xmin = 0;
|
||||
dev->xmax = PIXELS_X - 1;
|
||||
dev->ymin = 0;
|
||||
dev->ymax = PIXELS_Y - 1;
|
||||
|
||||
dev->pxlx = (double) PIXELS_X / (double) LPAGE_X;
|
||||
dev->pxly = (double) PIXELS_Y / (double) LPAGE_Y;
|
||||
|
||||
plP_setpxl(dev->pxlx, dev->pxly);
|
||||
plP_setphy(dev->xmin, dev->xmax, dev->ymin, dev->ymax);
|
||||
|
||||
/* Write Metafile header. */
|
||||
|
||||
WriteFileHeader(pls);
|
||||
|
||||
/* Write color map state info */
|
||||
|
||||
plD_state_plm(pls, PLSTATE_CMAP0);
|
||||
plD_state_plm(pls, PLSTATE_CMAP1);
|
||||
|
||||
/* Write initialization command. */
|
||||
|
||||
DEBUG_PRINT_LOCATION("before init");
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, c) );
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plD_line_plm()
|
||||
*
|
||||
* Draw a line in the current color from (x1,y1) to (x2,y2).
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plD_line_plm(PLStream *pls, short x1, short y1, short x2, short y2)
|
||||
{
|
||||
PLmDev *dev = (PLmDev *) pls->dev;
|
||||
U_CHAR c;
|
||||
U_SHORT xy[4];
|
||||
|
||||
/* dbug_enter("plD_line_plm"); */
|
||||
|
||||
/* Failsafe check */
|
||||
|
||||
#ifdef DEBUG
|
||||
if (x1 < dev->xmin || x1 > dev->xmax ||
|
||||
x2 < dev->xmin || x2 > dev->xmax ||
|
||||
y1 < dev->ymin || y1 > dev->ymax ||
|
||||
y2 < dev->ymin || y2 > dev->ymax) {
|
||||
|
||||
pldebug("plD_line_plm",
|
||||
"coordinates out of bounds -- \nActual: (%i,%i), (%i,%i) Bounds: (%i,%i,%i,%i)\n",
|
||||
x1, y1, x2, y2, dev->xmin, dev->xmax, dev->ymin, dev->ymax);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If continuation of previous line send the LINETO command, which uses
|
||||
the previous (x,y) point as it's starting location. This results in a
|
||||
storage reduction of not quite 50%, since the instruction length for
|
||||
a LINETO is 5/9 of that for the LINE command, and given that most
|
||||
graphics applications use this command heavily.
|
||||
|
||||
Still not quite as efficient as tektronix format since we also send the
|
||||
command each time (so shortest command is 25% larger), but a lot easier
|
||||
to implement than the tek method.
|
||||
*/
|
||||
if (x1 == dev->xold && y1 == dev->yold) {
|
||||
|
||||
c = (U_CHAR) LINETO;
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, c) );
|
||||
|
||||
xy[0] = x2;
|
||||
xy[1] = y2;
|
||||
plm_wr( pdf_wr_2nbytes(pls->pdfs, xy, 2) );
|
||||
}
|
||||
else {
|
||||
c = (U_CHAR) LINE;
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, c) );
|
||||
|
||||
xy[0] = x1;
|
||||
xy[1] = y1;
|
||||
xy[2] = x2;
|
||||
xy[3] = y2;
|
||||
plm_wr( pdf_wr_2nbytes(pls->pdfs, xy, 4) );
|
||||
}
|
||||
dev->xold = x2;
|
||||
dev->yold = y2;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plD_polyline_plm()
|
||||
*
|
||||
* Draw a polyline in the current color.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plD_polyline_plm(PLStream *pls, short *xa, short *ya, PLINT npts)
|
||||
{
|
||||
PLmDev *dev = (PLmDev *) pls->dev;
|
||||
U_CHAR c = (U_CHAR) POLYLINE;
|
||||
|
||||
dbug_enter("plD_polyline_plm");
|
||||
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, c) );
|
||||
|
||||
plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) npts) );
|
||||
|
||||
plm_wr( pdf_wr_2nbytes(pls->pdfs, (U_SHORT *) xa, npts) );
|
||||
plm_wr( pdf_wr_2nbytes(pls->pdfs, (U_SHORT *) ya, npts) );
|
||||
|
||||
dev->xold = xa[npts - 1];
|
||||
dev->yold = ya[npts - 1];
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plD_eop_plm()
|
||||
*
|
||||
* End of page.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plD_eop_plm(PLStream *pls)
|
||||
{
|
||||
U_CHAR c = (U_CHAR) EOP;
|
||||
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, c) );
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plD_bop_plm()
|
||||
*
|
||||
* Set up for the next page.
|
||||
*
|
||||
* Page header layout as follows:
|
||||
*
|
||||
* BOP (U_CHAR)
|
||||
* page number (U_SHORT)
|
||||
* prev page offset (U_LONG)
|
||||
* next page offset (U_LONG)
|
||||
*
|
||||
* Each call after the first is responsible for updating the table of
|
||||
* contents and the next page offset from the previous page.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plD_bop_plm(PLStream *pls)
|
||||
{
|
||||
PLmDev *dev = (PLmDev *) pls->dev;
|
||||
int isfile = (pls->output_type == 0);
|
||||
FPOS_T pp_offset = dev->lp_offset;;
|
||||
|
||||
dbug_enter("plD_bop_plm");
|
||||
|
||||
dev->xold = PL_UNDEFINED;
|
||||
dev->yold = PL_UNDEFINED;
|
||||
|
||||
/* Update previous page header */
|
||||
|
||||
if (isfile)
|
||||
UpdatePrevPagehdr(pls);
|
||||
|
||||
/* Start next family file if necessary. */
|
||||
|
||||
pls->bytecnt = pls->pdfs->bp;
|
||||
plGetFam(pls);
|
||||
|
||||
/* Update page counter */
|
||||
|
||||
pls->page++;
|
||||
|
||||
/* Update table of contents info & write new page header. */
|
||||
|
||||
WritePageInfo(pls, pp_offset);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* WritePageInfo()
|
||||
*
|
||||
* Update table of contents info & write new page header.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
WritePageInfo(PLStream *pls, FPOS_T pp_offset)
|
||||
{
|
||||
PLmDev *dev = (PLmDev *) pls->dev;
|
||||
FILE *file = pls->OutFile;
|
||||
int isfile = (pls->output_type == 0);
|
||||
U_CHAR c;
|
||||
FPOS_T cp_offset=0;
|
||||
|
||||
/* Update table of contents. */
|
||||
|
||||
if (isfile) {
|
||||
if (pl_fgetpos(file, &cp_offset))
|
||||
plexit("WritePageInfo (plmeta.c): fgetpos call failed");
|
||||
|
||||
UpdateIndex(pls, cp_offset);
|
||||
}
|
||||
|
||||
/* Write new page header */
|
||||
|
||||
if (dev->notfirst)
|
||||
c = BOP;
|
||||
else {
|
||||
c = BOP0;
|
||||
dev->notfirst = 1;
|
||||
}
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, c) );
|
||||
plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->page) );
|
||||
plm_wr( pdf_wr_4bytes(pls->pdfs, (U_LONG) pp_offset) );
|
||||
plm_wr( pdf_wr_4bytes(pls->pdfs, (U_LONG) 0) );
|
||||
|
||||
/* Update last page offset with current page value */
|
||||
|
||||
dev->lp_offset = cp_offset;
|
||||
|
||||
/* Write some page state information just to make things nice later on */
|
||||
/* Eventually there will be more */
|
||||
|
||||
plD_state_plm(pls, PLSTATE_COLOR0);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* UpdatePrevPagehdr()
|
||||
*
|
||||
* Update previous page header.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
UpdatePrevPagehdr(PLStream *pls)
|
||||
{
|
||||
PLmDev *dev = (PLmDev *) pls->dev;
|
||||
FILE *file = pls->OutFile;
|
||||
FPOS_T cp_offset=0;
|
||||
|
||||
fflush(file);
|
||||
|
||||
/* Determine where we are */
|
||||
|
||||
if (pl_fgetpos(file, &cp_offset))
|
||||
plexit("plD_bop_plm: fgetpos call failed");
|
||||
|
||||
/* Seek back to previous page header. */
|
||||
|
||||
if (dev->lp_offset > 0) {
|
||||
FPOS_T fwbyte_offset=0;
|
||||
|
||||
pldebug("UpdatePrevPagehdr 1 (plmeta.c)",
|
||||
"Location: %d, seeking to: %d\n",
|
||||
(int) cp_offset, (int) dev->lp_offset);
|
||||
|
||||
/* The forward byte offset is located exactly 7 bytes after the BOP */
|
||||
fwbyte_offset = dev->lp_offset + 7;
|
||||
if (pl_fsetpos(file, &fwbyte_offset)) {
|
||||
sprintf(buffer, "UpdatePrevPagehdr (plmeta.c): fsetpos to fwbyte_offset (%d) failed",
|
||||
(int) fwbyte_offset);
|
||||
plexit(buffer);
|
||||
}
|
||||
|
||||
/* DEBUG: verify current location */
|
||||
|
||||
#ifdef DEBUG
|
||||
if (pl_fgetpos(file, &fwbyte_offset))
|
||||
plexit("UpdatePrevPagehdr (plmeta.c): fgetpos call failed");
|
||||
|
||||
pldebug("UpdatePrevPagehdr 2 (plmeta.c)",
|
||||
"Now at: %d, to write: %d\n",
|
||||
(int) fwbyte_offset, (int) cp_offset);
|
||||
#endif
|
||||
|
||||
/* Write forward byte offset into previous page header. */
|
||||
|
||||
plm_wr( pdf_wr_4bytes(pls->pdfs, (U_LONG) cp_offset) );
|
||||
fflush(file);
|
||||
|
||||
/* DEBUG: move back to before the write & read it to verify */
|
||||
|
||||
#ifdef DEBUG
|
||||
if (pl_fsetpos(file, &fwbyte_offset)) {
|
||||
sprintf(buffer, "UpdatePrevPagehdr (plmeta.c): fsetpos to fwbyte_offset (%d) failed",
|
||||
(int) fwbyte_offset);
|
||||
plexit(buffer);
|
||||
}
|
||||
{
|
||||
U_LONG read_offset;
|
||||
plm_rd(pdf_rd_4bytes(pls->pdfs, &read_offset));
|
||||
pldebug("UpdatePrevPagehdr 3 (plmeta.c)",
|
||||
"Value read as: %d\n", read_offset);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Return to current page offset */
|
||||
|
||||
if (pl_fsetpos(file, &cp_offset)) {
|
||||
sprintf(buffer, "UpdatePrevPagehdr (plmeta.c): fsetpos to cp_offset (%d) failed",
|
||||
(int) cp_offset);
|
||||
plexit(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* UpdateIndex()
|
||||
*
|
||||
* Update file index.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
UpdateIndex(PLStream *pls, FPOS_T cp_offset)
|
||||
{
|
||||
PLmDev *dev = (PLmDev *) pls->dev;
|
||||
FILE *file = pls->OutFile;
|
||||
|
||||
/* Update file index. Right now only number of pages. */
|
||||
/* The ordering here is critical */
|
||||
|
||||
if (dev->index_offset > 0) {
|
||||
pldebug("UpdateIndex (plmeta.c)",
|
||||
"Location: %d, seeking to: %d\n",
|
||||
(int) cp_offset, (int) dev->lp_offset);
|
||||
|
||||
if (pl_fsetpos(file, &dev->index_offset)) {
|
||||
sprintf(buffer, "UpdateIndex (plmeta.c): fsetpos to index_offset (%d) failed",
|
||||
(int) dev->index_offset);
|
||||
plexit(buffer);
|
||||
}
|
||||
plm_wr( pdf_wr_header(pls->pdfs, "pages") );
|
||||
plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->page) );
|
||||
|
||||
pldebug("UpdateIndex (plmeta.c)",
|
||||
"Location: %d, seeking to: %d\n",
|
||||
(int) dev->lp_offset, (int) cp_offset);
|
||||
|
||||
if (pl_fsetpos(file, &cp_offset)) {
|
||||
sprintf(buffer, "UpdateIndex (plmeta.c): fsetpos to cp_offset (%d) failed",
|
||||
(int) cp_offset);
|
||||
plexit(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plD_tidy_plm()
|
||||
*
|
||||
* Close graphics file
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plD_tidy_plm(PLStream *pls)
|
||||
{
|
||||
U_CHAR c = (U_CHAR) CLOSE;
|
||||
|
||||
dbug_enter("plD_tidy_plm");
|
||||
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, c) );
|
||||
pdf_close(pls->pdfs);
|
||||
free_mem(pls->dev);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plD_state_plm()
|
||||
*
|
||||
* Handle change in PLStream state (color, pen width, fill attribute, etc).
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plD_state_plm(PLStream *pls, PLINT op)
|
||||
{
|
||||
U_CHAR c = (U_CHAR) CHANGE_STATE;
|
||||
int i;
|
||||
|
||||
dbug_enter("plD_state_plm");
|
||||
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, c) );
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, op) );
|
||||
|
||||
switch (op) {
|
||||
|
||||
case PLSTATE_WIDTH:
|
||||
plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) (pls->width)) );
|
||||
break;
|
||||
|
||||
case PLSTATE_COLOR0:
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, (U_CHAR) pls->icol0) );
|
||||
|
||||
if (pls->icol0 == PL_RGB_COLOR) {
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, pls->curcolor.r) );
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, pls->curcolor.g) );
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, pls->curcolor.b) );
|
||||
}
|
||||
break;
|
||||
|
||||
case PLSTATE_COLOR1:
|
||||
plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->icol1) );
|
||||
break;
|
||||
|
||||
case PLSTATE_FILL:
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, (U_CHAR) pls->patt) );
|
||||
break;
|
||||
|
||||
case PLSTATE_CMAP0:
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, (U_CHAR) pls->ncol0) );
|
||||
for (i = 0; i < pls->ncol0; i++) {
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, pls->cmap0[i].r) );
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, pls->cmap0[i].g) );
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, pls->cmap0[i].b) );
|
||||
}
|
||||
break;
|
||||
|
||||
case PLSTATE_CMAP1:
|
||||
plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->ncol1) );
|
||||
for (i = 0; i < pls->ncol1; i++) {
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, pls->cmap1[i].r) );
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, pls->cmap1[i].g) );
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, pls->cmap1[i].b) );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plD_esc_plm()
|
||||
*
|
||||
* Escape function. Note that any data written must be in device
|
||||
* independent form to maintain the transportability of the metafile.
|
||||
*
|
||||
* Functions:
|
||||
*
|
||||
* PLESC_FILL Fill polygon
|
||||
* PLESC_SWIN Set window parameters
|
||||
*
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plD_esc_plm(PLStream *pls, PLINT op, void *ptr)
|
||||
{
|
||||
U_CHAR c = (U_CHAR) ESCAPE;
|
||||
|
||||
dbug_enter("plD_esc_plm");
|
||||
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, c) );
|
||||
plm_wr( pdf_wr_1byte(pls->pdfs, (U_CHAR) op) );
|
||||
|
||||
switch (op) {
|
||||
case PLESC_FILL:
|
||||
plm_fill(pls);
|
||||
break;
|
||||
|
||||
case PLESC_SWIN:
|
||||
plm_swin(pls);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plm_fill()
|
||||
*
|
||||
* Fill polygon described in points pls->dev_x[] and pls->dev_y[].
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
plm_fill(PLStream *pls)
|
||||
{
|
||||
PLmDev *dev = (PLmDev *) pls->dev;
|
||||
|
||||
dbug_enter("plm_fill");
|
||||
|
||||
plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->dev_npts) );
|
||||
|
||||
plm_wr( pdf_wr_2nbytes(pls->pdfs, (U_SHORT *) pls->dev_x, pls->dev_npts) );
|
||||
plm_wr( pdf_wr_2nbytes(pls->pdfs, (U_SHORT *) pls->dev_y, pls->dev_npts) );
|
||||
|
||||
dev->xold = PL_UNDEFINED;
|
||||
dev->yold = PL_UNDEFINED;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plm_swin()
|
||||
*
|
||||
* Set window parameters.
|
||||
* Each parameter or group of parameters is tagged to make backward
|
||||
* compatibility easier.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
plm_swin(PLStream *pls)
|
||||
{
|
||||
dbug_enter("plm_swin");
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* WriteFileHeader()
|
||||
*
|
||||
* Writes Metafile header.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
WriteFileHeader(PLStream *pls)
|
||||
{
|
||||
PLmDev *dev = (PLmDev *) pls->dev;
|
||||
FILE *file = pls->OutFile;
|
||||
int isfile = (pls->output_type == 0);
|
||||
|
||||
dbug_enter("WriteFileHeader(PLStream *pls");
|
||||
|
||||
plm_wr( pdf_wr_header(pls->pdfs, PLMETA_HEADER) );
|
||||
plm_wr( pdf_wr_header(pls->pdfs, PLMETA_VERSION) );
|
||||
|
||||
/* Write file index info. Right now only number of pages. */
|
||||
/* The order here is critical */
|
||||
|
||||
if (isfile) {
|
||||
if (pl_fgetpos(file, &dev->index_offset))
|
||||
plexit("WriteFileHeader: fgetpos call failed");
|
||||
}
|
||||
|
||||
plm_wr( pdf_wr_header(pls->pdfs, "pages") );
|
||||
plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) 0) );
|
||||
|
||||
/* Write initialization info. Tag via strings to make backward
|
||||
compatibility with old metafiles as easy as possible. */
|
||||
|
||||
plm_wr( pdf_wr_header(pls->pdfs, "xmin") );
|
||||
plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) dev->xmin) );
|
||||
|
||||
plm_wr( pdf_wr_header(pls->pdfs, "xmax") );
|
||||
plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) dev->xmax) );
|
||||
|
||||
plm_wr( pdf_wr_header(pls->pdfs, "ymin") );
|
||||
plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) dev->ymin) );
|
||||
|
||||
plm_wr( pdf_wr_header(pls->pdfs, "ymax") );
|
||||
plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) dev->ymax) );
|
||||
|
||||
plm_wr( pdf_wr_header(pls->pdfs, "pxlx") );
|
||||
plm_wr( pdf_wr_ieeef(pls->pdfs, (float) dev->pxlx) );
|
||||
|
||||
plm_wr( pdf_wr_header(pls->pdfs, "pxly") );
|
||||
plm_wr( pdf_wr_ieeef(pls->pdfs, (float) dev->pxly) );
|
||||
|
||||
plm_wr( pdf_wr_header(pls->pdfs, "") );
|
||||
}
|
||||
|
||||
#else
|
||||
int
|
||||
pldummy_plmeta()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* PLD_plmeta */
|
|
@ -1,282 +0,0 @@
|
|||
/* $Id: plpage.c,v 1.1 2004/03/01 20:54:52 cozmic Exp $
|
||||
|
||||
Page/subpage handling routines
|
||||
*/
|
||||
|
||||
#include "plplotP.h"
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void pladv()
|
||||
*
|
||||
* Advance to subpage "page", or to the next one if "page" = 0.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_pladv(PLINT page)
|
||||
{
|
||||
if (plsc->level < 1) {
|
||||
plabort("pladv: Please call plinit first");
|
||||
return;
|
||||
}
|
||||
|
||||
if (page > 0 && page <= plsc->nsubx * plsc->nsuby)
|
||||
plsc->cursub = page;
|
||||
|
||||
else if (page == 0) {
|
||||
if (plsc->cursub >= plsc->nsubx * plsc->nsuby) {
|
||||
plP_eop();
|
||||
plP_bop();
|
||||
plsc->cursub = 1;
|
||||
}
|
||||
else
|
||||
plsc->cursub++;
|
||||
}
|
||||
else {
|
||||
plabort("pladv: Invalid subpage number");
|
||||
return;
|
||||
}
|
||||
|
||||
plP_setsub();
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void plclear()
|
||||
*
|
||||
* Clear current subpage. Subpages can be set with pladv before
|
||||
* calling plclear. Not all drivers support this.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plclear(void)
|
||||
{
|
||||
if (plsc->level < 1) {
|
||||
plabort("plclear: Please call plinit first");
|
||||
return;
|
||||
}
|
||||
|
||||
if (plsc->dev_clear)
|
||||
plP_esc(PLESC_CLEAR, NULL);
|
||||
else { /* driver does not support clear, fill using background color */
|
||||
|
||||
short x[5], y[5];
|
||||
int ocolor = plsc->icol0;
|
||||
|
||||
x[0] = x[3] = x[4] = plsc->sppxmi;
|
||||
x[1] = x[2] = plsc->sppxma;
|
||||
y[0] = y[1] = y[4] = plsc->sppymi;
|
||||
y[2] = y[3] = plsc->sppyma;
|
||||
plcol0(0);
|
||||
plP_fill(x, y, 5);
|
||||
plcol0(ocolor);
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void pleop()
|
||||
*
|
||||
* End current page.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_pleop(void)
|
||||
{
|
||||
if (plsc->level < 1) {
|
||||
plabort("pleop: Please call plinit first");
|
||||
return;
|
||||
}
|
||||
|
||||
plsc->cursub = plsc->nsubx * plsc->nsuby;
|
||||
plP_eop();
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void plbop()
|
||||
*
|
||||
* Start new page. Should only be used with pleop().
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plbop(void)
|
||||
{
|
||||
if (plsc->level < 1) {
|
||||
plabort("pladv: Please call plinit first");
|
||||
return;
|
||||
}
|
||||
plP_bop();
|
||||
plsc->cursub = 1;
|
||||
plP_setsub();
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void plP_subpInit()
|
||||
*
|
||||
* Set up plot parameters according to the number of subpages.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plP_subpInit(void)
|
||||
{
|
||||
PLFLT scale, size_chr, size_sym, size_maj, size_min;
|
||||
|
||||
/* Subpage checks */
|
||||
|
||||
if (plsc->nsubx <= 0)
|
||||
plsc->nsubx = 1;
|
||||
if (plsc->nsuby <= 0)
|
||||
plsc->nsuby = 1;
|
||||
|
||||
plsc->cursub = 0;
|
||||
|
||||
/*
|
||||
* Set default sizes
|
||||
* Global scaling:
|
||||
* Normalize to the page length for more uniform results.
|
||||
* A virtual page length of 200 mm is assumed.
|
||||
* Subpage scaling:
|
||||
* Reduce sizes with plot area (non-proportional, so that character
|
||||
* size doesn't get too small).
|
||||
*/
|
||||
scale = 0.5 *
|
||||
((plsc->phyxma - plsc->phyxmi) / plsc->xpmm +
|
||||
(plsc->phyyma - plsc->phyymi) / plsc->ypmm) / 200.0;
|
||||
|
||||
if (plsc->nsuby > 1)
|
||||
scale /= sqrt((double) plsc->nsuby);
|
||||
|
||||
size_chr = 4.0;
|
||||
size_sym = 4.0; /* All these in virtual plot units */
|
||||
size_maj = 3.0;
|
||||
size_min = 1.5;
|
||||
|
||||
plsc->chrdef = plsc->chrht = size_chr * scale;
|
||||
plsc->symdef = plsc->symht = size_sym * scale;
|
||||
plsc->majdef = plsc->majht = size_maj * scale;
|
||||
plsc->mindef = plsc->minht = size_min * scale;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void plP_setsub()
|
||||
*
|
||||
* Set up the subpage boundaries according to the current subpage selected.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plP_setsub(void)
|
||||
{
|
||||
PLINT ix, iy;
|
||||
|
||||
ix = (plsc->cursub - 1) % plsc->nsubx;
|
||||
iy = plsc->nsuby - (plsc->cursub - 1) / plsc->nsubx;
|
||||
|
||||
plsc->spdxmi = (PLFLT) (ix) / (PLFLT) (plsc->nsubx);
|
||||
plsc->spdxma = (PLFLT) (ix + 1) / (PLFLT) (plsc->nsubx);
|
||||
plsc->spdymi = (PLFLT) (iy - 1) / (PLFLT) (plsc->nsuby);
|
||||
plsc->spdyma = (PLFLT) (iy) / (PLFLT) (plsc->nsuby);
|
||||
|
||||
plsc->sppxmi = plP_dcpcx(plsc->spdxmi);
|
||||
plsc->sppxma = plP_dcpcx(plsc->spdxma);
|
||||
plsc->sppymi = plP_dcpcy(plsc->spdymi);
|
||||
plsc->sppyma = plP_dcpcy(plsc->spdyma);
|
||||
|
||||
plP_sclp(plsc->sppxmi, plsc->sppxma, plsc->sppymi, plsc->sppyma);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void plgspa()
|
||||
*
|
||||
* Get subpage boundaries in absolute coordinates (mm from bottom
|
||||
* left-hand corner of page.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plgspa(PLFLT *xmin, PLFLT *xmax, PLFLT *ymin, PLFLT *ymax)
|
||||
{
|
||||
if (plsc->level < 1) {
|
||||
plabort("plgspa: Please call plinit first");
|
||||
return;
|
||||
}
|
||||
*xmin = plP_dcmmx(plsc->spdxmi);
|
||||
*xmax = plP_dcmmx(plsc->spdxma);
|
||||
*ymin = plP_dcmmy(plsc->spdymi);
|
||||
*ymax = plP_dcmmy(plsc->spdyma);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* int plGetCursor()
|
||||
*
|
||||
* Wait for graphics input event and translate to world coordinates.
|
||||
* Returns 0 if no translation to world coordinates is possible.
|
||||
* Written by Paul Casteels.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
plGetCursor(PLGraphicsIn *plg)
|
||||
{
|
||||
plP_esc(PLESC_GETC, plg);
|
||||
return plTranslateCursor(plg);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* int plTranslateCursor()
|
||||
*
|
||||
* Translates cursor position from relative device coordinates to world
|
||||
* coordinates. Returns 0 if no translation to world coordinates is
|
||||
* possible. Written by Paul Casteels and modified by Alan W. Irwin.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
plTranslateCursor(PLGraphicsIn *plg)
|
||||
{
|
||||
int window;
|
||||
c_plcalc_world(plg->dX, plg->dY, &plg->wX, &plg->wY,
|
||||
(PLINT *) &window);
|
||||
if ( window >= 0 ) {
|
||||
plg->subwindow = window;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void c_plcalc_world
|
||||
*
|
||||
* Calculate world coordinates wx, and wy from relative device coordinates, rx
|
||||
* and ry. Also, return the window index for which the world coordinates
|
||||
* are valid. window is set to -1 and wx and wy to 0. if rx and ry do not
|
||||
* correspond to valid world coordinates for any currently existing window.
|
||||
* Originally written by Paul Casteels and modified by Alan W. Irwin.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plcalc_world(PLFLT rx, PLFLT ry, PLFLT *wx, PLFLT *wy, PLINT *window)
|
||||
{
|
||||
int i;
|
||||
int lastwin = plsc->nplwin - 1;
|
||||
int firstwin = MAX(plsc->nplwin - PL_MAXWINDOWS, 0);
|
||||
PLWindow *w;
|
||||
|
||||
for (i = lastwin; i >= firstwin; i--) {
|
||||
w = &plsc->plwin[i % PL_MAXWINDOWS];
|
||||
if ((rx >= w->dxmi) &&
|
||||
(rx <= w->dxma) &&
|
||||
(ry >= w->dymi) &&
|
||||
(ry <= w->dyma) ) {
|
||||
|
||||
*wx = w->wxmi + (rx - w->dxmi) *
|
||||
(w->wxma - w->wxmi) / (w->dxma - w->dxmi);
|
||||
|
||||
*wy = w->wymi + (ry - w->dymi) *
|
||||
(w->wyma - w->wymi) / (w->dyma - w->dymi);
|
||||
|
||||
*window = i;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* No valid window found with these relative coordinates. */
|
||||
*wx = 0.;
|
||||
*wy = 0.;
|
||||
*window = -1;
|
||||
return;
|
||||
}
|
|
@ -1,872 +0,0 @@
|
|||
/* $Id: plplotP.h,v 1.1 2004/03/01 20:54:52 cozmic Exp $
|
||||
|
||||
Copyright (C) 1993, 1994, 1995 by
|
||||
Maurice J. LeBrun, Geoff Furnish, Tony Richardson.
|
||||
|
||||
Internal (private) macros and prototypes for the PLplot package. This
|
||||
header file must be included before all others, including system header
|
||||
files. This file is typically needed when including driver specific
|
||||
header files (e.g. pltkd.h).
|
||||
|
||||
This software may be freely copied, modified and redistributed without
|
||||
fee provided that this copyright notice is preserved intact on all
|
||||
copies and modified copies.
|
||||
|
||||
There is no warranty or other guarantee of fitness of this software.
|
||||
It is provided solely "as is". The author(s) disclaim(s) all
|
||||
responsibility and liability with respect to this software's usage or
|
||||
its effect upon hardware or computer systems.
|
||||
*/
|
||||
|
||||
#ifndef __PLPLOTP_H__
|
||||
#define __PLPLOTP_H__
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Select environment. Must be done before anything else.
|
||||
*
|
||||
* Basically we want the widest range of system services that are available.
|
||||
* Fortunately on many systems, that is the default. To get "everything",
|
||||
* one of the following must be defined, as appropriate:
|
||||
*
|
||||
* _GNU_SOURCE on Linux (default)
|
||||
* _OSF_SOURCE on OSF1 (default)
|
||||
* _HPUX_SOURCE on HP (not default)
|
||||
* _ALL_SOURCE on AIX (no idea)
|
||||
*
|
||||
* To see where these are set, do the following:
|
||||
*
|
||||
* cd /usr/include; grep SOURCE *.h | fgrep 'define '
|
||||
*
|
||||
* and the file containing lots of these is the one you want (features.h on
|
||||
* Linux, standards.h on OSF1, etc). Follow the logic to see what needs to be
|
||||
* defined to get "everything", i.e. POSIX.*, XOPEN, etc.
|
||||
*
|
||||
* Note that for specific functionality, we test using autoconf. Still it's
|
||||
* best to stick to ANSI C, POSIX.1, and POSIX.2, in that order, for maximum
|
||||
* portability.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
/* HPUX - if this is no longer needed, please remove it */
|
||||
#ifdef _HPUX
|
||||
#define _HPUX_SOURCE
|
||||
#endif
|
||||
|
||||
/* A/IX - if this is no longer needed, please remove it */
|
||||
#ifdef _AIX
|
||||
#define _ALL_SOURCE
|
||||
#endif
|
||||
|
||||
/* Add others here as needed. */
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Configuration settings
|
||||
*
|
||||
* Some of the macros set during configuration are described here.
|
||||
*
|
||||
* If HAVE_TERMIOS_H is set, we employ POSIX.1 tty terminal I/O. One purpose
|
||||
* of this is to select character-oriented (CBREAK) i/o in the tek driver and
|
||||
* all its variants. It is usable without this but not as powerful. The
|
||||
* reason for using this is that some supported systems are still not
|
||||
* POSIX.1 compliant (and some may never be).
|
||||
*
|
||||
* If STDC_HEADERS is defined, the system's libc is ANSI-compliant.
|
||||
* ANSI libc calls are used for: (a) setting up handlers to be called
|
||||
* before program exit (via the "atexit" call), and (b) for seek
|
||||
* operations. Again, the code is usable without these. An ANSI libc
|
||||
* should be available, given the requirement of an ANSI compiler. Some
|
||||
* reasons why not: (a) the vendor didn't supply a complete ANSI
|
||||
* environment, or (b) the ANSI libc calls are buggy, or (c) you ported
|
||||
* gcc to your system but not glibc (for whatever reason). Note: without
|
||||
* an ANSI C lib, if you ^C out of a program using one of the PLplot tek
|
||||
* drivers, your terminal may be left in a strange state.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
#include "plConfig.h"
|
||||
#ifdef caddr_t
|
||||
#undef caddr_t
|
||||
#ifndef __USE_BSD
|
||||
typedef char * caddr_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* System headers */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <float.h>
|
||||
|
||||
#if HAVE_DIRENT_H
|
||||
# include <dirent.h>
|
||||
# define NAMLEN(dirent) strlen((dirent)->d_name)
|
||||
#else
|
||||
# define dirent direct
|
||||
# define NAMLEN(dirent) (dirent)->d_namlen
|
||||
# if HAVE_SYS_NDIR_H
|
||||
# include <sys/ndir.h>
|
||||
# endif
|
||||
# if HAVE_SYS_DIR_H
|
||||
# include <sys/dir.h>
|
||||
# endif
|
||||
# if HAVE_NDIR_H
|
||||
# include <ndir.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Macros for file positioning. I tried switching to f[sg]etpos() because I
|
||||
* like the semantics better, but ran into the problem that fpos_t is not
|
||||
* always a base type (it may be a struct). This is a problem because the
|
||||
* metafile driver needs to write relative offsets into the file itself. So
|
||||
* instead we use f{seek,tell} at a low level but keep the f[sg]etpos
|
||||
* semantics using these macros.
|
||||
*/
|
||||
|
||||
#ifdef STDC_FPOS_T
|
||||
#undef STDC_FPOS_T
|
||||
#endif
|
||||
|
||||
#ifdef STDC_FPOS_T
|
||||
#define FPOS_T fpos_t
|
||||
#define pl_fsetpos(a,b) fsetpos(a, b)
|
||||
#define pl_fgetpos(a,b) fgetpos(a, b)
|
||||
|
||||
#else
|
||||
#define FPOS_T long
|
||||
#define pl_fsetpos(a,b) fseek(a, *b, 0)
|
||||
#define pl_fgetpos(a,b) (-1L == (*b = ftell(a)))
|
||||
#endif
|
||||
|
||||
/* Include all externally-visible definitions and prototypes */
|
||||
/* plplot.h also includes some handy system header files */
|
||||
|
||||
#include "plplot.h"
|
||||
|
||||
/* plstream definition */
|
||||
|
||||
#include "plstrm.h"
|
||||
|
||||
/* If not including this file from inside of plcore.h, declare plsc */
|
||||
|
||||
#ifndef __PLCORE_H__
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
extern PLStream *plsc;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#include "pldebug.h"
|
||||
#endif
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Utility macros
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
/* Used to help ensure everything malloc'ed gets freed */
|
||||
|
||||
#define free_mem(a) \
|
||||
if (a != NULL) { free((void *) a); a = NULL; }
|
||||
|
||||
/* Allows multi-argument setup calls to not affect selected arguments */
|
||||
|
||||
#define plsetvar(a, b) \
|
||||
if (b != PL_NOTSET) a = b;
|
||||
|
||||
/* Lots of cool math macros */
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
#ifndef ABS
|
||||
#define ABS(a) ((a)<0 ? -(a) : (a))
|
||||
#endif
|
||||
#ifndef ROUND
|
||||
#define ROUND(a) (PLINT)((a)<0. ? ((a)-.5) : ((a)+.5))
|
||||
#endif
|
||||
#ifndef BETW
|
||||
#define BETW(ix,ia,ib) (((ix)<=(ia)&&(ix)>=(ib)) || ((ix)>=(ia)&&(ix)<=(ib)))
|
||||
#endif
|
||||
#ifndef SSQR
|
||||
#define SSQR(a,b) sqrt((a)*(a)+(b)*(b))
|
||||
#endif
|
||||
#ifndef SIGN
|
||||
#define SIGN(a) ((a)<0 ? -1 : 1)
|
||||
#endif
|
||||
|
||||
/* A coordinate value that should never occur */
|
||||
|
||||
#define PL_UNDEFINED -9999999
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* PLPLOT control macros
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
/* Some constants */
|
||||
|
||||
#define PL_MAXPOLY 256 /* Max segments in polyline or polygon */
|
||||
#define PL_NSTREAMS 100 /* Max number of concurrent streams. */
|
||||
#define PL_RGB_COLOR 1<<7 /* A hack */
|
||||
|
||||
#define TEXT_MODE 0
|
||||
#define GRAPHICS_MODE 1
|
||||
#ifndef PI
|
||||
#define PI 3.1415926535897932384
|
||||
#endif
|
||||
|
||||
/* These define the virtual coordinate system used by the metafile driver.
|
||||
Others are free to use it, or some variation, or define their own. */
|
||||
|
||||
/* Note desktop monitors of reasonable quality typically have 0.25 mm spacing
|
||||
* between dots which corresponds to 4.0 dots per mm. The parameters here
|
||||
* roughly correspond to a 14" monitor at 1024x768 resolution, which should
|
||||
* work fine at other sizes/resolutions. The number of virtual dots per mm is
|
||||
* scaled by a factor of 32, with pixels scaled accordingly. The customary
|
||||
* x/y ratio of 4:3 is used.
|
||||
*/
|
||||
|
||||
#define PIXELS_X 32768 /* Number of virtual pixels in x */
|
||||
#define PIXELS_Y 24576 /* Number of virtual pixels in x */
|
||||
#define DPMM 4. /* dots per mm */
|
||||
#define VDPMM (DPMM*32) /* virtual dots per mm */
|
||||
#define LPAGE_X (PIXELS_X/VDPMM) /* virtual page length in x in mm (256) */
|
||||
#define LPAGE_Y (PIXELS_Y/VDPMM) /* virtual page length in y in mm (192) */
|
||||
|
||||
/* This defines the first argument of the plRotPhy invocation that is made
|
||||
* in a number of device drivers (e.g., found in ljii.c, ljiip.c, ps.c,
|
||||
* and pstex.c) to rotate them "permanently" from portrait mode to non-
|
||||
* portrait mode. ORIENTATION of 1 corresponds to seascape mode (90 deg
|
||||
* clockwise rotation from portrait). This is the traditional value
|
||||
* effectively used in all older versions of PLplot. ORIENTATION of 3
|
||||
* corresponds to landscape mode (90 deg *counter*-clockwise rotation from
|
||||
* portrait) which is the new default non-portrait orientation. */
|
||||
|
||||
#define ORIENTATION 3
|
||||
|
||||
/* Switches for state function call. */
|
||||
|
||||
#define PLSTATE_WIDTH 1 /* pen width */
|
||||
#define PLSTATE_COLOR0 2 /* change to color in cmap 0 */
|
||||
#define PLSTATE_COLOR1 3 /* change to color in cmap 1 */
|
||||
#define PLSTATE_FILL 4 /* set area fill attribute */
|
||||
#define PLSTATE_CMAP0 5 /* change to cmap 0 */
|
||||
#define PLSTATE_CMAP1 6 /* change to cmap 1 */
|
||||
|
||||
/* Bit switches used in the driver interface */
|
||||
|
||||
#define PLDI_MAP 0x01
|
||||
#define PLDI_ORI 0x02
|
||||
#define PLDI_PLT 0x04
|
||||
#define PLDI_DEV 0x08
|
||||
|
||||
/* Default size for family files, in KB. */
|
||||
|
||||
#ifndef PL_FILESIZE_KB
|
||||
#define PL_FILESIZE_KB 1000
|
||||
#endif
|
||||
|
||||
/* Font file names. */
|
||||
|
||||
#define PLPLOT5_FONTS
|
||||
|
||||
#ifdef PLPLOT5_FONTS
|
||||
#define PL_XFONT "plxtnd5.fnt"
|
||||
#define PL_SFONT "plstnd5.fnt"
|
||||
#else
|
||||
#define PL_XFONT "plxtnd4.fnt"
|
||||
#define PL_SFONT "plstnd4.fnt"
|
||||
#endif
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* The following environment variables are defined:
|
||||
*
|
||||
* PLPLOT_BIN # where to find executables
|
||||
* PLPLOT_LIB # where to find library files (fonts, maps, etc)
|
||||
* PLPLOT_TCL # where to find tcl scripts
|
||||
*
|
||||
* PLPLOT_HOME # basename of plplot hierarchy
|
||||
*
|
||||
* search order:
|
||||
* 1) the most specific possible locators, one of
|
||||
* $(PLPLOT_BIN)
|
||||
* $(PLPLOT_LIB)
|
||||
* $(PLPLOT_TCL)
|
||||
* as appropriate
|
||||
*
|
||||
* 2) the current directory
|
||||
*
|
||||
* 3) one of $(PLPLOT_HOME)/bin
|
||||
* $(PLPLOT_HOME)/lib
|
||||
* $(PLPLOT_HOME)/tcl
|
||||
* as appropriate
|
||||
*
|
||||
* 4) as appropriate, the compile-time (Makefile)
|
||||
* BIN_DIR, LIB_DIR, TCL_DIR
|
||||
*
|
||||
* 8 Jun 1994 mj olesen (olesen@weber.me.queensu.ca)
|
||||
*
|
||||
* Other notes:
|
||||
*
|
||||
* In addition to the directories above, the following are also used:
|
||||
*
|
||||
* Lib file search path: PLLIBDEV (see plctrl.c). This is checked last,
|
||||
* and is a system-dependent hardwired location.
|
||||
*
|
||||
* Tcl search path: $HOME/tcl is searched before the install location,
|
||||
* TCL_DIR.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
#define PLPLOT_BIN_ENV "PLPLOT_BIN"
|
||||
#define PLPLOT_LIB_ENV "PLPLOT_LIB"
|
||||
#define PLPLOT_TCL_ENV "PLPLOT_TCL"
|
||||
#define PLPLOT_HOME_ENV "PLPLOT_HOME"
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Function Prototypes
|
||||
*
|
||||
* These typically should not be called directly by the user.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Determines interval between numeric labels */
|
||||
|
||||
void
|
||||
pldtik(PLFLT vmin, PLFLT vmax, PLFLT *tick, PLINT *nsubt);
|
||||
|
||||
/* Determines precision of box labels */
|
||||
|
||||
void
|
||||
pldprec(PLFLT vmin, PLFLT vmax, PLFLT tick, PLINT lf,
|
||||
PLINT *mode, PLINT *prec, PLINT digmax, PLINT *scale);
|
||||
|
||||
/* Draws a polyline within the clip limits. */
|
||||
|
||||
void
|
||||
plP_pllclp(PLINT *x, PLINT *y, PLINT npts,
|
||||
PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax,
|
||||
void (*draw) (short *, short *, PLINT));
|
||||
|
||||
/* Fills a polygon within the clip limits. */
|
||||
|
||||
void
|
||||
plP_plfclp(PLINT *x, PLINT *y, PLINT npts,
|
||||
PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax,
|
||||
void (*draw) (short *, short *, PLINT));
|
||||
|
||||
/* Clip a polygon to the 3d bounding plane */
|
||||
int
|
||||
plP_clip_poly(int Ni, PLFLT *Vi[3], int axis, PLFLT dir, PLFLT offset);
|
||||
|
||||
/* Pattern fills in software the polygon bounded by the input points. */
|
||||
|
||||
void
|
||||
plfill_soft(short *x, short *y, PLINT npts);
|
||||
|
||||
/* In case of an abort this routine is called. It just prints out an */
|
||||
/* error message and tries to clean up as much as possible. */
|
||||
|
||||
void
|
||||
plexit(char *errormsg);
|
||||
|
||||
/* Just a front-end to exit(). */
|
||||
|
||||
void
|
||||
pl_exit(void);
|
||||
|
||||
/* A handy way to issue warnings, if need be. */
|
||||
|
||||
void
|
||||
plwarn(char *errormsg);
|
||||
|
||||
/* Same as plwarn(), but appends ", aborting plot" to the error message */
|
||||
|
||||
void
|
||||
plabort(char *errormsg);
|
||||
|
||||
/* Loads either the standard or extended font. */
|
||||
|
||||
void
|
||||
plfntld(PLINT fnt);
|
||||
|
||||
/* Release memory for fonts. */
|
||||
|
||||
void
|
||||
plfontrel(void);
|
||||
|
||||
/* A replacement for strdup(), which isn't portable. */
|
||||
|
||||
char *
|
||||
plstrdup(const char *src);
|
||||
|
||||
/* Bin up cmap 1 space and assign colors to make inverse mapping easy. */
|
||||
|
||||
void
|
||||
plcmap1_calc(void);
|
||||
|
||||
/* Draws a slanting tick at position (mx,my) (measured in mm) of */
|
||||
/* vector length (dx,dy). */
|
||||
|
||||
void
|
||||
plstik(PLFLT mx, PLFLT my, PLFLT dx, PLFLT dy);
|
||||
|
||||
/* Prints out a "string" at reference position with physical coordinates */
|
||||
/* (refx,refy). */
|
||||
|
||||
void
|
||||
plstr(PLINT base, PLFLT *xform, PLINT refx, PLINT refy, const char *string);
|
||||
|
||||
/* Draws a tick parallel to x. */
|
||||
|
||||
void
|
||||
plxtik(PLINT x, PLINT y, PLINT below, PLINT above);
|
||||
|
||||
/* Draws a tick parallel to y. */
|
||||
|
||||
void
|
||||
plytik(PLINT x, PLINT y, PLINT left, PLINT right);
|
||||
|
||||
/* Driver interface filter --
|
||||
passes all coordinates through a variety of filters. */
|
||||
|
||||
void
|
||||
difilt(PLINT *, PLINT *, PLINT,
|
||||
PLINT *, PLINT *, PLINT *, PLINT *);
|
||||
|
||||
/* Driver draws text */
|
||||
|
||||
void
|
||||
plP_text(PLINT base, PLFLT just, PLFLT *xform, PLINT x, PLINT y,
|
||||
PLINT refx, PLINT refy, const char *string);
|
||||
|
||||
/* where should structure definitions that must be seen by drivers and core source files, be? */
|
||||
|
||||
/* structure to be used by plcore.c and anydriver.c, related to plP_text() */
|
||||
|
||||
typedef struct {
|
||||
PLINT base; /* ref point at base(1) or center(0) of text. Currently plplot only use 0 */
|
||||
PLFLT just; /* continuos justification, 0 left, 0.5 center, 1 right */
|
||||
PLFLT *xform; /* transformation (rotation) matrix */
|
||||
PLINT x; /* raw reference point--after any transformation */
|
||||
PLINT y;
|
||||
PLINT refx; /* processed ref. point--after justification, displacement, etc, processing */
|
||||
PLINT refy;
|
||||
const char *string; /* text to draw */
|
||||
}EscText;
|
||||
|
||||
/*
|
||||
* structure that contains driver specific information, to be used by plargs.c and anydriver.c,
|
||||
* related to plParseDrvOpts() and plHelpDrvOpts()
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
char *opt; /* a string with the name of the option */
|
||||
PLINT type; /* the type of the variable to be set, see bellow the available types */
|
||||
void *var_ptr; /* a pointer to the variable to be set */
|
||||
char *hlp_msg; /* help message of the option */
|
||||
} DrvOpt;
|
||||
|
||||
/* the available variable types, DrvOpt.type, for driver specific options */
|
||||
|
||||
enum {DRV_INT, DRV_FLT, DRV_STR};
|
||||
|
||||
/* parse driver specific options, as in -drvopt <option[=value]>* */
|
||||
|
||||
int
|
||||
plParseDrvOpts(DrvOpt *);
|
||||
|
||||
/* give help on driver specific options */
|
||||
|
||||
void
|
||||
plHelpDrvOpts(DrvOpt *);
|
||||
|
||||
/*
|
||||
* structures to store contour lines
|
||||
*/
|
||||
|
||||
#define LINE_ITEMS 20
|
||||
|
||||
typedef struct cont_line {
|
||||
PLFLT *x;
|
||||
PLFLT *y;
|
||||
PLINT npts;
|
||||
struct cont_line *next;
|
||||
} CONT_LINE;
|
||||
|
||||
typedef struct cont_level {
|
||||
PLFLT level;
|
||||
struct cont_line *line; /* contour line */
|
||||
struct cont_level *next; /* contour level */
|
||||
} CONT_LEVEL;
|
||||
|
||||
void
|
||||
cont_store(PLFLT *x, PLFLT *y, PLFLT **f, PLINT nx, PLINT ny, PLINT kx, PLINT lx,
|
||||
PLINT ky, PLINT ly, PLFLT *clevel, PLINT nlevel, CONT_LEVEL **contour);
|
||||
void
|
||||
cont_clean_store(CONT_LEVEL *ct);
|
||||
|
||||
/* Get x-y domain in world coordinates for 3d plots */
|
||||
|
||||
void
|
||||
plP_gdom(PLFLT *p_xmin, PLFLT *p_xmax, PLFLT *p_ymin, PLFLT *p_ymax);
|
||||
|
||||
/* Get vertical (z) scale parameters for 3-d plot */
|
||||
|
||||
void
|
||||
plP_grange(PLFLT *p_zscl, PLFLT *p_zmin, PLFLT *p_zmax);
|
||||
|
||||
/* Get parameters used in 3d plots */
|
||||
|
||||
void
|
||||
plP_gw3wc(PLFLT *p_dxx, PLFLT *p_dxy, PLFLT *p_dyx, PLFLT *p_dyy,
|
||||
PLFLT *p_dyz);
|
||||
|
||||
/* Get clip boundaries in physical coordinates */
|
||||
|
||||
void
|
||||
plP_gclp(PLINT *p_ixmin, PLINT *p_ixmax, PLINT *p_iymin, PLINT *p_iymax);
|
||||
|
||||
/* Set clip boundaries in physical coordinates */
|
||||
|
||||
void
|
||||
plP_sclp(PLINT ixmin, PLINT ixmax, PLINT iymin, PLINT iymax);
|
||||
|
||||
/* Get physical device limits in physical coordinates */
|
||||
|
||||
void
|
||||
plP_gphy(PLINT *p_ixmin, PLINT *p_ixmax, PLINT *p_iymin, PLINT *p_iymax);
|
||||
|
||||
/* Get number of subpages on physical device and current subpage */
|
||||
|
||||
void
|
||||
plP_gsub(PLINT *p_nx, PLINT *p_ny, PLINT *p_cs);
|
||||
|
||||
/* Set number of subpages on physical device and current subpage */
|
||||
|
||||
void
|
||||
plP_ssub(PLINT nx, PLINT ny, PLINT cs);
|
||||
|
||||
/* Set up plot parameters according to the number of subpages. */
|
||||
|
||||
void
|
||||
plP_subpInit(void);
|
||||
|
||||
/* Get number of pixels to a millimeter */
|
||||
|
||||
void
|
||||
plP_gpixmm(PLFLT *p_x, PLFLT *p_y);
|
||||
|
||||
/* All the drivers call this to set physical pixels/mm. */
|
||||
|
||||
void
|
||||
plP_setpxl(PLFLT xpmm0, PLFLT ypmm0);
|
||||
|
||||
/* Get background parameters for 3d plot. */
|
||||
|
||||
void
|
||||
plP_gzback(PLINT **zbf, PLINT **zbc, PLFLT **zbt);
|
||||
|
||||
/* Move to physical coordinates (x,y). */
|
||||
|
||||
void
|
||||
plP_movphy(PLINT x, PLINT y);
|
||||
|
||||
/* Draw to physical coordinates (x,y). */
|
||||
|
||||
void
|
||||
plP_draphy(PLINT x, PLINT y);
|
||||
|
||||
/* Move to world coordinates (x,y). */
|
||||
|
||||
void
|
||||
plP_movwor(PLFLT x, PLFLT y);
|
||||
|
||||
/* Draw to world coordinates (x,y). */
|
||||
|
||||
void
|
||||
plP_drawor(PLFLT x, PLFLT y);
|
||||
|
||||
/* Draw polyline in physical coordinates. */
|
||||
|
||||
void
|
||||
plP_draphy_poly(PLINT *x, PLINT *y, PLINT n);
|
||||
|
||||
/* Draw polyline in world coordinates. */
|
||||
|
||||
void
|
||||
plP_drawor_poly(PLFLT *x, PLFLT *y, PLINT n);
|
||||
|
||||
/* Sets up physical limits of plotting device. */
|
||||
|
||||
void
|
||||
plP_setphy(PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax);
|
||||
|
||||
/* Set up the subpage boundaries according to the current subpage selected */
|
||||
|
||||
void
|
||||
plP_setsub(void);
|
||||
|
||||
/* Get the floating point precision (in number of places) in numeric labels. */
|
||||
|
||||
void
|
||||
plP_gprec(PLINT *p_setp, PLINT *p_prec);
|
||||
|
||||
/* Computes the length of a string in mm, including escape sequences. */
|
||||
|
||||
PLFLT
|
||||
plstrl(const char *string);
|
||||
|
||||
/* Similar to strpos, but searches for occurrence of string str2. */
|
||||
|
||||
PLINT
|
||||
plP_stindex(const char *str1, const char *str2);
|
||||
|
||||
/* Searches string str for first occurrence of character chr. */
|
||||
|
||||
PLINT
|
||||
plP_strpos(char *str, int chr);
|
||||
|
||||
/* Searches string str for character chr (case insensitive). */
|
||||
|
||||
PLINT
|
||||
plP_stsearch(const char *str, int chr);
|
||||
|
||||
/* Conversion functions */
|
||||
|
||||
/* device coords to physical coords (x) */
|
||||
|
||||
PLINT
|
||||
plP_dcpcx(PLFLT x);
|
||||
|
||||
/* device coords to physical coords (y) */
|
||||
|
||||
PLINT
|
||||
plP_dcpcy(PLFLT y);
|
||||
|
||||
/* millimeters from bottom left-hand corner to physical coords (x) */
|
||||
|
||||
PLINT
|
||||
plP_mmpcx(PLFLT x);
|
||||
|
||||
/* millimeters from bottom left-hand corner to physical coords (y) */
|
||||
|
||||
PLINT
|
||||
plP_mmpcy(PLFLT y);
|
||||
|
||||
/* world coords to physical coords (x) */
|
||||
|
||||
PLINT
|
||||
plP_wcpcx(PLFLT x);
|
||||
|
||||
/* world coords to physical coords (y) */
|
||||
|
||||
PLINT
|
||||
plP_wcpcy(PLFLT y);
|
||||
|
||||
/* physical coords to device coords (x) */
|
||||
|
||||
PLFLT
|
||||
plP_pcdcx(PLINT x);
|
||||
|
||||
/* physical coords to device coords (y) */
|
||||
|
||||
PLFLT
|
||||
plP_pcdcy(PLINT y);
|
||||
|
||||
/* millimeters from bottom left corner to device coords (x) */
|
||||
|
||||
PLFLT
|
||||
plP_mmdcx(PLFLT x);
|
||||
|
||||
/* millimeters from bottom left corner to device coords (y) */
|
||||
|
||||
PLFLT
|
||||
plP_mmdcy(PLFLT y);
|
||||
|
||||
/* world coords into device coords (x) */
|
||||
|
||||
PLFLT
|
||||
plP_wcdcx(PLFLT x);
|
||||
|
||||
/* world coords into device coords (y) */
|
||||
|
||||
PLFLT
|
||||
plP_wcdcy(PLFLT y);
|
||||
|
||||
/* subpage coords to device coords (x) */
|
||||
|
||||
PLFLT
|
||||
plP_scdcx(PLFLT x);
|
||||
|
||||
/* subpage coords to device coords (y) */
|
||||
|
||||
PLFLT
|
||||
plP_scdcy(PLFLT y);
|
||||
|
||||
/* device coords to millimeters from bottom left-hand corner (x) */
|
||||
|
||||
PLFLT
|
||||
plP_dcmmx(PLFLT x);
|
||||
|
||||
/* device coords to millimeters from bottom left-hand corner (y) */
|
||||
|
||||
PLFLT
|
||||
plP_dcmmy(PLFLT y);
|
||||
|
||||
/* world coords into millimeters (x) */
|
||||
|
||||
PLFLT
|
||||
plP_wcmmx(PLFLT x);
|
||||
|
||||
/* world coords into millimeters (y) */
|
||||
|
||||
PLFLT
|
||||
plP_wcmmy(PLFLT y);
|
||||
|
||||
/* device coords to subpage coords (x) */
|
||||
|
||||
PLFLT
|
||||
plP_dcscx(PLFLT x);
|
||||
|
||||
/* device coords to subpage coords (y) */
|
||||
|
||||
PLFLT
|
||||
plP_dcscy(PLFLT y);
|
||||
|
||||
/* 3-d coords to 2-d projection (x) */
|
||||
|
||||
PLFLT
|
||||
plP_w3wcx(PLFLT x, PLFLT y, PLFLT z);
|
||||
|
||||
/* 3-d coords to 2-d projection (y) */
|
||||
|
||||
PLFLT
|
||||
plP_w3wcy(PLFLT x, PLFLT y, PLFLT z);
|
||||
|
||||
/* Driver calls */
|
||||
|
||||
/* Initialize device. */
|
||||
|
||||
void
|
||||
plP_init(void);
|
||||
|
||||
/* Draw line between two points */
|
||||
|
||||
void
|
||||
plP_line(short *x, short *y);
|
||||
|
||||
/* Draw polyline */
|
||||
|
||||
void
|
||||
plP_polyline(short *x, short *y, PLINT npts);
|
||||
|
||||
/* Fill polygon */
|
||||
|
||||
void
|
||||
plP_fill(short *x, short *y, PLINT npts);
|
||||
|
||||
/* draw image */
|
||||
|
||||
void
|
||||
plP_image(short *x, short *y, unsigned short *z, PLINT nx, PLINT ny, PLFLT xmin, PLFLT ymin, PLFLT dx, PLFLT dy, unsigned short zmin, unsigned short zmax);
|
||||
|
||||
/* End of page */
|
||||
|
||||
void
|
||||
plP_eop(void);
|
||||
|
||||
/* End of page */
|
||||
|
||||
void
|
||||
plP_bop(void);
|
||||
|
||||
/* Tidy up device (flush buffers, close file, etc.) */
|
||||
|
||||
void
|
||||
plP_tidy(void);
|
||||
|
||||
/* Change state. */
|
||||
|
||||
void
|
||||
plP_state(PLINT op);
|
||||
|
||||
/* Escape function, for driver-specific commands. */
|
||||
|
||||
void
|
||||
plP_esc(PLINT op, void *ptr);
|
||||
|
||||
/* Set up plot window parameters. */
|
||||
|
||||
void
|
||||
plP_swin(PLWindow *plwin);
|
||||
|
||||
/* Return file pointer to lib file. */
|
||||
|
||||
FILE *
|
||||
plLibOpen(char *fn);
|
||||
|
||||
/* Does required startup initialization of library. */
|
||||
|
||||
void
|
||||
pllib_init(void);
|
||||
|
||||
/* Does preliminary setup of device driver. */
|
||||
|
||||
void
|
||||
pllib_devinit(void);
|
||||
|
||||
/* Utility to copy one PLColor to another. */
|
||||
|
||||
void
|
||||
pl_cpcolor(PLColor *to, PLColor *from);
|
||||
|
||||
/* Does required startup initialization of a stream. */
|
||||
|
||||
void
|
||||
plstrm_init(void);
|
||||
|
||||
/* Builds a list of the active devices/streams by device name */
|
||||
|
||||
void
|
||||
plP_getinitdriverlist(char *names);
|
||||
|
||||
/* Checks a give list of device names against active streams and returns the number of matches */
|
||||
|
||||
PLINT
|
||||
plP_checkdriverinit( char *names);
|
||||
|
||||
/* disable writing to plot buffer and pixmap */
|
||||
void
|
||||
NoBufferNoPixmap(void);
|
||||
|
||||
/* restart writing to plot buffer and pixmap */
|
||||
void
|
||||
RestoreWrite2BufferPixmap(void);
|
||||
|
||||
void
|
||||
grimage(short *x, short *y, unsigned short *z, PLINT nx, PLINT ny);
|
||||
|
||||
void
|
||||
plimageslow(short *x, short *y, unsigned short *data, PLINT nx, PLINT ny,
|
||||
PLFLT xmin, PLFLT ymin, PLFLT dx, PLFLT dy,
|
||||
unsigned short zmin, unsigned short zmax);
|
||||
|
||||
typedef struct {
|
||||
PLFLT xmin, ymin, dx, dy;} IMG_DT;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PLPLOTP_H__ */
|
|
@ -1,335 +0,0 @@
|
|||
/* $Id: plsdef.c,v 1.1 2004/03/01 20:54:52 cozmic Exp $
|
||||
|
||||
Routines to set various plplot parameters, such as char height,
|
||||
symbol size, tick length, line and fill patterns, etc.
|
||||
*/
|
||||
|
||||
#include "plplotP.h"
|
||||
|
||||
/* Line pattern defaults */
|
||||
|
||||
static struct line {
|
||||
PLINT nels;
|
||||
PLINT mark[4];
|
||||
PLINT space[4];
|
||||
} line[] = {
|
||||
|
||||
{
|
||||
0, /* Continuous line */
|
||||
{
|
||||
0, 0, 0, 0
|
||||
},
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
},
|
||||
{
|
||||
1,
|
||||
{
|
||||
1000, 0, 0, 0
|
||||
},
|
||||
{
|
||||
1000, 0, 0, 0
|
||||
}
|
||||
},
|
||||
{
|
||||
1,
|
||||
{
|
||||
2000, 0, 0, 0
|
||||
},
|
||||
{
|
||||
2000, 0, 0, 0
|
||||
}
|
||||
},
|
||||
{
|
||||
1,
|
||||
{
|
||||
2000, 0, 0, 0
|
||||
},
|
||||
{
|
||||
1000, 0, 0, 0
|
||||
}
|
||||
},
|
||||
{
|
||||
2,
|
||||
{
|
||||
2500, 1000, 0, 0
|
||||
},
|
||||
{
|
||||
1000, 1000, 0, 0
|
||||
}
|
||||
},
|
||||
{
|
||||
2,
|
||||
{
|
||||
2000, 1000, 0, 0
|
||||
},
|
||||
{
|
||||
2000, 1000, 0, 0
|
||||
}
|
||||
},
|
||||
{
|
||||
3,
|
||||
{
|
||||
1000, 1500, 2000, 0
|
||||
},
|
||||
{
|
||||
1000, 1500, 2000, 0
|
||||
}
|
||||
},
|
||||
{
|
||||
3,
|
||||
{
|
||||
1000, 1500, 2000, 0
|
||||
},
|
||||
{
|
||||
1000, 1000, 1000, 0
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* Fill pattern defaults */
|
||||
|
||||
static struct pattern {
|
||||
PLINT nlines; /* Number of lines in pattern (1 or 2) */
|
||||
PLINT inc[2]; /* Inclination 10 ths of degrees */
|
||||
PLINT del[2]; /* Spacing for each line */
|
||||
} pattern[] = {
|
||||
|
||||
{
|
||||
1,
|
||||
{
|
||||
0, 0
|
||||
},
|
||||
{
|
||||
2000, 0
|
||||
}
|
||||
},
|
||||
{
|
||||
1,
|
||||
{
|
||||
900, 0
|
||||
},
|
||||
{
|
||||
2000, 0
|
||||
}
|
||||
},
|
||||
{
|
||||
1,
|
||||
{
|
||||
450, 0
|
||||
},
|
||||
{
|
||||
2000, 0
|
||||
}
|
||||
},
|
||||
{
|
||||
1,
|
||||
{
|
||||
-450, 0
|
||||
},
|
||||
{
|
||||
2000, 0
|
||||
}
|
||||
},
|
||||
{
|
||||
1,
|
||||
{
|
||||
300, 0
|
||||
},
|
||||
{
|
||||
2000, 0
|
||||
}
|
||||
},
|
||||
{
|
||||
1,
|
||||
{
|
||||
-300, 0
|
||||
},
|
||||
{
|
||||
2000, 0
|
||||
}
|
||||
},
|
||||
{
|
||||
2,
|
||||
{
|
||||
0, 900
|
||||
},
|
||||
{
|
||||
2000, 2000
|
||||
}
|
||||
},
|
||||
{
|
||||
2,
|
||||
{
|
||||
450, -450
|
||||
},
|
||||
{
|
||||
2000, 2000
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* Set defining parameters for pattern fill */
|
||||
|
||||
static void
|
||||
spat(PLINT inc[], PLINT del[], PLINT nlin);
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plschr()
|
||||
*
|
||||
* Set character height.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plschr(PLFLT def, PLFLT scale)
|
||||
{
|
||||
if (def != 0.0)
|
||||
plsc->chrdef = def;
|
||||
|
||||
plsc->chrht = scale * plsc->chrdef;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plsmin()
|
||||
*
|
||||
* Set up lengths of minor tick marks.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plsmin(PLFLT def, PLFLT scale)
|
||||
{
|
||||
if (def != 0.0)
|
||||
plsc->mindef = def;
|
||||
|
||||
plsc->minht = scale * plsc->mindef;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plsmaj()
|
||||
*
|
||||
* Set up lengths of major tick marks.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plsmaj(PLFLT def, PLFLT scale)
|
||||
{
|
||||
if (def != 0.0)
|
||||
plsc->majdef = def;
|
||||
|
||||
plsc->majht = scale * plsc->majdef;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plssym()
|
||||
*
|
||||
* Set symbol height.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plssym(PLFLT def, PLFLT scale)
|
||||
{
|
||||
if (def != 0.0)
|
||||
plsc->symdef = def;
|
||||
|
||||
plsc->symht = scale * plsc->symdef;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void pllsty()
|
||||
*
|
||||
* Set line style.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_pllsty(PLINT lin)
|
||||
{
|
||||
if (plsc->level < 1) {
|
||||
plabort("pllsty: Please call plinit first");
|
||||
return;
|
||||
}
|
||||
if (lin < 1 || lin > 8) {
|
||||
plabort("pllsty: Invalid line style");
|
||||
return;
|
||||
}
|
||||
|
||||
plstyl(line[lin - 1].nels,
|
||||
&line[lin - 1].mark[0], &line[lin - 1].space[0]);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plpat()
|
||||
*
|
||||
* Set fill pattern directly.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plpat(PLINT nlin, PLINT *inc, PLINT *del)
|
||||
{
|
||||
PLINT i;
|
||||
|
||||
if (plsc->level < 1) {
|
||||
plabort("plpat: Please call plinit first");
|
||||
return;
|
||||
}
|
||||
if (nlin < 1 || nlin > 2) {
|
||||
plabort("plpat: Only 1 or 2 line styles allowed");
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < nlin; i++) {
|
||||
if (del[i] < 0) {
|
||||
plabort("plpat: Line spacing must be greater than 0");
|
||||
return;
|
||||
}
|
||||
}
|
||||
spat(inc, del, nlin);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plpsty()
|
||||
*
|
||||
* Set fill pattern, using one of the predefined patterns.
|
||||
* A fill pattern <= 0 indicates hardware fill.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plpsty(PLINT patt)
|
||||
{
|
||||
if (plsc->level < 1) {
|
||||
plabort("plpsty: Please call plinit first");
|
||||
return;
|
||||
}
|
||||
if (patt > 8) {
|
||||
plabort("plpsty: Invalid pattern");
|
||||
return;
|
||||
}
|
||||
if (patt != plsc->patt) {
|
||||
plsc->patt = patt;
|
||||
|
||||
if (plsc->level > 0) {
|
||||
plP_state(PLSTATE_FILL);
|
||||
}
|
||||
}
|
||||
if (patt > 0) {
|
||||
spat(&pattern[patt - 1].inc[0], &pattern[patt - 1].del[0],
|
||||
pattern[patt - 1].nlines);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void spat()
|
||||
*
|
||||
* Set defining parameters for pattern fill
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
spat(PLINT inc[], PLINT del[], PLINT nlin)
|
||||
{
|
||||
PLINT i;
|
||||
|
||||
plsc->nps = nlin;
|
||||
for (i = 0; i < nlin; i++) {
|
||||
plsc->inclin[i] = inc[i];
|
||||
plsc->delta[i] = del[i];
|
||||
}
|
||||
}
|
|
@ -1,318 +0,0 @@
|
|||
/* $Id: plstripc.c,v 1.1 2004/03/01 20:54:53 cozmic Exp $
|
||||
|
||||
* Plots a simple stripchart.
|
||||
|
||||
* ToDo: better way of clearing plot. search for `plvsta'.
|
||||
*/
|
||||
|
||||
#include "plplotP.h"
|
||||
|
||||
/* Data declarations for stripcharts. */
|
||||
|
||||
#define PEN 4
|
||||
|
||||
typedef struct {
|
||||
PLFLT xmin, xmax, ymin, ymax, xjump, xlen;
|
||||
PLFLT wxmin, wxmax, wymin, wymax; /* FIXME - some redundancy might exist */
|
||||
char *xspec, *yspec, *labx, *laby, *labtop;
|
||||
PLINT y_ascl, acc, colbox, collab;
|
||||
PLFLT xlpos, ylpos;
|
||||
PLFLT *x[PEN], *y[PEN];
|
||||
PLINT npts[PEN], nptsmax[PEN];
|
||||
PLINT colline[PEN], styline[PEN];
|
||||
char *legline[PEN];
|
||||
} PLStrip;
|
||||
|
||||
static int sid; /* strip id number */
|
||||
#define MAX_STRIPC 1000 /* Max allowed */
|
||||
static PLStrip *strip[MAX_STRIPC]; /* Array of pointers */
|
||||
static PLStrip *stripc; /* current strip chart */
|
||||
|
||||
/* Generates a complete stripchart plot. */
|
||||
|
||||
static void
|
||||
plstrip_gen(PLStrip *strip);
|
||||
|
||||
/* draw legend */
|
||||
|
||||
static void
|
||||
plstrip_legend(PLStrip *strip, int flag);
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plstripc
|
||||
*
|
||||
* Create 1d stripchart.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plstripc( PLINT *id, char *xspec, char *yspec,
|
||||
PLFLT xmin, PLFLT xmax, PLFLT xjump, PLFLT ymin, PLFLT ymax,
|
||||
PLFLT xlpos, PLFLT ylpos,
|
||||
PLINT y_ascl, PLINT acc,
|
||||
PLINT colbox, PLINT collab,
|
||||
PLINT *colline, PLINT *styline, char *legline[],
|
||||
char *labx, char *laby, char *labtop )
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!plsc->termin) {
|
||||
plabort("Stripchart plot requires a terminal output device");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get a free strip id and allocate it */
|
||||
|
||||
for (i = 0; i < MAX_STRIPC; i++)
|
||||
if (strip[i] == NULL)
|
||||
break;
|
||||
|
||||
if (i == MAX_STRIPC) {
|
||||
plabort("plstripc: Cannot create new strip chart");
|
||||
*id = -1;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
sid = *id = i;
|
||||
strip[sid] = (PLStrip *) calloc(1, (size_t) sizeof(PLStrip));
|
||||
if (strip[sid] == NULL) {
|
||||
plabort("plstripc: Out of memory.");
|
||||
*id = -1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fill up the struct with all relevant info */
|
||||
|
||||
stripc = strip[sid];
|
||||
|
||||
for (i=0; i<PEN; i++) {
|
||||
stripc->npts[i] = 0;
|
||||
stripc->nptsmax[i] = 100;
|
||||
stripc->colline[i] = colline[i];
|
||||
stripc->styline[i] = styline[i];
|
||||
stripc->legline[i] = plstrdup(legline[i]);
|
||||
stripc->x[i] = (PLFLT *) malloc((size_t) sizeof(PLFLT) * stripc->nptsmax[i]);;
|
||||
stripc->y[i] = (PLFLT *) malloc((size_t) sizeof(PLFLT) * stripc->nptsmax[i]);;
|
||||
if (stripc->x[i] == NULL || stripc->y[i] == NULL) {
|
||||
plabort("plstripc: Out of memory.");
|
||||
plstripd(sid);
|
||||
*id = -1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
stripc->xlpos = xlpos; /* legend position [0..1] */
|
||||
stripc->ylpos = ylpos;
|
||||
stripc->xmin = xmin; /* initial bounding box */
|
||||
stripc->xmax = xmax;
|
||||
stripc->ymin = ymin;
|
||||
stripc->ymax = ymax;
|
||||
stripc->xjump = xjump; /* jump x step(%) when x attains xmax (xmax is then set to xmax+xjump) */
|
||||
stripc->xlen = xmax - xmin; /* length of x scale */
|
||||
stripc->y_ascl = y_ascl; /* autoscale y between x jump scale */
|
||||
stripc->acc = acc; /* accumulate plot (not really stripchart) */
|
||||
stripc->xspec = plstrdup(xspec); /* x axis specification */
|
||||
stripc->yspec = plstrdup(yspec);
|
||||
stripc->labx = plstrdup(labx); /* x label */
|
||||
stripc->laby = plstrdup(laby);
|
||||
stripc->labtop = plstrdup(labtop); /* title */
|
||||
stripc->colbox = colbox; /* box color */
|
||||
stripc->collab = collab; /* label color */
|
||||
|
||||
/* Generate the plot */
|
||||
|
||||
plstrip_gen(stripc);
|
||||
plstrip_legend(stripc,1);
|
||||
}
|
||||
|
||||
static void plstrip_legend(PLStrip *stripc, int first)
|
||||
{
|
||||
int i;
|
||||
PLFLT sc, dy;
|
||||
|
||||
/* draw legend */
|
||||
|
||||
plgchr(&sc, &dy);
|
||||
sc = dy = dy/100;
|
||||
plwind(-0.01, 1.01, -0.01, 1.01);
|
||||
for (i=0; i<PEN; i++) {
|
||||
if (stripc->npts[i] || first) {
|
||||
plcol(stripc->colline[i]); pllsty(stripc->styline[i]);
|
||||
pljoin(stripc->xlpos, stripc->ylpos - sc, stripc->xlpos + 0.1, stripc->ylpos - sc);
|
||||
plcol(stripc->collab);
|
||||
plptex(stripc->xlpos + 0.11, stripc->ylpos - sc, 0., 0., 0, stripc->legline[i]);sc += dy;
|
||||
}
|
||||
}
|
||||
plwind(stripc->xmin, stripc->xmax, stripc->ymin, stripc->ymax);
|
||||
plflush();
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plstrip_gen
|
||||
*
|
||||
* Generates a complete stripchart plot. Used either initially or
|
||||
* during rescaling.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
PLFLT oxm,oxM, oym,oyM;
|
||||
static void plstrip_gen( PLStrip *strip )
|
||||
{
|
||||
int i;
|
||||
PLFLT x[]={0.,1.,1.,0.}, y[]={0.,0.,1.,1.};
|
||||
|
||||
/* Set up window */
|
||||
|
||||
plvpor(0,1,0,1);
|
||||
plwind(0,1,0,1);
|
||||
plcol(0);plpsty(0);
|
||||
plfill(4, &x[0], &y[0]);
|
||||
plvsta();
|
||||
|
||||
/* Draw box and same window dimensions */
|
||||
strip->wxmin=strip->xmin; strip->wxmax=strip->xmax;
|
||||
strip->wymin=strip->ymin; strip->wymax=strip->ymax; /* FIXME - can exist some redundancy here */
|
||||
|
||||
plwind(strip->xmin, strip->xmax, strip->ymin, strip->ymax);
|
||||
|
||||
pllsty(1);
|
||||
plcol(strip->colbox);
|
||||
plbox(strip->xspec, 0.0, 0, strip->yspec, 0.0, 0);
|
||||
|
||||
plcol(strip->collab);
|
||||
pllab(strip->labx, strip->laby, strip->labtop);
|
||||
|
||||
for (i=0; i<PEN; i++) {
|
||||
if (strip->npts[i] > 0) {
|
||||
plcol(strip->colline[i]);pllsty(strip->styline[i]);
|
||||
plline(strip->npts[i], strip->x[i], strip->y[i]);
|
||||
}
|
||||
}
|
||||
|
||||
plstrip_legend(strip,0);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plstripa
|
||||
*
|
||||
* Add a point to a stripchart.
|
||||
* Allocates memory and rescales as necessary.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void c_plstripa( PLINT id, PLINT p, PLFLT x, PLFLT y )
|
||||
{
|
||||
int j, yasc=0, istart;
|
||||
|
||||
if (p >= PEN) {
|
||||
plabort("Non existent pen");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((id < 0) || (id >= MAX_STRIPC) ||
|
||||
((stripc = strip[id]) == NULL)) {
|
||||
plabort("Non existent stripchart");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Add new point, allocating memory if necessary */
|
||||
|
||||
if (++stripc->npts[p] > stripc->nptsmax[p]) {
|
||||
stripc->nptsmax[p] += 32;
|
||||
stripc->x[p] = (PLFLT *) realloc((void *) stripc->x[p], sizeof(PLFLT)*stripc->nptsmax[p]);
|
||||
stripc->y[p] = (PLFLT *) realloc((void *) stripc->y[p], sizeof(PLFLT)*stripc->nptsmax[p]);
|
||||
if (stripc->x[p] == NULL || stripc->y[p] == NULL) {
|
||||
plabort("plstripc: Out of memory.");
|
||||
plstripd(id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
stripc->x[p][stripc->npts[p]-1] = x;
|
||||
stripc->y[p][stripc->npts[p]-1] = y;
|
||||
|
||||
stripc->xmax = x;
|
||||
|
||||
if (stripc->y_ascl == 1 && (y > stripc->ymax || y < stripc->ymin))
|
||||
yasc=1;
|
||||
|
||||
if (y > stripc->ymax)
|
||||
stripc->ymax = stripc->ymin + 1.1*(y - stripc->ymin);
|
||||
if (y < stripc->ymin)
|
||||
stripc->ymin = stripc->ymax - 1.1*(stripc->ymax - y);
|
||||
|
||||
/* Now either plot new point or regenerate plot */
|
||||
|
||||
if (stripc->xmax - stripc->xmin < stripc->xlen) {
|
||||
if( yasc == 0) {
|
||||
|
||||
/* If user has changed subwindow, make shure we have the correct one */
|
||||
plvsta();
|
||||
plwind(stripc->wxmin, stripc->wxmax, stripc->wymin, stripc->wymax); /* FIXME - can exist some redundancy here */
|
||||
plcol(stripc->colline[p]); pllsty(stripc->styline[p]);
|
||||
if ((stripc->npts[p]-2) < 0)
|
||||
plP_movwor(stripc->x[p][stripc->npts[p]-1], stripc->y[p][stripc->npts[p]-1]);
|
||||
else
|
||||
plP_movwor(stripc->x[p][stripc->npts[p]-2], stripc->y[p][stripc->npts[p]-2]);
|
||||
plP_drawor(stripc->x[p][stripc->npts[p]-1], stripc->y[p][stripc->npts[p]-1]);
|
||||
plflush();
|
||||
}
|
||||
else {
|
||||
stripc->xmax = stripc->xmin + stripc->xlen;
|
||||
plstrip_gen(stripc);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Regenerating plot */
|
||||
if (stripc->acc == 0) {
|
||||
for (j=0; j<PEN; j++) {
|
||||
if (stripc->npts[j] > 0) {
|
||||
istart = 0;
|
||||
while (stripc->x[j][istart] < stripc->xmin + stripc->xlen*stripc->xjump)
|
||||
istart++;
|
||||
|
||||
stripc->npts[j] = stripc->npts[j] - istart;
|
||||
memcpy( &stripc->x[j][0], &stripc->x[j][istart], (stripc->npts[j])*sizeof(PLFLT));
|
||||
memcpy( &stripc->y[j][0], &stripc->y[j][istart], (stripc->npts[j])*sizeof(PLFLT));
|
||||
}
|
||||
}
|
||||
} else
|
||||
stripc->xlen = stripc->xlen * (1 + stripc->xjump);
|
||||
|
||||
stripc->xmin = stripc->x[p][0];
|
||||
stripc->xmax = stripc->xmax + stripc->xlen*stripc->xjump;
|
||||
|
||||
plstrip_gen(stripc);
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* plstripd
|
||||
*
|
||||
* Deletes and releases memory used by a stripchart.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void c_plstripd( PLINT id )
|
||||
{
|
||||
int i;
|
||||
|
||||
if ((id < 0) || (id >= MAX_STRIPC) ||
|
||||
((stripc = strip[id]) == NULL)) {
|
||||
plabort("Non existent stripchart");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i=0; i<PEN; i++) {
|
||||
if (stripc->npts[i]) {
|
||||
free((void *) stripc->x[i]);
|
||||
free((void *) stripc->y[i]);
|
||||
free(stripc->legline[i]);
|
||||
}
|
||||
}
|
||||
|
||||
free(stripc->xspec);
|
||||
free(stripc->yspec);
|
||||
free(stripc->labx);
|
||||
free(stripc->laby);
|
||||
free(stripc->labtop);
|
||||
free((void *) stripc);
|
||||
strip[id] = NULL;
|
||||
}
|
|
@ -1,681 +0,0 @@
|
|||
/* $Id: plstrm.h,v 1.1 2004/03/01 20:54:53 cozmic Exp $
|
||||
*
|
||||
* Contains declarations for PLStream and PLDev structs.
|
||||
* Also prototypes for stream & device utility functions.
|
||||
*/
|
||||
|
||||
#include "pdf.h"
|
||||
|
||||
#ifndef __PLSTRM_H__
|
||||
#define __PLSTRM_H__
|
||||
|
||||
#include "disptab.h"
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Define the PLDev data structure.
|
||||
*
|
||||
* These are all quantities that must be saved on a per-device basis.
|
||||
* Some drivers (xwin, tk) allocate structures defined internally.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
typedef struct {
|
||||
PLFLT pxlx, pxly;
|
||||
PLINT xold, yold;
|
||||
|
||||
PLINT xmin, xmax, xlen;
|
||||
PLINT ymin, ymax, ylen;
|
||||
|
||||
PLINT xmin_dev, xmax_dev, xlen_dev;
|
||||
PLINT ymin_dev, ymax_dev, ylen_dev;
|
||||
|
||||
PLFLT xscale_dev, yscale_dev;
|
||||
} PLDev;
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Define the PLStream data structure.
|
||||
*
|
||||
* This contains a copy of every variable that is stream dependent, which
|
||||
* tends to be those which are settable by the user and persist for longer
|
||||
* than one plot.
|
||||
*
|
||||
* Only those quantities listed in the PLStream struct will be preserved
|
||||
* for an individual stream. Note that the lack of every plplot constant
|
||||
* means that one should only switch streams at a fairly high level, i.e.
|
||||
* on the scale of an entire plot. Otherwise intermediate quantities
|
||||
* will be confused between the streams, possibly resulting in garbage plots.
|
||||
* This structure may be expanded in time to improve intra-stream independence,
|
||||
* but it is doubtful streams will ever be fully independent (perhaps
|
||||
* neither necessary nor desirable? -- time will tell).
|
||||
*
|
||||
* There are undoubtably some inconsistencies in the declaration & use of
|
||||
* the variables below. This is a result of the continuing evolution of
|
||||
* plplot and the numerous authors involved. Hopefully in time the function
|
||||
* of all variables can be fully documented and made more consistent.
|
||||
*
|
||||
* The quantities in each stream are as follows:
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Misc control variables
|
||||
*
|
||||
* ipls PLINT Stream number
|
||||
* level PLINT Initialization level
|
||||
* program char* Program name
|
||||
* verbose PLINT Be more verbose than usual
|
||||
* debug PLINT Generate debugging output
|
||||
* initialized PLINT Set if the stream has been initialized
|
||||
* dev_initialized PLINT Set if the device driver has been loaded
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Palettes (two of them)
|
||||
*
|
||||
* Color map 0 is intended for static objects, such as boxes, lines, points,
|
||||
* labels, etc. These should be allocated before calling plinit (else you
|
||||
* get 16 by default, which can be undesirable on some platforms). These
|
||||
* are then explicitly selected by number (in order of allocation). The
|
||||
* lowest number is 0, but this is used for the background color, so all
|
||||
* color drivers start with 1 as the default color.
|
||||
*
|
||||
* Color map 1 is for continuous-tone plots, where color is used to
|
||||
* represent function value or intensity. These are set in a relative way
|
||||
* only, for increased portability and flexibility. The actual number of
|
||||
* colors used to represent intensity levels is determined by the driver.
|
||||
* Note that it is only necessary to specify intensity (on a scale from 0
|
||||
* to 1) to get an appropriate color. Drivers incapable of fine shading
|
||||
* will do the best job they can.
|
||||
*
|
||||
* A palette selection tool for both palettes is available for the Tk
|
||||
* driver. Direct writing of RGB values (i.e. banging on the hardware) is
|
||||
* supported but highly discouraged (colors so written will be affected
|
||||
* unpredictably by the palette tools).
|
||||
*
|
||||
* icol0 PLINT Color map 0 entry, current color (0 <= icol0 <= ncol0)
|
||||
* ncol0 PLINT Number of colors allocated in color map 0.
|
||||
* icol1 PLINT Color map 1 entry, current color (0 <= icol1 <= ncol1)
|
||||
* ncol1 PLINT Number of colors allocated in color map 1.
|
||||
* ncol1cp PLINT Number of control points in cmap1 allocation (max PL_MAX_CMAP1CP)
|
||||
* lcol1cp PLFLT Locations of control points in cmap1 [0,1]
|
||||
* curcmap PLINT Current color map
|
||||
* curcolor RGB[] Current color
|
||||
* tmpcolor RGB[] Temporary color storage
|
||||
* cmap0 RGB[] Color map 0: maximum of ncol0 RGB 8-bit values
|
||||
* cmap1 RGB[] Color map 1: maximum of ncol1 RGB 8-bit values
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Variables governing pen width
|
||||
*
|
||||
* width Current pen width
|
||||
* widthset Set if pen width was specified
|
||||
* widthlock Set if pen width is locked
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Variables used to pass information between the core and the driver
|
||||
*
|
||||
* It would be nice to use the "dev_" prefix uniformly but changing
|
||||
* all that old code would be quite a lot of work..
|
||||
*
|
||||
* device PLINT Graphics device id number
|
||||
* dev_minor PLINT Minor device id (for variations on one type)
|
||||
* color PLINT Set if color is available
|
||||
* colorset PLINT Set if "color" was set prior to calling plinit
|
||||
* plbuf_read PLINT Set during a plot buffer redraw
|
||||
* plbuf_write PLINT Set if driver needs to use the plot buffer
|
||||
* dev_fill0 PLINT Set if driver can do solid area fills
|
||||
* dev_text PLINT Set if driver want to do it's only text drawing
|
||||
* dev_fill1 PLINT Set if driver can do pattern area fills
|
||||
* dev_dash PLINT Set if driver can do dashed lines
|
||||
* dev_di PLINT Set if driver wants to handle DI commands
|
||||
* dev_flush PLINT Set if driver wants to handle flushes itself
|
||||
* dev_swin PLINT Set if driver wants to handle 'set window' commands
|
||||
* dev_fastimg PLINT Set if driver has fast image drawing capabilities
|
||||
* dev_xor PLINT Set if driver supports xor mode.
|
||||
* dev_clear PLINT Set if driver support clear.
|
||||
* termin PLINT Set for interactive devices
|
||||
* graphx PLINT Set if currently in graphics mode
|
||||
* nopause PLINT Set if we are skipping the pause between frames
|
||||
* family PLINT Set if familying is enabled
|
||||
* member PLINT Number of current family member file open
|
||||
* finc PLINT Number to increment between member files
|
||||
* fflen PLINT Minimum field length to use in member file number
|
||||
* bytemax PLINT Number of bytes maximum per member file
|
||||
* famadv PLINT Set to advance to the next family member
|
||||
* DevName char* Device name
|
||||
* OutFile FILE Output file pointer
|
||||
* BaseName char* Output base name (i.e. family)
|
||||
* FileName char* Output file name
|
||||
* output_type int 0 for file, 1 for stream
|
||||
* bytecnt PLINT Byte count for output stream
|
||||
* page PLINT Page count for output stream
|
||||
* linepos PLINT Line count for output stream
|
||||
* pdfs PDFstrm* PDF stream pointer
|
||||
*
|
||||
* These are used by the escape function (for area fill, etc).
|
||||
*
|
||||
* dev_npts PLINT Number of points we are plotting
|
||||
* dev_x short* Pointer to array of x values
|
||||
* dev_y short* Pointer to array of x values
|
||||
*
|
||||
* For images
|
||||
* dev_nptsX PLINT Number of points we are plotting in X
|
||||
* dev_nptsY PLINT Number of points we are plotting in Y
|
||||
* dev_z ushort* Pointer to array of z values for the color
|
||||
* dev_zmin,
|
||||
* dev_zmax ushort Min and max values of z to plot
|
||||
*
|
||||
* The following pointer is for drivers that require device-specific
|
||||
* data. At initialization the driver should malloc the necessary
|
||||
* space and set pls->dev to point to this area. This way there can
|
||||
* be multiple streams using the same driver without conflict.
|
||||
*
|
||||
* dev void* pointer to device-specific data (malloc'ed)
|
||||
*
|
||||
* User-supplied event handlers for use by interactive drivers (e.g. X).
|
||||
* Can be used to take various actions depending on input. Currently
|
||||
* only a keyboard event handler is supported.
|
||||
*
|
||||
* KeyEH void* Keyboard event handler
|
||||
* KeyEH_data void* Pointer to client data to pass
|
||||
*
|
||||
* ButtonEH void* (Mouse) Button event handler
|
||||
* ButtonEH_data void* Pointer to client data to pass
|
||||
*
|
||||
* bop_handler void* bop handler
|
||||
* bop_data void* Pointer to client data to pass
|
||||
*
|
||||
* eop_handler void* eop handler
|
||||
* eop_data void* Pointer to client data to pass
|
||||
*
|
||||
* Variables used for direct specification of device characteristics
|
||||
* Not supported by all drivers (or even very many)
|
||||
*
|
||||
* xdpi.. PLFLT Device DPI settings in x and y
|
||||
* xlength.. PLINT Device output lengths in x and y
|
||||
* xoffset.. PLINT Device offsets from upper left hand corner
|
||||
* pageset PLINT Set if page dimensions were specified
|
||||
* hack PLINT Enables driver-specific hack(s) if set
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* User customization tidy routine. This is called before closing a stream
|
||||
* to do any program specific cleanup.
|
||||
*
|
||||
* tidy void* pointer to cleanup routine
|
||||
* tidy_data void* pointer to client data to pass
|
||||
*
|
||||
****************************************************************************
|
||||
*
|
||||
* User error control variables. Pass in a pointer for either to be set
|
||||
* in exceptional conditions. The caller is responsible for clearing the
|
||||
* error code.
|
||||
*
|
||||
* errcode PLINT* pointer to variable to assign error code
|
||||
* errmsg char* pointer to error message buffer (must be >= 160 bytes)
|
||||
*
|
||||
****************************************************************************
|
||||
*
|
||||
* Stuff used by Xlib driver
|
||||
*
|
||||
* geometry char* Window geometry (malloc'ed)
|
||||
* window_id long X-window window ID
|
||||
* nopixmap int Set if you want to forbid allocation of pixmaps
|
||||
* db int Set if you want to double buffer output
|
||||
* (only pixmap is drawn to directly; it is blitted
|
||||
* to output window on EOP or an Expose)
|
||||
***************************************************************************
|
||||
*
|
||||
* These are for support of the TK driver.
|
||||
*
|
||||
* server_name char* Main window name of server
|
||||
* server_host char* Name of host to run server on
|
||||
* server_port char* Port to talk to server on
|
||||
* user char* Your user name on remote host (for remsh command)
|
||||
* plserver char* Name of server
|
||||
* plwindow char* Name of reference server window (malloc'ed)
|
||||
* tcl_cmd char* TCL command(s) to eval on startup
|
||||
* tk_file char* File for plserver use with its -file option
|
||||
* auto_path char* Additional directories to autoload
|
||||
* bufmax int Number of bytes sent before output buffer is flushed
|
||||
* dp int Use Tcl-DP for communication, if set
|
||||
* server_nokill int Don't kill plserver on a ^C if set
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Variables for use by the plot buffer
|
||||
*
|
||||
* plbufFile FILE Plot buffer file pointer
|
||||
* plbufOwner int Typically set; only zero if current stream is cloned.
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Driver interface (DI)
|
||||
*
|
||||
* difilt PLINT Driver interface filter flag
|
||||
*
|
||||
* dipxmin PLFLT
|
||||
* dipymin PLFLT Min, max relative plot coordinates
|
||||
* dipxmax PLFLT
|
||||
* dipymax PLFLT
|
||||
* dipxax PLFLT Plot window transformation:
|
||||
* dipxb PLFLT x' = dipxax * x + dipxb
|
||||
* dipyay PLFLT
|
||||
* dipyb PLFLT y' = dipyay * y + dipyb
|
||||
*
|
||||
* aspdev PLFLT Original device aspect ratio
|
||||
* aspect PLFLT Page aspect ratio
|
||||
* aspori PLFLT Rotation-induced aspect ratio
|
||||
* caspfactor PLFLT Factor applied to preserve character aspect ratio
|
||||
* freeaspect PLINT Allow aspect ratio to adjust to orientation swaps
|
||||
* when overall aspect ratio is changed.
|
||||
* portrait PLINT Portrait mode (orientation and aspect ratio)
|
||||
* mar PLFLT Page margin (minimum)
|
||||
* jx PLFLT Page justification in x
|
||||
* jy PLFLT Page justification in y
|
||||
*
|
||||
* didxax PLFLT Device window transformation:
|
||||
* didxb PLFLT x' = didxax * x + didxb
|
||||
* didyay PLFLT
|
||||
* didyb PLFLT y' = didyay * y + didyb
|
||||
*
|
||||
* diclpxmi PLINT
|
||||
* diclpxma PLINT Device clip limits
|
||||
* diclpymi PLINT
|
||||
* diclpyma PLINT
|
||||
*
|
||||
* diorot PLFLT Rotation angle (in units of pi/2)
|
||||
* dioxax PLFLT Orientation transformation:
|
||||
* dioxay PLFLT x' = dioxax * x + dioxay * y + dioxb
|
||||
* dioxb PLFLT
|
||||
* dioyax PLFLT y' = dioyax * x + dioyay * y + dioyb
|
||||
* dioyay PLFLT
|
||||
* dioyb PLFLT
|
||||
*
|
||||
* dimxmin PLFLT
|
||||
* dimymin PLFLT Target coordinate system parameters.
|
||||
* dimxmax PLFLT
|
||||
* dimymax PLFLT
|
||||
* dimxpmm PLFLT
|
||||
* dimypmm PLFLT
|
||||
* dimxax PLFLT Map meta to physical coordinates:
|
||||
* dimxb PLFLT x' = dimxax * x + dimxb
|
||||
* dimyay PLFLT
|
||||
* dimyb PLFLT y' = dimyay * y + dimyb
|
||||
*
|
||||
* page_status PLINT Flag to indicate current action
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Fill pattern state information.
|
||||
* patt < 0: Hardware fill, if available (not implemented yet)
|
||||
* patt ==0: Hardware fill, if available, solid
|
||||
* patt > 0: Software fill
|
||||
*
|
||||
* patt Fill pattern number
|
||||
* inclin Array of inclinations in tenths of degree for fill lines
|
||||
* delta Array of spacings in micrometers between fill lines
|
||||
* nps Number of distinct line styles for fills
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Variables used in line drawing
|
||||
*
|
||||
* currx Physical x-coordinate of current point
|
||||
* curry Physical y-coordinate of current point
|
||||
* mark Array of mark lengths in micrometers for broken lines
|
||||
* space Array of space lengths in micrometers for broken lines
|
||||
* nms Number of elements for current broken line style
|
||||
* timecnt Timer for broken lines
|
||||
* alarm Alarm indicating change of broken line status
|
||||
* pendn Flag indicating if pen is up or down
|
||||
* curel Current element within broken line
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Variables governing character strings
|
||||
*
|
||||
* esc Text string escape character
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Scale factors for characters, symbols, and tick marks.
|
||||
*
|
||||
* scale Scaling factor for chr, sym, maj, min.
|
||||
* chr... Character default height and current (scaled) height
|
||||
* sym... Symbol default height and current (scaled) height
|
||||
* maj... Major tick default height and current (scaled) height
|
||||
* min... Minor tick default height and current (scaled) height
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Variables governing numeric axis label appearance
|
||||
*
|
||||
* setpre Non-zero to set precision using "prec"
|
||||
* precis User-specified precision
|
||||
* xdigmax.. Allowed #digits in axes labels
|
||||
* xdigits.. Actual field widths (returned)
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Variables governing physical coordinate system
|
||||
*
|
||||
* vpp.. Viewport boundaries in physical coordinates
|
||||
* spp.. Subpage boundaries in physical coordinates
|
||||
* clp.. Clip boundaries in physical coordinates
|
||||
* phy... Physical device limits in physical coordinates
|
||||
* um. Number of micrometers in a pixel
|
||||
* pmm Number of pixels to a millimeter
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* State variables for 3d plots
|
||||
*
|
||||
* base3. World coordinate size of base for 3-d plot
|
||||
* basec. Position of centre of base for 3-d plot
|
||||
* dom... Minimum and maximum values for domain
|
||||
* zzscl Vertical (z) scale for 3-d plot
|
||||
* ran.. Minimum and maximum z values for 3-d plot
|
||||
* c.. Coordinate transformation from 3-d to 2-d
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Variables for keeping track of world coordinate windows on a page.
|
||||
*
|
||||
* nCWindows Number of coordinate windows on current page
|
||||
* windows Array of plCWindow's for current page
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Variables governing subpages and viewports.
|
||||
*
|
||||
* nsub... Number of subpages on physical device
|
||||
* cursub Current subpage
|
||||
* spd... Subpage boundaries in normalized device coordinates
|
||||
* vpd... Viewport boundaries in normalized device coordinates
|
||||
* vpw... Viewport boundaries in world coordinates
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Transformation variables
|
||||
*
|
||||
* wp.... Transformation variables for world to physical conversion
|
||||
* wm.... Transformation variables for world coordinates to mm
|
||||
*
|
||||
****************************************************************************
|
||||
*
|
||||
* Other variables
|
||||
*
|
||||
* dev_compression Compression level for supporting devices
|
||||
*
|
||||
****************************************************************************
|
||||
*
|
||||
* Font related variables
|
||||
*
|
||||
* cfont Current font number, replaces global 'font' in plsym.c
|
||||
* This can be latter extended for font shape, series, family and size
|
||||
*
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
#define PL_MAX_CMAP1CP 256
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* Misc control information */
|
||||
|
||||
PLINT ipls, level, verbose, debug, initialized, dev_initialized;
|
||||
char *program;
|
||||
|
||||
/* Colormaps */
|
||||
|
||||
PLINT icol0, ncol0, icol1, ncol1, ncp1, curcmap;
|
||||
|
||||
PLColor curcolor, tmpcolor;
|
||||
PLColor *cmap0;
|
||||
PLColor *cmap1;
|
||||
|
||||
PLControlPt cmap1cp[PL_MAX_CMAP1CP];
|
||||
|
||||
/* Variables governing pen width */
|
||||
|
||||
PLINT width;
|
||||
PLINT widthset, widthlock;
|
||||
|
||||
/* Driver dispatch table, obsoletes "device" member below. */
|
||||
|
||||
PLDispatchTable *dispatch_table;
|
||||
|
||||
/* Variables used for interacting with or by device driver */
|
||||
|
||||
PLINT plbuf_read, plbuf_write;
|
||||
PLINT device, dev_minor, termin, graphx, nopause;
|
||||
PLINT color, colorset;
|
||||
PLINT family, member, finc, fflen, bytemax, famadv;
|
||||
PLINT dev_fill0, dev_fill1, dev_dash, dev_di, dev_flush, dev_swin;
|
||||
PLINT dev_text, dev_xor, dev_clear, dev_fastimg;
|
||||
|
||||
char DevName[80];
|
||||
FILE *OutFile;
|
||||
char *BaseName, *FileName;
|
||||
int output_type;
|
||||
PLINT bytecnt, page, linepos;
|
||||
PDFstrm *pdfs;
|
||||
|
||||
PLINT dev_npts;
|
||||
short *dev_x, *dev_y;
|
||||
|
||||
/* variables for plimage() */
|
||||
|
||||
PLINT dev_nptsX, dev_nptsY;
|
||||
short *dev_ix, *dev_iy;
|
||||
unsigned short *dev_z;
|
||||
unsigned short dev_zmin, dev_zmax;
|
||||
PLINT imclxmin, imclxmax, imclymin, imclymax;
|
||||
|
||||
/* end of variables for plimage() */
|
||||
|
||||
void *dev;
|
||||
|
||||
void (*KeyEH) (PLGraphicsIn *gin, void *KeyEH_data,
|
||||
int *exit_eventloop);
|
||||
void *KeyEH_data;
|
||||
|
||||
void (*ButtonEH) (PLGraphicsIn *gin, void *ButtonEH_data,
|
||||
int *exit_eventloop);
|
||||
void *ButtonEH_data;
|
||||
|
||||
void (*LocateEH) (PLGraphicsIn *gin, void *LocateEH_data,
|
||||
int *locate_mode);
|
||||
void *LocateEH_data;
|
||||
|
||||
void (*bop_handler) (void *bop_data, int *skip_driver_bop);
|
||||
void *bop_data;
|
||||
|
||||
void (*eop_handler) (void *eop_data, int *skip_driver_eop);
|
||||
void *eop_data;
|
||||
|
||||
PLFLT xdpi, ydpi;
|
||||
PLINT xlength, ylength;
|
||||
PLINT xoffset, yoffset;
|
||||
PLINT pageset, hack;
|
||||
|
||||
/* Per stream tidy function. */
|
||||
|
||||
void (*tidy) (void *);
|
||||
void *tidy_data;
|
||||
|
||||
/* Error info */
|
||||
|
||||
PLINT *errcode;
|
||||
char *errmsg;
|
||||
|
||||
/* Stuff used by Xlib driver */
|
||||
|
||||
char *geometry;
|
||||
long window_id;
|
||||
int nopixmap, db;
|
||||
|
||||
/* Stuff used by TK, DP drivers */
|
||||
|
||||
char *server_name, *server_host, *server_port, *user;
|
||||
char *plserver, *plwindow;
|
||||
char *tcl_cmd, *auto_path;
|
||||
char *tk_file; /* plserver -file option */
|
||||
int bufmax, dp, server_nokill;
|
||||
|
||||
/* Plot buffer settings */
|
||||
|
||||
FILE *plbufFile;
|
||||
int plbufOwner;
|
||||
|
||||
/* Driver interface (DI) */
|
||||
|
||||
PLINT difilt, diclpxmi, diclpxma, diclpymi, diclpyma;
|
||||
PLFLT dipxmin, dipymin, dipxmax, dipymax;
|
||||
PLFLT dipxax, dipxb, dipyay, dipyb;
|
||||
PLFLT aspdev, aspect, aspori, caspfactor, mar, jx, jy;
|
||||
PLFLT didxax, didxb, didyay, didyb;
|
||||
PLFLT diorot;
|
||||
PLFLT dioxax, dioxay, dioxb, dioyax, dioyay, dioyb;
|
||||
PLFLT dimxax, dimxb, dimyay, dimyb;
|
||||
PLFLT dimxmin, dimymin, dimxmax, dimymax, dimxpmm, dimypmm;
|
||||
PLINT page_status, freeaspect, portrait;
|
||||
|
||||
/* Fill pattern info */
|
||||
|
||||
PLINT patt, inclin[2], delta[2], nps;
|
||||
|
||||
/* Variables used in line drawing */
|
||||
|
||||
PLINT currx, curry;
|
||||
PLINT mark[10], space[10], nms;
|
||||
PLINT timecnt, alarm, pendn, curel;
|
||||
|
||||
/* Variables governing character strings */
|
||||
|
||||
char esc;
|
||||
|
||||
/* Scale factors for characters, symbols, and tick marks. */
|
||||
|
||||
PLFLT scale;
|
||||
PLFLT chrdef, chrht;
|
||||
PLFLT symdef, symht;
|
||||
PLFLT majdef, majht;
|
||||
PLFLT mindef, minht;
|
||||
|
||||
/* Variables governing numeric axis label appearance */
|
||||
|
||||
PLINT setpre, precis;
|
||||
PLINT xdigmax, ydigmax, zdigmax;
|
||||
PLINT xdigits, ydigits, zdigits;
|
||||
|
||||
/* Variables governing physical coordinate system */
|
||||
|
||||
PLINT vppxmi, vppxma, vppymi, vppyma;
|
||||
PLINT sppxmi, sppxma, sppymi, sppyma;
|
||||
PLINT clpxmi, clpxma, clpymi, clpyma;
|
||||
PLINT phyxmi, phyxma, phyxlen, phyymi, phyyma, phyylen;
|
||||
PLINT umx, umy;
|
||||
PLFLT xpmm, ypmm;
|
||||
|
||||
/* State variables for 3d plots */
|
||||
|
||||
PLFLT base3x, base3y, basecx, basecy;
|
||||
PLFLT domxmi, domxma, domymi, domyma;
|
||||
PLFLT zzscl, ranmi, ranma;
|
||||
PLFLT cxx, cxy, cyx, cyy, cyz;
|
||||
|
||||
/* Variables for keeping track of windows on a page. */
|
||||
|
||||
int nplwin;
|
||||
PLWindow plwin[PL_MAXWINDOWS];
|
||||
|
||||
/* Variables governing subpages and viewports. */
|
||||
|
||||
PLINT nsubx, nsuby, cursub;
|
||||
PLFLT spdxmi, spdxma, spdymi, spdyma;
|
||||
PLFLT vpdxmi, vpdxma, vpdymi, vpdyma;
|
||||
PLFLT vpwxmi, vpwxma, vpwymi, vpwyma;
|
||||
|
||||
/* Transformation variables */
|
||||
|
||||
PLFLT wpxscl, wpxoff, wpyscl, wpyoff;
|
||||
PLFLT wmxscl, wmxoff, wmyscl, wmyoff;
|
||||
PLFLT wdxscl, wdxoff, wdyscl, wdyoff;
|
||||
|
||||
/* Other variables */
|
||||
|
||||
PLINT dev_compression;
|
||||
PLINT cfont;
|
||||
|
||||
void *FT;
|
||||
|
||||
/* Stuff used by the Tkwin driver for Plframe */
|
||||
struct PlPlotter *plPlotterPtr;
|
||||
|
||||
} PLStream;
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* Prototypes for stream & device utility functions.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Get the current stream pointer */
|
||||
|
||||
void
|
||||
plgpls(PLStream **p_pls);
|
||||
|
||||
/* Initializes device cmap 1 entry by interpolation from pls->cmap1 entries */
|
||||
|
||||
void
|
||||
plcol_interp(PLStream *pls, PLColor *newcolor, int i, int ncol);
|
||||
|
||||
/* Opens file for output, prompting if not set. */
|
||||
|
||||
void
|
||||
plOpenFile(PLStream *pls);
|
||||
|
||||
/* Sets up next file member name (in pls->FileName), but does not open it. */
|
||||
|
||||
void
|
||||
plP_getmember(PLStream *pls);
|
||||
|
||||
/* Sets up file name & family stem name. */
|
||||
|
||||
void
|
||||
plP_sfnam(PLStream *pls, const char *fnam);
|
||||
|
||||
/* Initializes family file parameters. */
|
||||
|
||||
void
|
||||
plFamInit(PLStream *pls);
|
||||
|
||||
/* Starts new member file of family file set if necessary. */
|
||||
|
||||
void
|
||||
plGetFam(PLStream *pls);
|
||||
|
||||
/* Rotates physical coordinates if necessary for given orientation. */
|
||||
|
||||
void
|
||||
plRotPhy(PLINT orient, PLINT xmin, PLINT ymin, PLINT xmax, PLINT ymax,
|
||||
int *px, int *py);
|
||||
|
||||
/* Allocates a standard PLDev structure for device-specific data */
|
||||
|
||||
PLDev *
|
||||
plAllocDev(PLStream *pls);
|
||||
|
||||
/* Just fills in the PLGraphicsIn with appropriate initial values. */
|
||||
|
||||
void
|
||||
plGinInit(PLGraphicsIn *gin);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PLSTRM_H__ */
|
|
@ -1,139 +0,0 @@
|
|||
/* $Id: pltick.c,v 1.2 2005/03/17 21:39:21 eli Exp $
|
||||
|
||||
Routines for drawing error bars and tick marks.
|
||||
*/
|
||||
|
||||
#include "plplotP.h"
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plxtik()
|
||||
*
|
||||
* Draws a tick parallel to x.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plxtik(PLINT x, PLINT y, PLINT below, PLINT above)
|
||||
{
|
||||
plP_draphy(x, y);
|
||||
|
||||
if (below != 0)
|
||||
plP_draphy(x, y - below);
|
||||
|
||||
if (above != 0)
|
||||
plP_draphy(x, y + above);
|
||||
|
||||
plP_draphy(x, y);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plytik()
|
||||
*
|
||||
* Draws a tick parallel to y.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plytik(PLINT x, PLINT y, PLINT left, PLINT right)
|
||||
{
|
||||
plP_draphy(x, y);
|
||||
|
||||
if (left != 0)
|
||||
plP_draphy(x - left, y);
|
||||
|
||||
if (right != 0)
|
||||
plP_draphy(x + right, y);
|
||||
|
||||
plP_draphy(x, y);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plstik()
|
||||
*
|
||||
* Draws a slanting tick at position (mx,my) (measured in mm) of
|
||||
* vector length (dx,dy).
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
plstik(PLFLT mx, PLFLT my, PLFLT dx, PLFLT dy)
|
||||
{
|
||||
plP_draphy(plP_mmpcx(mx), plP_mmpcy(my));
|
||||
plP_draphy(plP_mmpcx((PLFLT) (mx + dx)), plP_mmpcy((PLFLT) (my + dy)));
|
||||
plP_draphy(plP_mmpcx(mx), plP_mmpcy(my));
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plerx1()
|
||||
*
|
||||
* Plot single horizontal error bar.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
plerx1(PLFLT xmin, PLFLT xmax, PLFLT y)
|
||||
{
|
||||
PLINT yminor;
|
||||
|
||||
yminor = MAX(1.0, plsc->minht * plsc->ypmm);
|
||||
plP_movwor(xmin, y);
|
||||
plxtik(plP_wcpcx(xmin), plP_wcpcy(y), yminor, yminor);
|
||||
plP_drawor(xmax, y);
|
||||
plxtik(plP_wcpcx(xmax), plP_wcpcy(y), yminor, yminor);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plery1()
|
||||
*
|
||||
* Plot single vertical error bar.
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
plery1(PLFLT x, PLFLT ymin, PLFLT ymax)
|
||||
{
|
||||
PLINT xminor;
|
||||
|
||||
xminor = MAX(1.0, plsc->minht * plsc->xpmm);
|
||||
plP_movwor(x, ymin);
|
||||
plytik(plP_wcpcx(x), plP_wcpcy(ymin), xminor, xminor);
|
||||
plP_drawor(x, ymax);
|
||||
plytik(plP_wcpcx(x), plP_wcpcy(ymax), xminor, xminor);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plerrx()
|
||||
*
|
||||
* Plot horizontal error bars (xmin(i),y(i)) to (xmax(i),y(i)).
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
MZ_DLLEXPORT
|
||||
void
|
||||
c_plerrx(PLINT n, PLFLT *xmin, PLFLT *xmax, PLFLT *y)
|
||||
{
|
||||
PLINT i;
|
||||
|
||||
if (plsc->level < 3) {
|
||||
plabort("plerrx: Please set up window first");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
plerx1(xmin[i], xmax[i], y[i]);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
* void plerry()
|
||||
*
|
||||
* Plot vertical error bars (x,ymin(i)) to (x(i),ymax(i)).
|
||||
\*----------------------------------------------------------------------*/
|
||||
|
||||
MZ_DLLEXPORT
|
||||
void
|
||||
c_plerry(PLINT n, PLFLT *x, PLFLT *ymin, PLFLT *ymax)
|
||||
{
|
||||
PLINT i;
|
||||
|
||||
if (plsc->level < 3) {
|
||||
plabort("plerry: Please set up window first");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
plery1(x[i], ymin[i], ymax[i]);
|
||||
}
|
|
@ -1,444 +0,0 @@
|
|||
/* $Id: plvpor.c,v 1.2 2005/03/17 21:39:22 eli Exp $
|
||||
|
||||
Functions dealing with viewports.
|
||||
*/
|
||||
|
||||
#include "plplotP.h"
|
||||
|
||||
static void
|
||||
c_plenvi(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax,
|
||||
PLINT just, PLINT axis, PLINT old);
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void plenv()
|
||||
*
|
||||
* Simple interface for defining viewport and window.
|
||||
*
|
||||
* The "just" parameter control how the axes will be scaled:
|
||||
*
|
||||
* just=-1 : The scales will not be set, the user must set up the scale
|
||||
* before calling plenv() using plsvpa(), plvasp() or other;
|
||||
* just= 0 : The scales will be set up to optimize plot area;
|
||||
* just= 1 : The scales will be the same;
|
||||
* just= 2 : The axes will be equal, the plot box will be square.
|
||||
*
|
||||
* The "axis" parameter is interpreted as follows:
|
||||
*
|
||||
* axis=-2 : draw no box, no tick marks, no numeric tick labels, no axes.
|
||||
* axis=-1 : draw box only.
|
||||
* axis= 0 : Draw box, ticks, and numeric tick labels.
|
||||
* axis= 1 : Also draw coordinate axes at X=0, and Y=0.
|
||||
* axis= 2 : Also draw a grid at major tick positions in both coordinates.
|
||||
* axis= 3 : Same as 2, but the grid will be also at the minor ticks.
|
||||
* axis=10 : Same as 0 except Logarithmic X tick marks. (The X data have
|
||||
* to be converted to logarithms separately.)
|
||||
* axis=11 : Same as 1 except Logarithmic X tick marks. (The X data have
|
||||
* to be converted to logarithms separately.)
|
||||
* axis=12 : Same as 2 except Logarithmic X tick marks. (The X data have
|
||||
* to be converted to logarithms separately.)
|
||||
* axis=13 : Same as 12, but the grid will be also at the minor ticks.
|
||||
* axis=20 : Same as 0 except Logarithmic Y tick marks. (The Y data have
|
||||
* to be converted to logarithms separately.)
|
||||
* axis=21 : Same as 1 except Logarithmic Y tick marks. (The Y data have
|
||||
* to be converted to logarithms separately.)
|
||||
* axis=22 : Same as 2 except Logarithmic Y tick marks. (The Y data have
|
||||
* to be converted to logarithms separately.)
|
||||
* axis=23 : Same as 22, but the grid will be also at the minor ticks.
|
||||
* axis=30 : Same as 0 except Logarithmic X,Y tick marks. (The X,Y data have
|
||||
* to be converted to logarithms separately.)
|
||||
* axis=31 : Same as 1 except Logarithmic X,Y tick marks. (The X,Y data have
|
||||
* to be converted to logarithms separately.)
|
||||
* axis=32 : Same as 2 except Logarithmic X,Y tick marks. (The X,Y data have
|
||||
* to be converted to logarithms separately.)
|
||||
* axis=33 : Same as 32, but the grid will be also at the minor ticks.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
MZ_DLLEXPORT
|
||||
void
|
||||
c_plenv(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax,
|
||||
PLINT just, PLINT axis)
|
||||
{
|
||||
c_plenvi(xmin, xmax, ymin, ymax, just, axis, 1);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void plenv0()
|
||||
*
|
||||
* same as plenv() above, but if in multiplot mode does not advance the subpage,
|
||||
* instead clears it.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plenv0(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax,
|
||||
PLINT just, PLINT axis)
|
||||
{
|
||||
c_plenvi(xmin, xmax, ymin, ymax, just, axis, 0);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
c_plenvi(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax,
|
||||
PLINT just, PLINT axis, PLINT old)
|
||||
{
|
||||
PLFLT lb, rb, tb, bb, dx, dy;
|
||||
PLFLT xsize, ysize, size, xscale, yscale, scale;
|
||||
PLFLT spxmin, spxmax, spymin, spymax;
|
||||
PLFLT vpxmin, vpxmax, vpymin, vpymax;
|
||||
|
||||
if (plsc->level < 1) {
|
||||
plabort("plenv: Please call plinit first");
|
||||
return;
|
||||
}
|
||||
if (xmin == xmax) {
|
||||
plabort("plenv: Invalid xmin and xmax arguments");
|
||||
return;
|
||||
}
|
||||
if (ymin == ymax) {
|
||||
plabort("plenv: Invalid ymin and ymax arguments");
|
||||
return;
|
||||
}
|
||||
if (just < -1 || just > 2) {
|
||||
plabort("plenv: Invalid just option");
|
||||
return;
|
||||
}
|
||||
|
||||
if (plsc->nsubx * plsc->nsuby == 1) /* not multiplot mode */
|
||||
old = 1;
|
||||
|
||||
if (old == 1)
|
||||
pladv(0);
|
||||
else
|
||||
plclear();
|
||||
|
||||
if (just == 0)
|
||||
plvsta();
|
||||
else if (just == 1){
|
||||
lb = 8.0 * plsc->chrht;
|
||||
rb = 5.0 * plsc->chrht;
|
||||
tb = 5.0 * plsc->chrht;
|
||||
bb = 5.0 * plsc->chrht;
|
||||
dx = ABS(xmax - xmin);
|
||||
dy = ABS(ymax - ymin);
|
||||
plgspa(&spxmin, &spxmax, &spymin, &spymax);
|
||||
xsize = spxmax - spxmin;
|
||||
ysize = spymax - spymin;
|
||||
xscale = dx / (xsize - lb - rb);
|
||||
yscale = dy / (ysize - tb - bb);
|
||||
scale = MAX(xscale, yscale);
|
||||
vpxmin = MAX(lb, 0.5 * (xsize - dx / scale));
|
||||
vpxmax = vpxmin + (dx / scale);
|
||||
vpymin = MAX(bb, 0.5 * (ysize - dy / scale));
|
||||
vpymax = vpymin + (dy / scale);
|
||||
plsvpa(vpxmin, vpxmax, vpymin, vpymax);
|
||||
} else if(just == 2) {
|
||||
lb = 8.0 * plsc->chrht;
|
||||
rb = 5.0 * plsc->chrht;
|
||||
tb = 5.0 * plsc->chrht;
|
||||
bb = 5.0 * plsc->chrht;
|
||||
plgspa(&spxmin, &spxmax, &spymin, &spymax);
|
||||
xsize = spxmax - spxmin;
|
||||
ysize = spymax - spymin;
|
||||
size = MIN(xsize-lb-rb, ysize-tb-bb);
|
||||
dx = (xsize-size-lb-rb)/2;
|
||||
vpxmin = lb + dx;
|
||||
vpxmax = vpxmin + size;
|
||||
dy = (ysize-size-bb-tb)/2;
|
||||
vpymin = bb + dy;
|
||||
vpymax = vpymin + size;
|
||||
plsvpa(vpxmin, vpxmax, vpymin, vpymax);
|
||||
}
|
||||
|
||||
plwind(xmin, xmax, ymin, ymax);
|
||||
|
||||
switch (axis) {
|
||||
case -2:
|
||||
break;
|
||||
case -1:
|
||||
plbox("bc", (PLFLT) 0.0, 0, "bc", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
case 0:
|
||||
plbox("bcnst", (PLFLT) 0.0, 0, "bcnstv", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
case 1:
|
||||
plbox("abcnst", (PLFLT) 0.0, 0, "abcnstv", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
case 2:
|
||||
plbox("abcgnst", (PLFLT) 0.0, 0, "abcgnstv", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
case 3:
|
||||
plbox("abcgnsth", (PLFLT) 0.0, 0, "abcgnstvh", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
case 10:
|
||||
plbox("bclnst", (PLFLT) 0.0, 0, "bcnstv", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
case 11:
|
||||
plbox("abclnst", (PLFLT) 0.0, 0, "abcnstv", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
case 12:
|
||||
plbox("abcglnst", (PLFLT) 0.0, 0, "abcgnstv", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
case 13:
|
||||
plbox("abcglnsth", (PLFLT) 0.0, 0, "abcgnstvh", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
case 20:
|
||||
plbox("bcnst", (PLFLT) 0.0, 0, "bclnstv", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
case 21:
|
||||
plbox("abcnst", (PLFLT) 0.0, 0, "abclnstv", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
case 22:
|
||||
plbox("abcgnst", (PLFLT) 0.0, 0, "abcglnstv", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
case 23:
|
||||
plbox("abcgnsth", (PLFLT) 0.0, 0, "abcglnstvh", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
case 30:
|
||||
plbox("bclnst", (PLFLT) 0.0, 0, "bclnstv", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
case 31:
|
||||
plbox("abclnst", (PLFLT) 0.0, 0, "abclnstv", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
case 32:
|
||||
plbox("abcglnst", (PLFLT) 0.0, 0, "abcglnstv", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
case 33:
|
||||
plbox("abcglnsth", (PLFLT) 0.0, 0, "abcglnstvh", (PLFLT) 0.0, 0);
|
||||
break;
|
||||
default:
|
||||
plwarn("plenv: Invalid axis argument");
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void plvsta()
|
||||
*
|
||||
* Defines a "standard" viewport with seven character heights for
|
||||
* the left margin and four character heights everywhere else.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plvsta(void)
|
||||
{
|
||||
PLFLT xmin, xmax, ymin, ymax;
|
||||
PLFLT lb, rb, tb, bb;
|
||||
|
||||
if (plsc->level < 1) {
|
||||
plabort("plvsta: Please call plinit first");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Find out position of subpage boundaries in millimetres, reduce by */
|
||||
/* the desired border, and convert back into normalized subpage */
|
||||
/* coordinates */
|
||||
|
||||
lb = 8.0 * plsc->chrht;
|
||||
rb = 5.0 * plsc->chrht;
|
||||
tb = 5.0 * plsc->chrht;
|
||||
bb = 5.0 * plsc->chrht;
|
||||
|
||||
xmin = plP_dcscx(plP_mmdcx((PLFLT) (plP_dcmmx(plsc->spdxmi) + lb)));
|
||||
xmax = plP_dcscx(plP_mmdcx((PLFLT) (plP_dcmmx(plsc->spdxma) - rb)));
|
||||
ymin = plP_dcscy(plP_mmdcy((PLFLT) (plP_dcmmy(plsc->spdymi) + tb)));
|
||||
ymax = plP_dcscy(plP_mmdcy((PLFLT) (plP_dcmmy(plsc->spdyma) - bb)));
|
||||
|
||||
plvpor(xmin, xmax, ymin, ymax);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void plvpor()
|
||||
*
|
||||
* Creates a viewport with the specified normalized subpage coordinates.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plvpor(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax)
|
||||
{
|
||||
if (plsc->level < 1) {
|
||||
plabort("plvpor: Please call plinit first");
|
||||
return;
|
||||
}
|
||||
if ((xmin >= xmax) || (ymin >= ymax)) {
|
||||
plabort("plvpor: Invalid limits");
|
||||
return;
|
||||
}
|
||||
if ((plsc->cursub <= 0) || (plsc->cursub > (plsc->nsubx * plsc->nsuby))) {
|
||||
plabort("plvpor: Please call pladv or plenv to go to a subpage");
|
||||
return;
|
||||
}
|
||||
|
||||
plsc->vpdxmi = plsc->spdxmi + (plsc->spdxma - plsc->spdxmi) * xmin;
|
||||
plsc->vpdxma = plsc->spdxmi + (plsc->spdxma - plsc->spdxmi) * xmax;
|
||||
plsc->vpdymi = plsc->spdymi + (plsc->spdyma - plsc->spdymi) * ymin;
|
||||
plsc->vpdyma = plsc->spdymi + (plsc->spdyma - plsc->spdymi) * ymax;
|
||||
|
||||
plsc->vppxmi = plP_dcpcx(plsc->vpdxmi);
|
||||
plsc->vppxma = plP_dcpcx(plsc->vpdxma);
|
||||
plsc->vppymi = plP_dcpcy(plsc->vpdymi);
|
||||
plsc->vppyma = plP_dcpcy(plsc->vpdyma);
|
||||
|
||||
plsc->clpxmi = MAX(plsc->vppxmi, plsc->phyxmi);
|
||||
plsc->clpxma = MIN(plsc->vppxma, plsc->phyxma);
|
||||
plsc->clpymi = MAX(plsc->vppymi, plsc->phyymi);
|
||||
plsc->clpyma = MIN(plsc->vppyma, plsc->phyyma);
|
||||
|
||||
plsc->level = 2;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void plvpas()
|
||||
*
|
||||
* Creates the largest viewport of the specified aspect ratio that fits
|
||||
* within the specified normalized subpage coordinates.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plvpas(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT aspect)
|
||||
{
|
||||
PLFLT vpxmi, vpxma, vpymi, vpyma;
|
||||
PLFLT vpxmid, vpymid, vpxlen, vpylen, w_aspect, ratio;
|
||||
|
||||
if (plsc->level < 1) {
|
||||
plabort("plvpas: Please call plinit first");
|
||||
return;
|
||||
}
|
||||
if ((xmin >= xmax) || (ymin >= ymax)) {
|
||||
plabort("plvpas: Invalid limits");
|
||||
return;
|
||||
}
|
||||
|
||||
if (aspect <= 0.0) {
|
||||
c_plvpor(xmin, xmax, ymin, ymax);
|
||||
return;
|
||||
}
|
||||
|
||||
vpxmi = plP_dcmmx(xmin);
|
||||
vpxma = plP_dcmmx(xmax);
|
||||
vpymi = plP_dcmmy(ymin);
|
||||
vpyma = plP_dcmmy(ymax);
|
||||
|
||||
vpxmid = (vpxmi + vpxma) / 2.;
|
||||
vpymid = (vpymi + vpyma) / 2.;
|
||||
|
||||
vpxlen = vpxma - vpxmi;
|
||||
vpylen = vpyma - vpymi;
|
||||
|
||||
w_aspect = vpylen / vpxlen;
|
||||
ratio = aspect / w_aspect;
|
||||
|
||||
/*
|
||||
* If ratio < 1, you are requesting an aspect ratio (y/x) less than the natural
|
||||
* aspect ratio of the specified window, and you will need to reduce the length
|
||||
* in y correspondingly. Similarly, for ratio > 1, x length must be reduced.
|
||||
*/
|
||||
|
||||
if (ratio <= 0.) {
|
||||
plabort("plvpas: Error in aspect ratio setting");
|
||||
return;
|
||||
}
|
||||
else if (ratio < 1.)
|
||||
vpylen = vpylen * ratio;
|
||||
else
|
||||
vpxlen = vpxlen / ratio;
|
||||
|
||||
vpxmi = vpxmid - vpxlen / 2.;
|
||||
vpxma = vpxmid + vpxlen / 2.;
|
||||
vpymi = vpymid - vpylen / 2.;
|
||||
vpyma = vpymid + vpylen / 2.;
|
||||
|
||||
plsvpa(vpxmi, vpxma, vpymi, vpyma);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void plvasp()
|
||||
*
|
||||
* Sets the edges of the viewport with the given aspect ratio, leaving
|
||||
* room for labels.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plvasp(PLFLT aspect)
|
||||
{
|
||||
PLFLT spxmin, spxmax, spymin, spymax;
|
||||
PLFLT vpxmin, vpxmax, vpymin, vpymax;
|
||||
PLFLT xsize, ysize, nxsize, nysize;
|
||||
PLFLT lb, rb, tb, bb;
|
||||
|
||||
if (plsc->level < 1) {
|
||||
plabort("plvasp: Please call plinit first");
|
||||
return;
|
||||
}
|
||||
|
||||
lb = 8.0 * plsc->chrht;
|
||||
rb = 5.0 * plsc->chrht;
|
||||
tb = 5.0 * plsc->chrht;
|
||||
bb = 5.0 * plsc->chrht;
|
||||
|
||||
plgspa(&spxmin, &spxmax, &spymin, &spymax);
|
||||
xsize = spxmax - spxmin;
|
||||
ysize = spymax - spymin;
|
||||
xsize -= lb + rb; /* adjust for labels */
|
||||
ysize -= bb + tb;
|
||||
if (aspect * xsize > ysize) {
|
||||
nxsize = ysize / aspect;
|
||||
nysize = ysize;
|
||||
}
|
||||
else {
|
||||
nxsize = xsize;
|
||||
nysize = xsize * aspect;
|
||||
}
|
||||
|
||||
/* center plot within page */
|
||||
|
||||
vpxmin = .5 * (xsize - nxsize) + lb;
|
||||
vpxmax = vpxmin + nxsize;
|
||||
vpymin = .5 * (ysize - nysize) + bb;
|
||||
vpymax = vpymin + nysize;
|
||||
|
||||
plsvpa(vpxmin, vpxmax, vpymin, vpymax);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void plsvpa()
|
||||
*
|
||||
* Sets the edges of the viewport to the specified absolute coordinates
|
||||
* (mm), measured with respect to the current subpage boundaries.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plsvpa(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax)
|
||||
{
|
||||
PLFLT sxmin, symin;
|
||||
|
||||
if (plsc->level < 1) {
|
||||
plabort("plsvpa: Please call plinit first");
|
||||
return;
|
||||
}
|
||||
if ((xmin >= xmax) || (ymin >= ymax)) {
|
||||
plabort("plsvpa: Invalid limits");
|
||||
return;
|
||||
}
|
||||
if ((plsc->cursub <= 0) || (plsc->cursub > (plsc->nsubx * plsc->nsuby))) {
|
||||
plabort("plsvpa: Please call pladv or plenv to go to a subpage");
|
||||
return;
|
||||
}
|
||||
|
||||
sxmin = plP_dcmmx(plsc->spdxmi);
|
||||
symin = plP_dcmmy(plsc->spdymi);
|
||||
|
||||
plsc->vpdxmi = plP_mmdcx((PLFLT) (sxmin + xmin));
|
||||
plsc->vpdxma = plP_mmdcx((PLFLT) (sxmin + xmax));
|
||||
plsc->vpdymi = plP_mmdcy((PLFLT) (symin + ymin));
|
||||
plsc->vpdyma = plP_mmdcy((PLFLT) (symin + ymax));
|
||||
|
||||
plsc->vppxmi = plP_dcpcx(plsc->vpdxmi);
|
||||
plsc->vppxma = plP_dcpcx(plsc->vpdxma);
|
||||
plsc->vppymi = plP_dcpcy(plsc->vpdymi);
|
||||
plsc->vppyma = plP_dcpcy(plsc->vpdyma);
|
||||
|
||||
plsc->clpxmi = plP_dcpcx(plsc->vpdxmi);
|
||||
plsc->clpxma = plP_dcpcx(plsc->vpdxma);
|
||||
plsc->clpymi = plP_dcpcy(plsc->vpdymi);
|
||||
plsc->clpyma = plP_dcpcy(plsc->vpdyma);
|
||||
|
||||
plsc->level = 2;
|
||||
}
|
|
@ -1,178 +0,0 @@
|
|||
/* $Id: plwind.c,v 1.2 2005/03/17 21:39:22 eli Exp $
|
||||
|
||||
Routines for setting up world coordinates of the current viewport.
|
||||
*/
|
||||
|
||||
#include "plplotP.h"
|
||||
|
||||
#define dtr 0.01745329252
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void plwind()
|
||||
*
|
||||
* Set up world coordinates of the viewport boundaries (2d plots).
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
c_plwind(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax)
|
||||
{
|
||||
PLFLT dx, dy, mmxmi, mmxma, mmymi, mmyma;
|
||||
PLWindow w;
|
||||
|
||||
if (plsc->level < 2) {
|
||||
plabort("plwind: Please set up viewport first");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Best to just warn and recover on bounds errors */
|
||||
|
||||
if (xmin == xmax) {
|
||||
plwarn("plwind: Invalid window limits in x.");
|
||||
xmin--; xmax++;
|
||||
}
|
||||
if (ymin == ymax) {
|
||||
plwarn("plwind: Invalid window limits in y.");
|
||||
ymin--; ymax++;
|
||||
}
|
||||
|
||||
dx = (xmax - xmin) * 1.0e-5;
|
||||
dy = (ymax - ymin) * 1.0e-5;
|
||||
|
||||
/* The true plot window is made slightly larger than requested so that */
|
||||
/* the end limits will be on the graph */
|
||||
|
||||
plsc->vpwxmi = xmin - dx;
|
||||
plsc->vpwxma = xmax + dx;
|
||||
plsc->vpwymi = ymin - dy;
|
||||
plsc->vpwyma = ymax + dy;
|
||||
|
||||
/* Compute the scaling between coordinate systems */
|
||||
|
||||
dx = plsc->vpwxma - plsc->vpwxmi;
|
||||
dy = plsc->vpwyma - plsc->vpwymi;
|
||||
|
||||
plsc->wpxscl = (plsc->vppxma - plsc->vppxmi) / dx;
|
||||
plsc->wpxoff = (xmax * plsc->vppxmi - xmin * plsc->vppxma) / dx;
|
||||
plsc->wpyscl = (plsc->vppyma - plsc->vppymi) / dy;
|
||||
plsc->wpyoff = (ymax * plsc->vppymi - ymin * plsc->vppyma) / dy;
|
||||
|
||||
mmxmi = plP_dcmmx(plsc->vpdxmi);
|
||||
mmxma = plP_dcmmx(plsc->vpdxma);
|
||||
mmymi = plP_dcmmy(plsc->vpdymi);
|
||||
mmyma = plP_dcmmy(plsc->vpdyma);
|
||||
|
||||
/* Set transformation variables for world coordinates to mm */
|
||||
|
||||
plsc->wmxscl = (mmxma - mmxmi) / dx;
|
||||
plsc->wmxoff = (xmax * mmxmi - xmin * mmxma) / dx;
|
||||
plsc->wmyscl = (mmyma - mmymi) / dy;
|
||||
plsc->wmyoff = (ymax * mmymi - ymin * mmyma) / dy;
|
||||
|
||||
/* Set transformation variables for world coordinates to device coords */
|
||||
|
||||
plsc->wdxscl = plsc->wmxscl * plsc->xpmm / (plsc->phyxma - plsc->phyxmi);
|
||||
plsc->wdxoff = plsc->wmxoff * plsc->xpmm / (plsc->phyxma - plsc->phyxmi);
|
||||
plsc->wdyscl = plsc->wmyscl * plsc->ypmm / (plsc->phyyma - plsc->phyymi);
|
||||
plsc->wdyoff = plsc->wmyoff * plsc->ypmm / (plsc->phyyma - plsc->phyymi);
|
||||
|
||||
/* Register plot window attributes */
|
||||
|
||||
w.dxmi = plsc->vpdxmi;
|
||||
w.dxma = plsc->vpdxma;
|
||||
w.dymi = plsc->vpdymi;
|
||||
w.dyma = plsc->vpdyma;
|
||||
|
||||
w.wxmi = plsc->vpwxmi;
|
||||
w.wxma = plsc->vpwxma;
|
||||
w.wymi = plsc->vpwymi;
|
||||
w.wyma = plsc->vpwyma;
|
||||
|
||||
plP_swin(&w);
|
||||
|
||||
/* Go to level 3 */
|
||||
|
||||
plsc->level = 3;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*\
|
||||
* void plw3d()
|
||||
*
|
||||
* Set up a window for three-dimensional plotting. The data are mapped
|
||||
* into a box with world coordinate size "basex" by "basey" by "height",
|
||||
* with the base being symmetrically positioned about zero. Thus
|
||||
* the mapping between data 3-d and world 3-d coordinates is given by:
|
||||
*
|
||||
* x = xmin => wx = -0.5*basex
|
||||
* x = xmax => wx = 0.5*basex
|
||||
* y = ymin => wy = -0.5*basey
|
||||
* y = ymax => wy = 0.5*basey
|
||||
* z = zmin => wz = 0.0
|
||||
* z = zmax => wz = height
|
||||
*
|
||||
* The world coordinate box is then viewed from position "alt"-"az",
|
||||
* measured in degrees. For proper operation, 0 <= alt <= 90 degrees,
|
||||
* but az can be any value.
|
||||
\*--------------------------------------------------------------------------*/
|
||||
|
||||
MZ_DLLEXPORT
|
||||
void
|
||||
c_plw3d(PLFLT basex, PLFLT basey, PLFLT height, PLFLT xmin0,
|
||||
PLFLT xmax0, PLFLT ymin0, PLFLT ymax0, PLFLT zmin0,
|
||||
PLFLT zmax0, PLFLT alt, PLFLT az)
|
||||
{
|
||||
PLFLT xmin, xmax, ymin, ymax, zmin, zmax, d;
|
||||
PLFLT cx, cy, saz, caz, salt, calt, zscale;
|
||||
|
||||
if (plsc->level < 3) {
|
||||
plabort("plw3d: Please set up 2-d window first");
|
||||
return;
|
||||
}
|
||||
if (basex <= 0.0 || basey <= 0.0 || height <= 0.0) {
|
||||
plabort("plw3d: Invalid world coordinate boxsize");
|
||||
return;
|
||||
}
|
||||
if (xmin0 == xmax0 || ymin0 == ymax0 || zmin0 == zmax0) {
|
||||
plabort("plw3d: Invalid axis range");
|
||||
return;
|
||||
}
|
||||
if (alt < 0.0 || alt > 90.0) {
|
||||
plabort("plw3d: Altitude must be between 0 and 90 degrees");
|
||||
return;
|
||||
}
|
||||
|
||||
d = 1.0e-5 * (xmax0 - xmin0);
|
||||
xmax = xmax0 + d;
|
||||
xmin = xmin0 - d;
|
||||
d = 1.0e-5 * (ymax0 - ymin0);
|
||||
ymax = ymax0 + d;
|
||||
ymin = ymin0 - d;
|
||||
d = 1.0e-5 * (zmax0 - zmin0);
|
||||
zmax = zmax0 + d;
|
||||
zmin = zmin0 - d;
|
||||
cx = basex / (xmax - xmin);
|
||||
cy = basey / (ymax - ymin);
|
||||
zscale = height / (zmax - zmin);
|
||||
saz = sin(dtr * az);
|
||||
caz = cos(dtr * az);
|
||||
salt = sin(dtr * alt);
|
||||
calt = cos(dtr * alt);
|
||||
|
||||
plsc->domxmi = xmin;
|
||||
plsc->domxma = xmax;
|
||||
plsc->domymi = ymin;
|
||||
plsc->domyma = ymax;
|
||||
plsc->zzscl = zscale;
|
||||
plsc->ranmi = zmin;
|
||||
plsc->ranma = zmax;
|
||||
|
||||
plsc->base3x = basex;
|
||||
plsc->base3y = basey;
|
||||
plsc->basecx = 0.5 * (xmin + xmax);
|
||||
plsc->basecy = 0.5 * (ymin + ymax);
|
||||
|
||||
plsc->cxx = cx * caz;
|
||||
plsc->cxy = -cy * saz;
|
||||
plsc->cyx = cx * saz * salt;
|
||||
plsc->cyy = cy * caz * salt;
|
||||
plsc->cyz = zscale * calt;
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
/* $Id: plxwd.h,v 1.1 2004/03/01 20:54:53 cozmic Exp $
|
||||
|
||||
Holds system header includes, prototypes of xwin driver
|
||||
utility functions, and definition of the state structure.
|
||||
*/
|
||||
|
||||
#ifndef __PLXWD_H__
|
||||
#define __PLXWD_H__
|
||||
|
||||
#include "plplot.h"
|
||||
#include "plstrm.h"
|
||||
#ifdef HAVE_PTHREAD
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
/* System headers */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/cursorfont.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
/* Specify max number of displays in use */
|
||||
|
||||
#define PLXDISPLAYS 100
|
||||
|
||||
/* Set constants for dealing with colormap. In brief:
|
||||
*
|
||||
* ccmap When set, turns on custom color map
|
||||
*
|
||||
* See Init_CustomCmap() and Init_DefaultCmap() for more info.
|
||||
* Set ccmap at your own risk -- still under development.
|
||||
*/
|
||||
|
||||
static int plplot_ccmap = 0;
|
||||
|
||||
|
||||
/* One of these holds the display info, shared by all streams on a given */
|
||||
/* display */
|
||||
|
||||
typedef struct {
|
||||
int nstreams; /* Number of streams using display */
|
||||
int ixwd; /* Specifies xwDisplay number */
|
||||
char *displayName; /* Name of X display */
|
||||
int screen; /* X screen */
|
||||
Display *display; /* X display */
|
||||
Visual *visual; /* X Visual */
|
||||
GC gcXor; /* Graphics context for XOR draws */
|
||||
Colormap map; /* Colormap */
|
||||
unsigned depth; /* display depth */
|
||||
int color; /* Set to 1 if a color output device */
|
||||
int ncol0; /* Number of cmap 0 colors allocated */
|
||||
int ncol1; /* Number of cmap 1 colors allocated */
|
||||
XColor cmap0[16]; /* Color entries for cmap 0 */
|
||||
XColor cmap1[256]; /* Color entries for cmap 1 */
|
||||
XColor fgcolor; /* Foreground color (if grayscale) */
|
||||
Cursor xhair_cursor; /* Crosshair cursor */
|
||||
int rw_cmap; /* Can we allocate r/w color cells? */
|
||||
} XwDisplay;
|
||||
|
||||
/* One of these holds the X driver state information */
|
||||
|
||||
typedef struct {
|
||||
XwDisplay *xwd; /* Pointer to display info */
|
||||
|
||||
int is_main; /* Set if the toplevel X window */
|
||||
Window window; /* X window id */
|
||||
Pixmap pixmap; /* Off-screen pixmap */
|
||||
GC gc; /* Graphics context */
|
||||
XColor curcolor; /* Current pen color */
|
||||
|
||||
long event_mask; /* Event mask */
|
||||
int exit_eventloop; /* Breaks the event loop when set */
|
||||
long init_width; /* Initial window width */
|
||||
long init_height; /* Initial window height */
|
||||
|
||||
unsigned width, height, border; /* Current window dimensions */
|
||||
|
||||
double xscale_init; /* initial pixels/lx (virt. coords) */
|
||||
double yscale_init; /* initial pixels/ly (virt. coords) */
|
||||
double xscale; /* as above, but current value */
|
||||
double yscale; /* (after possible resizing) */
|
||||
|
||||
short xlen, ylen; /* Lengths of device coord space */
|
||||
|
||||
int write_to_window; /* Set if plotting direct to window */
|
||||
int write_to_pixmap; /* Set if plotting to pixmap */
|
||||
|
||||
int instr; /* Instruction timer */
|
||||
int max_instr; /* Limit before X server is queried */
|
||||
|
||||
PLGraphicsIn gin; /* Graphics input structure */
|
||||
|
||||
int locate_mode; /* Set while in locate mode */
|
||||
int drawing_xhairs; /* Set during xhair draws */
|
||||
XPoint xhair_x[2], xhair_y[2]; /* Crosshair lines */
|
||||
|
||||
void (*MasterEH) (PLStream *, XEvent *); /* Master X event handler */
|
||||
#ifdef HAVE_PTHREAD
|
||||
pthread_t updater; /* The X events updater thread id */
|
||||
#endif
|
||||
} XwDev;
|
||||
|
||||
#endif /* __PLXWD_H__ */
|
|
@ -31,7 +31,6 @@ AC_ARG_ENABLE(jit, [ --enable-jit support JIT compiler (enabled
|
|||
AC_ARG_ENABLE(foreign, [ --enable-foreign support foreign calls (enabled by default)], , enable_foreign=yes)
|
||||
AC_ARG_ENABLE(places, [ --enable-places support places (3m only; usually enabled by default)])
|
||||
AC_ARG_ENABLE(futures, [ --enable-futures support futures (usually enabled by default)])
|
||||
AC_ARG_ENABLE(plot, [ --enable-plot support plot libraries (enabled by default)], , enable_plot=yes )
|
||||
AC_ARG_ENABLE(float, [ --enable-float support single-precision floats (enabled by default)], , enable_float=yes)
|
||||
AC_ARG_ENABLE(floatinstead, [ --enable-floatinstead use single-precision by default])
|
||||
|
||||
|
@ -239,7 +238,6 @@ show_explicitly_enabled "${enable_xonx}" "Unix style"
|
|||
show_explicitly_enabled "${enable_shared}" "Shared libraries"
|
||||
|
||||
show_explicitly_disabled "${enable_gracket}" GRacket
|
||||
show_explicitly_disabled "${enable_plot}" Plot
|
||||
|
||||
if test "$LIBTOOLPROG" != "" ; then
|
||||
echo "=== Libtool program: $LIBTOOLPROG"
|
||||
|
@ -1196,7 +1194,6 @@ AC_SUBST(MRLIBINSTALL)
|
|||
AC_SUBST(LIBFINISH)
|
||||
|
||||
AC_SUBST(MAKE_GRACKET)
|
||||
AC_SUBST(MAKE_PLOT)
|
||||
AC_SUBST(MAKE_COPYTREE)
|
||||
AC_SUBST(MAKE_FINISH)
|
||||
|
||||
|
@ -1274,14 +1271,6 @@ fi
|
|||
makefiles="$makefiles foreign/Makefile"
|
||||
ac_configure_args="$ac_configure_args$SUB_CONFIGURE_EXTRAS"
|
||||
|
||||
if test -d "${srcdir}/plot" && test "${enable_plot}" = "yes" ; then
|
||||
makefiles="$makefiles
|
||||
plot/Makefile"
|
||||
MAKE_PLOT=plot
|
||||
else
|
||||
MAKE_PLOT=no
|
||||
fi
|
||||
|
||||
if test "${enable_gracket}" = "yes" ; then
|
||||
makefiles="$makefiles
|
||||
gracket/Makefile
|
||||
|
|