diff --git a/collects/meta/dist-specs.rkt b/collects/meta/dist-specs.rkt index 7f717ca421..286d4dba28 100644 --- a/collects/meta/dist-specs.rkt +++ b/collects/meta/dist-specs.rkt @@ -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) diff --git a/collects/meta/props b/collects/meta/props index 57c1bfbda6..4688dd43ea 100755 --- a/collects/meta/props +++ b/collects/meta/props @@ -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 diff --git a/collects/mzlib/struct.rkt b/collects/mzlib/struct.rkt index eb54208080..9e3e79bfbe 100644 --- a/collects/mzlib/struct.rkt +++ b/collects/mzlib/struct.rkt @@ -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) diff --git a/collects/plot/demos/demo-1.rkt b/collects/plot/demos/demo-1.rkt deleted file mode 100644 index 0319f552af..0000000000 --- a/collects/plot/demos/demo-1.rkt +++ /dev/null @@ -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\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\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\364P\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 diff --git a/collects/plot/demos/demo-10.rkt b/collects/plot/demos/demo-10.rkt deleted file mode 100644 index cfc52e1477..0000000000 --- a/collects/plot/demos/demo-10.rkt +++ /dev/null @@ -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))))) diff --git a/collects/plot/demos/demo-2.rkt b/collects/plot/demos/demo-2.rkt deleted file mode 100644 index 8fb82521d9..0000000000 --- a/collects/plot/demos/demo-2.rkt +++ /dev/null @@ -1,4 +0,0 @@ -#lang scheme -(require plot) - -(plot (line (lambda (x) x) #:color 'red)) diff --git a/collects/plot/demos/demo-3.rkt b/collects/plot/demos/demo-3.rkt deleted file mode 100644 index 130080fe9f..0000000000 --- a/collects/plot/demos/demo-3.rkt +++ /dev/null @@ -1,4 +0,0 @@ -#lang scheme -(require plot) - -(plot (line sin #:color 'red)) diff --git a/collects/plot/demos/demo-4.rkt b/collects/plot/demos/demo-4.rkt deleted file mode 100644 index 942d036319..0000000000 --- a/collects/plot/demos/demo-4.rkt +++ /dev/null @@ -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)") diff --git a/collects/plot/demos/demo-5.rkt b/collects/plot/demos/demo-5.rkt deleted file mode 100644 index 973c03327e..0000000000 --- a/collects/plot/demos/demo-5.rkt +++ /dev/null @@ -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)") diff --git a/collects/plot/demos/demo-6.rkt b/collects/plot/demos/demo-6.rkt deleted file mode 100644 index 9153c84880..0000000000 --- a/collects/plot/demos/demo-6.rkt +++ /dev/null @@ -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)") diff --git a/collects/plot/demos/demo-7.rkt b/collects/plot/demos/demo-7.rkt deleted file mode 100644 index 49d1623022..0000000000 --- a/collects/plot/demos/demo-7.rkt +++ /dev/null @@ -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)") diff --git a/collects/plot/demos/demo-8.rkt b/collects/plot/demos/demo-8.rkt deleted file mode 100644 index d5b01982ed..0000000000 --- a/collects/plot/demos/demo-8.rkt +++ /dev/null @@ -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)) diff --git a/collects/plot/demos/fit-demo-1.rkt b/collects/plot/demos/fit-demo-1.rkt deleted file mode 100644 index 7462fe27f0..0000000000 --- a/collects/plot/demos/fit-demo-1.rkt +++ /dev/null @@ -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) diff --git a/collects/plot/demos/fit-demo-2.rkt b/collects/plot/demos/fit-demo-2.rkt deleted file mode 100644 index f09802ce1c..0000000000 --- a/collects/plot/demos/fit-demo-2.rkt +++ /dev/null @@ -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) diff --git a/collects/plot/extend.rkt b/collects/plot/extend.rkt deleted file mode 100644 index ab0c053c65..0000000000 --- a/collects/plot/extend.rkt +++ /dev/null @@ -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) diff --git a/collects/plot/fit-low-level.rkt b/collects/plot/fit-low-level.rkt deleted file mode 100644 index 82415aeb12..0000000000 --- a/collects/plot/fit-low-level.rkt +++ /dev/null @@ -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)) diff --git a/collects/plot/fit.rkt b/collects/plot/fit.rkt deleted file mode 100644 index 437c8eab22..0000000000 --- a/collects/plot/fit.rkt +++ /dev/null @@ -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)))) diff --git a/collects/plot/fonts/plstnd5.fnt b/collects/plot/fonts/plstnd5.fnt deleted file mode 100644 index 51923d998d..0000000000 Binary files a/collects/plot/fonts/plstnd5.fnt and /dev/null differ diff --git a/collects/plot/fonts/plxtnd5.fnt b/collects/plot/fonts/plxtnd5.fnt deleted file mode 100644 index 88ec784ba9..0000000000 Binary files a/collects/plot/fonts/plxtnd5.fnt and /dev/null differ diff --git a/collects/plot/info.rkt b/collects/plot/info.rkt deleted file mode 100644 index d85005bb8f..0000000000 --- a/collects/plot/info.rkt +++ /dev/null @@ -1,5 +0,0 @@ -#lang setup/infotab - -(define scribblings '(("plot.scrbl" (multi-page) (gui-library)))) - -(define compile-omit-paths '("demos")) diff --git a/collects/plot/main.rkt b/collects/plot/main.rkt deleted file mode 100644 index 7f14bef620..0000000000 --- a/collects/plot/main.rkt +++ /dev/null @@ -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])) - diff --git a/collects/plot/math.rkt b/collects/plot/math.rkt deleted file mode 100644 index a8ef955d88..0000000000 --- a/collects/plot/math.rkt +++ /dev/null @@ -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))) diff --git a/collects/plot/plot-extend.rkt b/collects/plot/plot-extend.rkt deleted file mode 100644 index 08bb3ef957..0000000000 --- a/collects/plot/plot-extend.rkt +++ /dev/null @@ -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))) - diff --git a/collects/plot/plot.rkt b/collects/plot/plot.rkt deleted file mode 100644 index 81410a9d74..0000000000 --- a/collects/plot/plot.rkt +++ /dev/null @@ -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 - - ) diff --git a/collects/plot/plot.scrbl b/collects/plot/plot.scrbl deleted file mode 100644 index d5e4950384..0000000000 --- a/collects/plot/plot.scrbl +++ /dev/null @@ -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.} - -} diff --git a/collects/plot/plplot.rkt b/collects/plot/plplot.rkt deleted file mode 100644 index fd065f6d20..0000000000 --- a/collects/plot/plplot.rkt +++ /dev/null @@ -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)) diff --git a/collects/plot/renderer-helpers.rkt b/collects/plot/renderer-helpers.rkt deleted file mode 100644 index 50d8ab6d19..0000000000 --- a/collects/plot/renderer-helpers.rkt +++ /dev/null @@ -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) - - ) diff --git a/collects/plot/renderers.rkt b/collects/plot/renderers.rkt deleted file mode 100644 index ea6ef9d62a..0000000000 --- a/collects/plot/renderers.rkt +++ /dev/null @@ -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))) - - diff --git a/collects/plot/view.rkt b/collects/plot/view.rkt deleted file mode 100644 index 8d31beea9e..0000000000 --- a/collects/plot/view.rkt +++ /dev/null @@ -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%)) diff --git a/collects/tests/plot/3d-mesh.png b/collects/tests/plot/3d-mesh.png deleted file mode 100644 index 8ae38eff29..0000000000 Binary files a/collects/tests/plot/3d-mesh.png and /dev/null differ diff --git a/collects/tests/plot/contours.png b/collects/tests/plot/contours.png deleted file mode 100644 index 00ab85f239..0000000000 Binary files a/collects/tests/plot/contours.png and /dev/null differ diff --git a/collects/tests/plot/dashed-line.png b/collects/tests/plot/dashed-line.png deleted file mode 100644 index 83d4149a9e..0000000000 Binary files a/collects/tests/plot/dashed-line.png and /dev/null differ diff --git a/collects/tests/plot/mix.png b/collects/tests/plot/mix.png deleted file mode 100644 index def30152c5..0000000000 Binary files a/collects/tests/plot/mix.png and /dev/null differ diff --git a/collects/tests/plot/red-identity.png b/collects/tests/plot/red-identity.png deleted file mode 100644 index f2e29615c5..0000000000 Binary files a/collects/tests/plot/red-identity.png and /dev/null differ diff --git a/collects/tests/plot/run-tests.rkt b/collects/tests/plot/run-tests.rkt deleted file mode 100755 index 680d9433b2..0000000000 --- a/collects/tests/plot/run-tests.rkt +++ /dev/null @@ -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") diff --git a/collects/tests/plot/shade.png b/collects/tests/plot/shade.png deleted file mode 100644 index 1079df9222..0000000000 Binary files a/collects/tests/plot/shade.png and /dev/null differ diff --git a/collects/tests/plot/size.png b/collects/tests/plot/size.png deleted file mode 100644 index b3fa5023bb..0000000000 Binary files a/collects/tests/plot/size.png and /dev/null differ diff --git a/collects/tests/plot/vector-field.png b/collects/tests/plot/vector-field.png deleted file mode 100644 index 024de606e9..0000000000 Binary files a/collects/tests/plot/vector-field.png and /dev/null differ diff --git a/src/Makefile.in b/src/Makefile.in index adab5b19fe..526b1f8588 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -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) diff --git a/src/configure b/src/configure index 85000e0cf7..18e9b96de4 100755 --- a/src/configure +++ b/src/configure @@ -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= use 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 diff --git a/src/get-libs.rkt b/src/get-libs.rkt index 3d772166d8..491326c388 100644 --- a/src/get-libs.rkt +++ b/src/get-libs.rkt @@ -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)]] diff --git a/src/plot/Makefile.in b/src/plot/Makefile.in deleted file mode 100644 index a0ee45deb6..0000000000 --- a/src/plot/Makefile.in +++ /dev/null @@ -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_, which -# typically redirects to RUN_THIS_RACKET_: -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@" diff --git a/src/plot/build.bat b/src/plot/build.bat deleted file mode 100644 index a60b3ffa73..0000000000 --- a/src/plot/build.bat +++ /dev/null @@ -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 diff --git a/src/plot/build.rkt b/src/plot/build.rkt deleted file mode 100644 index 8bd0b99bb4..0000000000 --- a/src/plot/build.rkt +++ /dev/null @@ -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)))))) diff --git a/src/plot/dllexport.h b/src/plot/dllexport.h deleted file mode 100644 index b0f4023d2b..0000000000 --- a/src/plot/dllexport.h +++ /dev/null @@ -1,6 +0,0 @@ - -#if (defined(__WIN32__) || defined(WIN32) || defined(_WIN32)) -# define MZ_DLLEXPORT __declspec(dllexport) -#else -# define MZ_DLLEXPORT -#endif diff --git a/src/plot/fit/fit.c b/src/plot/fit/fit.c deleted file mode 100644 index b6f819190d..0000000000 --- a/src/plot/fit/fit.c +++ /dev/null @@ -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 - - - -#include "matrix.h" -#include "fit.h" -#include -#include -#include - -/* #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; - } -} diff --git a/src/plot/fit/fit.h b/src/plot/fit/fit.h deleted file mode 100644 index 83fa7a9f33..0000000000 --- a/src/plot/fit/fit.h +++ /dev/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(); diff --git a/src/plot/fit/matrix.c b/src/plot/fit/matrix.c deleted file mode 100644 index 76015775db..0000000000 --- a/src/plot/fit/matrix.c +++ /dev/null @@ -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 -#include - -// 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; i0 ? 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= 0; i--) { /* solve R*x+d = 0, by backsubstitution */ - double s = d[i]; - r[i] = 0; /* ... and also set r[i] = 0 for i= 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= k; i--) { /* don't compute upper triangle of A */ - double s = I[i][k]; - for (j = i+1; j. -*/ - -#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); -} diff --git a/src/plot/plplot/disptab.h b/src/plot/plplot/disptab.h deleted file mode 100644 index 6e98329ad0..0000000000 --- a/src/plot/plplot/disptab.h +++ /dev/null @@ -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__ */ diff --git a/src/plot/plplot/drivers.h b/src/plot/plplot/drivers.h deleted file mode 100644 index 30fc09190b..0000000000 --- a/src/plot/plplot/drivers.h +++ /dev/null @@ -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__ */ diff --git a/src/plot/plplot/metadefs.h b/src/plot/plplot/metadefs.h deleted file mode 100644 index 0045c40c94..0000000000 --- a/src/plot/plplot/metadefs.h +++ /dev/null @@ -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 diff --git a/src/plot/plplot/nan.h b/src/plot/plplot/nan.h deleted file mode 100644 index 8699d60f9c..0000000000 --- a/src/plot/plplot/nan.h +++ /dev/null @@ -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 diff --git a/src/plot/plplot/pdf.h b/src/plot/plplot/pdf.h deleted file mode 100644 index 646348d175..0000000000 --- a/src/plot/plplot/pdf.h +++ /dev/null @@ -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 -#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__ */ diff --git a/src/plot/plplot/pdfutils.c b/src/plot/plplot/pdfutils.c deleted file mode 100644 index b9a91a73e1..0000000000 --- a/src/plot/plplot/pdfutils.c +++ /dev/null @@ -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 | 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; -} diff --git a/src/plot/plplot/plConfig.h b/src/plot/plplot/plConfig.h deleted file mode 100644 index fc2fcbaeee..0000000000 --- a/src/plot/plplot/plConfig.h +++ /dev/null @@ -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 diff --git a/src/plot/plplot/plDevs.h b/src/plot/plplot/plDevs.h deleted file mode 100644 index 8abfacd988..0000000000 --- a/src/plot/plplot/plDevs.h +++ /dev/null @@ -1,2 +0,0 @@ -#define PLD_null - diff --git a/src/plot/plplot/plargs.c b/src/plot/plplot/plargs.c deleted file mode 100644 index 1594549feb..0000000000 --- a/src/plot/plplot/plargs.c +++ /dev/null @@ -1,2213 +0,0 @@ -/* $Id: plargs.c,v 1.1 2004/03/01 20:54:50 cozmic Exp $ - - Copyright 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. - - Some parts of this code were derived from "xterm.c" and "ParseCmd.c" of - the X-windows Version 11 distribution. The copyright notice is - reproduced here: - -Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts, -and the Massachusetts Institute of Technology, Cambridge, Massachusetts. - - All Rights Reserved - - The full permission notice is given in the PLplot documentation. - -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - - This file contains routines to extract & process command flags. The - command flags recognized by PLplot are stored in the "ploption_table" - structure, along with strings giving the syntax, long help message, and - option handler. - - The command line parser -- plParseOpts() -- removes all recognized flags - (decreasing argc accordingly), so that invalid input may be readily - detected. It can also be used to process user command line flags. The - user can merge an option table of type PLOptionTable into the internal - option table info structure using plMergeOpts(). Or, the user can - specify that ONLY the external table(s) be parsed by calling - plClearOpts() before plMergeOpts(). - - The default action taken by plParseOpts() is as follows: - - Returns with an error if an unrecognized option or badly formed - option-value pair are encountered. - - Returns immediately (return code 0) when the first non-option - command line argument is found. - - Returns with the return code of the option handler, if one - was called. - - Deletes command line arguments from argv list as they are found, - and decrements argc accordingly. - - Does not show "invisible" options in usage or help messages. - - Assumes the program name is contained in argv[0]. - - These behaviors may be controlled through the "mode" argument, which can - have the following bits set: - - PL_PARSE_FULL -- Full parsing of command line and all error messages - enabled, including program exit when an error occurs. Anything on the - command line that isn't recognized as a valid option or option argument - is flagged as an error. - - PL_PARSE_QUIET -- Turns off all output except in the case of - errors. - - PL_PARSE_NODELETE -- Turns off deletion of processed arguments. - - PL_PARSE_SHOWALL -- Show invisible options - - PL_PARSE_NOPROGRAM -- Specified if argv[0] is NOT a pointer to the - program name. - - PL_PARSE_NODASH -- Set if leading dash is NOT required. - - PL_PARSE_SKIP -- Set to quietly skip over any unrecognized args. - - Note: if you want to have both your option and a PLplot option of the - same name processed (e.g. the -v option in plrender), do the following: - 1. Tag your option with PL_OPT_NODELETE - 2. Give it an option handler that uses a return code of 1. - 3. Merge your option table in. - By merging your table, your option will be processed before the PLplot - one. The PL_OPT_NODELETE ensures that the option string is not deleted - from the argv list, and the return code of 1 ensures that the parser - continues looking for it. - - See plrender.c for examples of actual usage. */ - -#include "plplotP.h" -#include - -/* Support functions */ - -static int ParseOpt (int *, char ***, int *, char ***, PLOptionTable *); -static int ProcessOpt (char *, PLOptionTable *, int *, char ***, int *); -static int GetOptarg (char **, int *, char ***, int *); -static void Help (void); -static void Syntax (void); - -/* Option handlers */ - -static int opt_h (char *, char *, void *); -static int opt_v (char *, char *, void *); -static int opt_verbose (char *, char *, void *); -static int opt_debug (char *, char *, void *); -static int opt_hack (char *, char *, void *); -static int opt_dev (char *, char *, void *); -static int opt_o (char *, char *, void *); -static int opt_geo (char *, char *, void *); -static int opt_a (char *, char *, void *); -static int opt_jx (char *, char *, void *); -static int opt_jy (char *, char *, void *); -static int opt_mar (char *, char *, void *); -static int opt_ori (char *, char *, void *); -static int opt_freeaspect (char *, char *, void *); -static int opt_portrait (char *, char *, void *); -static int opt_width (char *, char *, void *); -static int opt_bg (char *, char *, void *); -static int opt_ncol0 (char *, char *, void *); -static int opt_ncol1 (char *, char *, void *); -static int opt_fam (char *, char *, void *); -static int opt_fsiz (char *, char *, void *); -static int opt_fbeg (char *, char *, void *); -static int opt_finc (char *, char *, void *); -static int opt_fflen (char *, char *, void *); -static int opt_bufmax (char *, char *, void *); -static int opt_nopixmap (char *, char *, void *); -static int opt_db (char *, char *, void *); -static int opt_np (char *, char *, void *); -static int opt_px (char *, char *, void *); -static int opt_py (char *, char *, void *); -static int opt_wplt (char *, char *, void *); -static int opt_drvopt (char *, char *, void *); - -static int opt_plserver (char *, char *, void *); -static int opt_plwindow (char *, char *, void *); -static int opt_tcl_cmd (char *, char *, void *); -static int opt_auto_path (char *, char *, void *); -static int opt_bufmax (char *, char *, void *); -static int opt_server_name (char *, char *, void *); -static int opt_server_host (char *, char *, void *); -static int opt_server_port (char *, char *, void *); -static int opt_user (char *, char *, void *); -static int opt_tk_file (char *, char *, void *); -static int opt_dpi (char *, char *, void *); -static int opt_dev_compression (char *, char *, void *); - -/* Global variables */ - -static char *program = NULL; -static char *usage = NULL; - -static int mode_full; -static int mode_quiet; -static int mode_nodelete; -static int mode_showall; -static int mode_noprogram; -static int mode_nodash; -static int mode_skip; - -/* Temporary buffer used for parsing */ - -#define OPTMAX 1024 -static char opttmp[OPTMAX]; - -/*--------------------------------------------------------------------------*\ - * PLPLOT options data structure definition. - * - * The table is defined as follows - * - * typedef struct { - * char *opt; - * int (*handler) (char *, char *, void *); - * void *client_data; - * void *var; - * long mode; - * char *syntax; - * char *desc; - * } PLOptionTable; - * - * where each entry has the following meaning: - * - * opt option string - * handler pointer to function for processing the option and - * (optionally) its argument - * client_data pointer to data that gets passed to (*handler) - * var address of variable to set based on "mode" - * mode governs handling of option (see below) - * syntax short syntax description - * desc long syntax description - * - * The syntax and or desc strings can be NULL if the option is never to be - * described. Usually this is only used for obsolete arguments; those we - * just wish to hide from normal use are better made invisible (which are - * made visible by either specifying -showall first or PL_PARSE_SHOWALL). - * - * The mode bits are: - * - * PL_OPT_ARG Option has an argment - * PL_OPT_NODELETE Don't delete after processing - * PL_OPT_INVISIBLE Make invisible (usually for debugging) - * PL_OPT_DISABLED Ignore this option - * - * The following mode bits cause the option to be processed as specified: - * - * PL_OPT_FUNC Call function handler (opt, optarg) - * PL_OPT_BOOL Set *var=1 - * PL_OPT_INT Set *var=atoi(optarg) - * PL_OPT_FLOAT Set *var=atof(optarg) - * PL_OPT_STRING Set *var=optarg - * - * where opt points to the option string and optarg points to the - * argument string. - * -\*--------------------------------------------------------------------------*/ - -static PLOptionTable ploption_table[] = { -{ - "showall", /* Turns on invisible options */ - NULL, - NULL, - &mode_showall, - PL_OPT_BOOL | PL_OPT_INVISIBLE, - "-showall", - "Turns on invisible options" }, -{ - "h", /* Help */ - opt_h, - NULL, - NULL, - PL_OPT_FUNC, - "-h", - "Print out this message" }, -{ - "v", /* Version */ - opt_v, - NULL, - NULL, - PL_OPT_FUNC, - "-v", - "Print out the PLplot library version number" }, -{ - "verbose", /* Be more verbose than usual */ - opt_verbose, - NULL, - NULL, - PL_OPT_FUNC, - "-verbose", - "Be more verbose than usual" }, -{ - "debug", /* Print debugging info */ - opt_debug, - NULL, - NULL, - PL_OPT_FUNC, - "-debug", - "Print debugging info (implies -verbose)" }, -{ - "hack", /* Enable driver-specific hack(s) */ - opt_hack, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_INVISIBLE, - "-hack", - "Enable driver-specific hack(s)" }, -{ - "dev", /* Output device */ - opt_dev, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-dev name", - "Output device name" }, -{ - "o", /* Output filename */ - opt_o, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-o name", - "Output filename" }, -{ - "display", /* X server */ - opt_o, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-display name", - "X server to contact" }, -{ - "px", /* Plots per page in x */ - opt_px, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-px number", - "Plots per page in x" }, -{ - "py", /* Plots per page in y */ - opt_py, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-py number", - "Plots per page in y" }, -{ - "geometry", /* Geometry */ - opt_geo, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-geometry geom", - "Window size, in pixels (e.g. -geometry 400x300)" }, -{ - "geo", /* Geometry (alias) */ - opt_geo, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG | PL_OPT_INVISIBLE, - "-geo geom", - "Window size, in pixels (e.g. -geo 400x300)" }, -{ - "wplt", /* Plot window */ - opt_wplt, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-wplt xl,yl,xr,yr", - "Relative coordinates [0-1] of window into plot" }, -{ - "mar", /* Margin */ - opt_mar, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-mar margin", - "Margin space in relative coordinates (0 to 0.5, def 0)" }, -{ - "a", /* Aspect ratio */ - opt_a, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-a aspect", - "Page aspect ratio (def: same as output device)"}, -{ - "jx", /* Justification in x */ - opt_jx, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-jx justx", - "Page justification in x (-0.5 to 0.5, def 0)"}, -{ - "jy", /* Justification in y */ - opt_jy, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-jy justy", - "Page justification in y (-0.5 to 0.5, def 0)"}, -{ - "ori", /* Orientation */ - opt_ori, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-ori orient", - "Plot orientation (0,1,2,3=landscape,portrait,seascape,upside-down)" }, -{ - "freeaspect", /* floating aspect ratio */ - opt_freeaspect, - NULL, - NULL, - PL_OPT_FUNC, - "-freeaspect", - "Allow aspect ratio to adjust to orientation swaps" }, -{ - "portrait", /* floating aspect ratio */ - opt_portrait, - NULL, - NULL, - PL_OPT_FUNC, - "-portrait", - "Sets portrait mode (both orientation and aspect ratio)" }, -{ - "width", /* Pen width */ - opt_width, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-width width", - "Sets pen width (0 <= width)" }, -{ - "bg", /* Background color */ - opt_bg, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-bg color", - "Background color (0=black, FFFFFF=white)" }, -{ - "ncol0", /* Allocated colors in cmap 0 */ - opt_ncol0, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-ncol0 n", - "Number of colors to allocate in cmap 0 (upper bound)" }, -{ - "ncol1", /* Allocated colors in cmap 1 */ - opt_ncol1, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-ncol1 n", - "Number of colors to allocate in cmap 1 (upper bound)" }, -{ - "fam", /* Familying on switch */ - opt_fam, - NULL, - NULL, - PL_OPT_FUNC, - "-fam", - "Create a family of output files" }, -{ - "fsiz", /* Family file size */ - opt_fsiz, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-fsiz size[kKmMgG]", - "Output family file size (e.g. -fsiz 0.5G, def MB)" }, -{ - "fbeg", /* Family starting member */ - opt_fbeg, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-fbeg number", - "First family member number on output" }, -{ - "finc", /* Family member increment */ - opt_finc, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-finc number", - "Increment between family members" }, -{ - "fflen", /* Family member min field width */ - opt_fflen, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-fflen length", - "Family member number minimum field width" }, -{ - "nopixmap", /* Do not use pixmaps */ - opt_nopixmap, - NULL, - NULL, - PL_OPT_FUNC, - "-nopixmap", - "Don't use pixmaps in X-based drivers" }, -{ - "db", /* Double buffering on switch */ - opt_db, - NULL, - NULL, - PL_OPT_FUNC, - "-db", - "Double buffer X window output" }, -{ - "np", /* Page pause off switch */ - opt_np, - NULL, - NULL, - PL_OPT_FUNC, - "-np", - "No pause between pages" }, -{ - "bufmax", /* # bytes sent before flushing output */ - opt_bufmax, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG | PL_OPT_INVISIBLE, - "-bufmax", - "bytes sent before flushing output" }, -{ - "server_name", /* Main window name of server */ - opt_server_name, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-server_name name", - "Main window name of PLplot server (tk driver)" }, -{ - "server_host", /* Host to run server on */ - opt_server_host, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-server_host name", - "Host to run PLplot server on (dp driver)" }, -{ - "server_port", /* Port to talk to server on */ - opt_server_port, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-server_port name", - "Port to talk to PLplot server on (dp driver)" }, -{ - "user", /* user name on remote node */ - opt_user, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-user name", - "User name on remote node (dp driver)" }, -{ - "plserver", /* PLplot server name */ - opt_plserver, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG | PL_OPT_INVISIBLE, - "-plserver name", - "Invoked name of PLplot server (tk or dp driver)" }, -{ - "plwindow", /* PLplot container window name */ - opt_plwindow, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG | PL_OPT_INVISIBLE, - "-plwindow name", - "Name of PLplot container window (tk or dp driver)" }, -{ - "tcl_cmd", /* TCL initialization command */ - opt_tcl_cmd, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG | PL_OPT_INVISIBLE, - "-tcl_cmd command", - "TCL command string run at startup (note: disabled)" }, -{ - "auto_path", /* Additional directory(s) to autoload */ - opt_auto_path, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG | PL_OPT_INVISIBLE, - "-auto_path dir", - "Additional directory(s) to autoload (tk or dp driver)" }, -{ - "tk_file", /* -file option for plserver */ - opt_tk_file, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG | PL_OPT_INVISIBLE, - "-tk_file file", - "file for plserver (tk or dp driver)" }, -{ - "dpi", /* Dots per inch */ - opt_dpi, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-dpi dpi", - "Resolution, in dots per inch (e.g. -dpi 360x360)" }, -{ - "compression", /* compression */ - opt_dev_compression, - NULL, - NULL, - PL_OPT_FUNC | PL_OPT_ARG, - "-compression num", - "Sets compression level in supporting devices" }, -{ - "drvopt", /* Driver specific options */ - opt_drvopt, - NULL, - NULL, - PL_OPT_ARG | PL_OPT_FUNC, - "-drvopt option[=value][,option[=value]]*", - "Driver specific options" }, -{ - NULL, /* option */ - NULL, /* handler */ - NULL, /* client data */ - NULL, /* address of variable to set */ - 0, /* mode flag */ - NULL, /* short syntax */ - NULL } /* long syntax */ -}; - -static char *plplot_notes[] = { -"All parameters must be white-space delimited. Some options are driver", -"dependent. Please see the PLplot reference document for more detail.", -NULL}; - -/*--------------------------------------------------------------------------*\ - * Array of option tables and associated info. - * - * The user may merge up to PL_MAX_OPT_TABLES custom option tables (of type - * PLOptionTable) with the internal one. The resulting treatment is simple, - * powerful, and robust. The tables are parsed in the order of last added - * first, to the internal table last. If multiple options of the same name - * occur, only the first parsed is "seen", thus, the user can easily - * override any PLplot internal option merely by providing the same option. - * This same precedence is followed when printing help and usage messages, - * with each set of options given separately. See example usage in - * plrender.c. -\*--------------------------------------------------------------------------*/ - -typedef struct { - PLOptionTable *options; - char *name; - char **notes; -} PLOptionInfo; - -PLOptionInfo ploption_info_default = { - ploption_table, - "PLplot options", - plplot_notes -}; - -#define PL_MAX_OPT_TABLES 10 -PLOptionInfo ploption_info[PL_MAX_OPT_TABLES] = { - { - ploption_table, - "PLplot options", - plplot_notes - } -}; - -/* The structure that hold the driver specific command line options */ - -typedef struct DrvOptCmd { - char *option; - char *value; - struct DrvOptCmd *next; -} DrvOptCmd; - -/* the variable where opt_drvopt() stores the driver specific command line options */ -static DrvOptCmd drv_opt; - -static int tables = 1; - -/*--------------------------------------------------------------------------*\ - * plSetOpt() - * - * Process input strings, treating them as an option and argument pair. - * Returns 1 on an error. -\*--------------------------------------------------------------------------*/ - -int -c_plsetopt(char *opt, char *optarg) -{ - return(plSetOpt(opt, optarg)); -} - -int -plSetOpt(char *opt, char *optarg) -{ - int mode = 0, argc = 2, status; - char *argv[3]; - - argv[0] = opt; - argv[1] = optarg; - argv[2] = NULL; - mode = - PL_PARSE_QUIET | - PL_PARSE_NODELETE | - PL_PARSE_NOPROGRAM | - PL_PARSE_NODASH; - - status = plParseOpts(&argc, argv, mode); - if (status) { - fprintf( stderr, "plSetOpt: Unrecognized option %s\n", opt); - } - return status; -} - -/*--------------------------------------------------------------------------*\ - * plMergeOpts() - * - * Merge user option table info structure with internal one. -\*--------------------------------------------------------------------------*/ - -int -plMergeOpts(PLOptionTable *options, char *name, char **notes) -{ - PLOptionTable *tab; - - pllib_init(); - -/* Check to make sure option table has been terminated correctly */ - - for (tab = options; tab->opt; tab++) - ; - -/* We've reached the last table entry. All the subentries must be NULL or 0 */ - - if ((tab->handler != NULL) || - (tab->client_data != NULL) || - (tab->var != NULL) || - (tab->mode != 0) || - (tab->syntax != NULL) || - (tab->desc != NULL)) { - - plabort("plMergeOpts: input table improperly terminated"); - return 1; - } - -/* No room for more tables */ - - if (tables++ >= PL_MAX_OPT_TABLES) { - plabort("plMergeOpts: max tables limit exceeded, table not merged"); - return 1; - } - - ploption_info[tables-1].options = options; - ploption_info[tables-1].name = name; - ploption_info[tables-1].notes = notes; - - return 0; -} - -/*--------------------------------------------------------------------------*\ - * plClearOpts() - * - * Clear internal option table info structure. -\*--------------------------------------------------------------------------*/ - -void -plClearOpts(void) -{ - tables = 0; -} - -/*--------------------------------------------------------------------------*\ - * plResetOpts() - * - * Reset internal option table info structure. -\*--------------------------------------------------------------------------*/ - -void -plResetOpts(void) -{ - ploption_info[0] = ploption_info_default; - tables = 1; -} - -/*--------------------------------------------------------------------------*\ - * plParseOpts() - * - * Process options list using current ploptions_info structure. - * An error in parsing the argument list causes a program exit if - * mode_full is set, otherwise the function returns with an error. -\*--------------------------------------------------------------------------*/ - -int -plParseOpts(int *p_argc, char **argv, PLINT mode) -{ - char **argsave, **argend; - int i, myargc, status = 0; - - pllib_init(); - -/* Initialize */ - - mode_full = mode & PL_PARSE_FULL; - mode_quiet = mode & PL_PARSE_QUIET; - mode_nodelete = mode & PL_PARSE_NODELETE; - mode_showall = mode & PL_PARSE_SHOWALL; - mode_noprogram = mode & PL_PARSE_NOPROGRAM; - mode_nodash = mode & PL_PARSE_NODASH; - mode_skip = mode & PL_PARSE_SKIP; - - /* Initialize the driver specific option linked structure */ - drv_opt.option = drv_opt.value = NULL; - drv_opt.next = NULL; - - myargc = (*p_argc); - argend = argv + myargc; - -/* If program name is first argument, save and advance */ - - if ( ! mode_noprogram) { - plsc->program = program = argv[0]; - --myargc; ++argv; - } - if (myargc == 0) - return 0; - -/* Process the command line */ - - argsave = argv; - for (; myargc > 0; --myargc, ++argv) { - - /* Allow for "holes" in argv list */ - - if (*argv == NULL || *argv[0] == '\0') - continue; - - /* Loop over all options tables, starting with the last */ - - for (i = tables-1; i >= 0; i--) { - - /* Check option table for option */ - - status = ParseOpt(&myargc, &argv, p_argc, &argsave, - ploption_info[i].options); - - if ( ! status) break; - } - - /* Handle error return as specified by the mode flag */ - - if (status == -1) { - - /* No match. Keep going if mode_skip is set, otherwise abort if - fully parsing, else return without error. */ - - if (mode_skip) { - if ( ! mode_nodelete) - *argsave++ = *argv; - continue; - } - if ( ! mode_quiet && mode_full) { - fprintf(stderr, "\nBad command line option \"%s\"\n", argv[0]); - plOptUsage(); - } - if (mode_full) exit(1); - - status = 0; - break; - - } else if (status == 1) { - - /* Illegal or badly formed */ - - if ( ! mode_quiet) { - fprintf(stderr, "\nBad command line option \"%s\"\n", argv[0]); - plOptUsage(); - } - if (mode_full) exit(1); - - break; - - } else if (status == 2) { - - /* Informational option encountered (-h or -v) */ - - exit(0); - } - } - -/* Compress and NULL-terminate argv */ - - if ( ! mode_nodelete) { - for (i = 0; i < myargc; i++) - *argsave++ = *argv++; - - if (argsave < argend) - *argsave = NULL; - } - - return status; -} - -/*--------------------------------------------------------------------------*\ - * ParseOpt() - * - * Parses & determines appropriate action for input flag. -\*--------------------------------------------------------------------------*/ - -static int -ParseOpt(int *p_myargc, char ***p_argv, int *p_argc, char ***p_argsave, - PLOptionTable *option_table) -{ - PLOptionTable *tab; - char *opt; - -/* Only handle actual flags and their arguments */ - - if ( mode_nodash || (*p_argv)[0][0] == '-') { - - opt = (*p_argv)[0]; - if (*opt == '-') - opt++; - - for (tab = option_table; tab->opt; tab++) { - - /* Skip if option not enabled */ - - if (tab->mode & PL_OPT_DISABLED) - continue; - - /* Try to match it */ - - if (*opt == *tab->opt && ! strcmp(opt, tab->opt)) { - - /* Option matched, so remove from argv list if applicable. */ - - if ( ! mode_nodelete) { - if (tab->mode & PL_OPT_NODELETE) - (*(*p_argsave)++) = (**p_argv); - else - --(*p_argc); - } - - /* Process option (and argument if applicable) */ - - return (ProcessOpt(opt, tab, p_myargc, p_argv, p_argc)); - } - } - } - - return -1; -} - -/*--------------------------------------------------------------------------*\ - * ProcessOpt() - * - * Process option (and argument if applicable). -\*--------------------------------------------------------------------------*/ - -static int -ProcessOpt(char *opt, PLOptionTable *tab, int *p_myargc, char ***p_argv, - int *p_argc) -{ - int need_arg, res; - char *optarg = NULL; - -/* Get option argument if necessary */ - - need_arg = PL_OPT_ARG | PL_OPT_INT | PL_OPT_FLOAT | PL_OPT_STRING; - - if (tab->mode & need_arg) { - if (GetOptarg(&optarg, p_myargc, p_argv, p_argc)) - return 1; - } - -/* Process argument */ - - switch (tab->mode & 0xFF00) { - - case PL_OPT_FUNC: - - /* Call function handler to do the job */ - - if (tab->handler == NULL) { - fprintf(stderr, - "ProcessOpt: no handler specified for option %s\n", - tab->opt); - return 1; - } - - if (mode_nodelete && optarg) { - - /* Make a copy, since handler may mung optarg with strtok() */ - char *copy = - (char *) malloc((size_t)(1+strlen(optarg))*sizeof(char)); - if (copy == NULL) { - plabort("ProcessOpt: out of memory"); - return 1; - } - strcpy(copy, optarg); - res = ((*tab->handler) (opt, copy, tab->client_data)); - free((void *) copy); - return res; - } - else { - return ((*tab->handler) (opt, optarg, tab->client_data)); - } - - case PL_OPT_BOOL: - - /* Set *var as a boolean */ - - if (tab->var == NULL) { - fprintf(stderr, - "ProcessOpt: no variable specified for option %s\n", - tab->opt); - return 1; - } - *(int *)tab->var = 1; - break; - - case PL_OPT_INT: - - /* Set *var as an int */ - - if (tab->var == NULL) { - fprintf(stderr, - "ProcessOpt: no variable specified for option %s\n", - tab->opt); - return 1; - } - *(int *)tab->var = atoi(optarg); - break; - - case PL_OPT_FLOAT: - - /* Set *var as a float */ - - if (tab->var == NULL) { - fprintf(stderr, - "ProcessOpt: no variable specified for option %s\n", - tab->opt); - return 1; - } - *(PLFLT *)tab->var = atof(optarg); - break; - - case PL_OPT_STRING: - - /* Set var (can be NULL initially) to point to optarg string */ - - *(char **)tab->var = (char *)optarg; - break; - - default: - - /* Somebody messed up.. */ - - fprintf(stderr, - "ProcessOpt: invalid processing mode for option %s\n", - tab->opt); - return 1; - } - return 0; -} - -/*--------------------------------------------------------------------------*\ - * GetOptarg() - * - * Retrieves an option argument. - * If an error occurs here it is a true syntax error. -\*--------------------------------------------------------------------------*/ - -static int -GetOptarg(char **poptarg, int *p_myargc, char ***p_argv, int *p_argc) -{ - int result = 0; - - --(*p_myargc); - - if ((*p_myargc) <= 0) /* oops, no more arguments */ - result = 1; - - if ( ! result) { - (*p_argv)++; - if ((*p_argv)[0][0] == '-' && isalpha((*p_argv)[0][1])) { - - (*p_argv)--; /* oops, next arg is a flag */ - result = 1; - } - } - - if ( ! result) { /* yeah, the user got it right */ - (*p_argc)--; - *poptarg = (*p_argv)[0]; - } - else { - if ( ! mode_quiet) { - fprintf(stderr, "Argument missing for %s option.\n", (*p_argv)[0]); - plOptUsage(); - } - } - return result; -} - -/*--------------------------------------------------------------------------*\ - * plSetUsage() - * - * Set the strings used in usage and syntax messages. -\*--------------------------------------------------------------------------*/ - -void -plSetUsage(char *program_string, char *usage_string) -{ - if (program_string != NULL) - program = program_string; - - if (usage_string != NULL) - usage = usage_string; -} - -/*--------------------------------------------------------------------------*\ - * plOptUsage() - * - * Print usage & syntax message. -\*--------------------------------------------------------------------------*/ - -void -plOptUsage(void) -{ - if (usage == NULL) - fprintf(stderr, "\nUsage:\n %s [options]\n", program); - else - fputs(usage, stderr); - - Syntax(); - - fprintf(stderr, "\n\nType %s -h for a full description.\n\n", - program); -} - -/*--------------------------------------------------------------------------*\ - * Syntax() - * - * Print short syntax message. -\*--------------------------------------------------------------------------*/ - -static void -Syntax(void) -{ - PLOptionTable *tab; - int i, col, len; - -/* Loop over all options tables */ - - for (i = tables-1; i >= 0; i--) { - - /* Introducer */ - - if (ploption_info[i].name) - fprintf(stderr, "\n%s:", ploption_info[i].name); - else - fputs("\nUser options:", stderr); - - /* Print syntax for each option */ - - col = 80; - for (tab = ploption_info[i].options; tab->opt; tab++) { - if (tab->mode & PL_OPT_DISABLED) - continue; - - if ( ! mode_showall && (tab->mode & PL_OPT_INVISIBLE)) - continue; - - if (tab->syntax == NULL) - continue; - - len = 3 + strlen(tab->syntax); /* space [ string ] */ - if (col + len > 79) { - fprintf(stderr, "\n "); /* 3 spaces */ - col = 3; - } - fprintf(stderr, " [%s]", tab->syntax); - col += len; - } - fprintf(stderr, "\n"); - } -} - -/*--------------------------------------------------------------------------*\ - * Help() - * - * Print long help message. -\*--------------------------------------------------------------------------*/ - -static void -Help(void) -{ - PLOptionTable *tab; - char **note; - int i; - FILE *outfile = stderr; - -#ifdef HAVE_POPEN - FILE *pager = NULL; - if (getenv("PAGER") != NULL) - pager = (FILE *) popen("$PAGER", "w"); - if (pager == NULL) - pager = (FILE *) popen("more", "w"); - if (pager != NULL) - outfile = pager; -#endif - -/* Usage line */ - - if (usage == NULL) - fprintf(outfile, "\nUsage:\n %s [options]\n", program); - else - fputs(usage, outfile); - -/* Loop over all options tables */ - - for (i = tables-1; i >= 0; i--) { - - /* Introducer */ - - if (ploption_info[i].name) - fprintf(outfile, "\n%s:\n", ploption_info[i].name); - else - fputs("\nUser options:\n", outfile); - - /* Print description for each option */ - - for (tab = ploption_info[i].options; tab->opt; tab++) { - if (tab->mode & PL_OPT_DISABLED) - continue; - - if ( ! mode_showall && (tab->mode & PL_OPT_INVISIBLE)) - continue; - - if (tab->desc == NULL) - continue; - - if (tab->mode & PL_OPT_INVISIBLE) - fprintf(outfile, " * %-20s %s\n", tab->syntax, tab->desc); - else - fprintf(outfile, " %-20s %s\n", tab->syntax, tab->desc); - } - - /* Usage notes */ - - if (ploption_info[i].notes) { - putc('\n', outfile); - for (note = ploption_info[i].notes; *note; note++) { - fputs(*note, outfile); - putc('\n', outfile); - } - } - } - -#ifdef HAVE_POPEN - if (pager != NULL) - pclose(pager); -#endif -} - -/*--------------------------------------------------------------------------*\ - * plParseDrvOpts - * - * Parse driver specific options -\*--------------------------------------------------------------------------*/ - -int -plParseDrvOpts(DrvOpt *acc_opt) { - DrvOptCmd *drvp; - DrvOpt *t; - int fl; - char msg[80]; - - if (!drv_opt.option) - return 1; - - drvp = &drv_opt; - do { - t = acc_opt; fl = 0; - while (t->opt) { - if (strcmp(drvp->option, t->opt) == 0) { - fl = 1; - switch (t->type) { - - case DRV_STR: - *(char **)(t->var_ptr) = (drvp->value); -#ifdef DEBUG - fprintf(stderr,"plParseDrvOpts: %s %s\n", t->opt, *(char**)t->var_ptr); -#endif - break; - - case DRV_INT: - if (sscanf(drvp->value, "%d", (int *)t->var_ptr) != 1) { - sprintf(msg,"Incorrect argument to '%s' option", drvp->option); - plexit(msg); - } -#ifdef DEBUG - fprintf(stderr,"plParseDrvOpts: %s %d\n", t->opt, *(int *) t->var_ptr); -#endif - break; - - case DRV_FLT: - if (sscanf(drvp->value, "%f", (float *)t->var_ptr) != 1) { - sprintf(msg,"Incorrect argument to '%s' option", drvp->option); - plexit(msg); - } -#ifdef DEBUG - fprintf(stderr,"plParseDrvOpts: %s %f\n", t->opt, *(float *) t->var_ptr); -#endif - break; - } - } - t++; - } - - if (!fl) { - sprintf(msg, "Option '%s' not recognized.\n\nRecognized options for this driver are:\n", drvp->option); - plwarn(msg); - plHelpDrvOpts(acc_opt); - plexit(""); - } - } - while((drvp = drvp->next)) - ; - - return 0; -} - -/*--------------------------------------------------------------------------*\ - * plHelpDrvOpts - * - * Give driver specific help -\*--------------------------------------------------------------------------*/ - -void -plHelpDrvOpts(DrvOpt *acc_opt) { - DrvOpt *t; - - t = acc_opt; - while(t->opt) { - fprintf(stderr, "%s:\t%s\n", t->opt, t->hlp_msg); - t++; - } -} - -/*--------------------------------------------------------------------------*\ - * Option handlers -\*--------------------------------------------------------------------------*/ - -/*--------------------------------------------------------------------------*\ - * opt_h() - * - * Performs appropriate action for option "h": - * Issues help message -\*--------------------------------------------------------------------------*/ - -static int -opt_h(char *opt, char *optarg, void *client_data) -{ - if ( ! mode_quiet) - Help(); - - return 2; -} - -/*--------------------------------------------------------------------------*\ - * opt_v() - * - * Performs appropriate action for option "v": - * Issues version message -\*--------------------------------------------------------------------------*/ - -static int -opt_v(char *opt, char *optarg, void *client_data) -{ - if ( ! mode_quiet) - fprintf(stderr, "PLplot library version: %s\n", VERSION); - - return 2; -} - -/*--------------------------------------------------------------------------*\ - * opt_verbose() - * - * Performs appropriate action for option "verbose": - * Turn on verbosity flag -\*--------------------------------------------------------------------------*/ - -static int -opt_verbose(char *opt, char *optarg, void *client_data) -{ - plsc->verbose = 1; - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_debug() - * - * Performs appropriate action for option "debug": - * Turn on debugging flag -\*--------------------------------------------------------------------------*/ - -static int -opt_debug(char *opt, char *optarg, void *client_data) -{ - plsc->debug = 1; - plsc->verbose = 1; - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_hack() - * - * Performs appropriate action for option "hack": - * Enables driver-specific hack(s) -\*--------------------------------------------------------------------------*/ - -static int -opt_hack(char *opt, char *optarg, void *client_data) -{ - plsc->hack = 1; - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_dev() - * - * Performs appropriate action for option "dev": - * Sets output device keyword -\*--------------------------------------------------------------------------*/ - -static int -opt_dev(char *opt, char *optarg, void *client_data) -{ - plsdev(optarg); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_o() - * - * Performs appropriate action for option "o": - * Sets output file name -\*--------------------------------------------------------------------------*/ - -static int -opt_o(char *opt, char *optarg, void *client_data) -{ - plsfnam(optarg); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_mar() - * - * Performs appropriate action for option "mar": - * Sets relative margin width -\*--------------------------------------------------------------------------*/ - -static int -opt_mar(char *opt, char *optarg, void *client_data) -{ - plsdidev(atof(optarg), PL_NOTSET, PL_NOTSET, PL_NOTSET); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_a() - * - * Performs appropriate action for option "a": - * Sets plot aspect ratio on page -\*--------------------------------------------------------------------------*/ - -static int -opt_a(char *opt, char *optarg, void *client_data) -{ - plsdidev(PL_NOTSET, atof(optarg), PL_NOTSET, PL_NOTSET); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_jx() - * - * Performs appropriate action for option "jx": - * Sets relative justification in x -\*--------------------------------------------------------------------------*/ - -static int -opt_jx(char *opt, char *optarg, void *client_data) -{ - plsdidev(PL_NOTSET, PL_NOTSET, atof(optarg), PL_NOTSET); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_jy() - * - * Performs appropriate action for option "jy": - * Sets relative justification in y -\*--------------------------------------------------------------------------*/ - -static int -opt_jy(char *opt, char *optarg, void *client_data) -{ - plsdidev(PL_NOTSET, PL_NOTSET, PL_NOTSET, atof(optarg)); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_ori() - * - * Performs appropriate action for option "ori": - * Sets orientation -\*--------------------------------------------------------------------------*/ - -static int -opt_ori(char *opt, char *optarg, void *client_data) -{ - plsdiori(atof(optarg)); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_freeaspect() - * - * Performs appropriate action for option "freeaspect": - * Allow aspect ratio to adjust to orientation swaps. -\*--------------------------------------------------------------------------*/ - -static int -opt_freeaspect(char *opt, char *optarg, void *client_data) -{ - plsc->freeaspect = 1; - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_portrait() - * - * Performs appropriate action for option "portrait": - * Set portrait mode. If plsc->portrait = 1, then the orientation for certain - * drivers is changed by 90 deg to portrait orientation from the default - * landscape orientation used by PLplot while the aspect ratio allowed to - * adjust using freeaspect. - * N.B. the driver list where this flag is honored is currently limited - * to ljii, ljiip, psc, ps, and pstex. A 90 deg rotation is just not - * appropriate for certain other drivers. These drivers where portrait - * mode is ignored include display drivers (e.g., xwin, tk), drivers - * which are subequently going to be transformed to another form - * (e.g., meta or pbm), or drivers which are normally used for web - * publishing (e.g., png, jpeg). That said, the case is not entirely clear - * for all drivers so the list of drivers where portrait mode is honored - * may increase in the future. To add to the list simply copy the small - * bit of code from ps.c that has to do with pls->portrait to the - * appropriate driver file. -\*--------------------------------------------------------------------------*/ - -static int -opt_portrait(char *opt, char *optarg, void *client_data) -{ - plsc->portrait = 1; - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_width() - * - * Performs appropriate action for option "width": - * Sets pen width -\*--------------------------------------------------------------------------*/ - -static int -opt_width(char *opt, char *optarg, void *client_data) -{ - int width; - - width = atoi(optarg); - if (width < 0) { - fprintf(stderr, "?invalid width\n"); - return 1; - } - else { - plwid(width); - plsc->widthlock = 1; - } - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_bg() - * - * Performs appropriate action for option "bg": - * Sets background color -\*--------------------------------------------------------------------------*/ - -static int -opt_bg(char *opt, char *optarg, void *client_data) -{ - char *rgb; - long bgcolor, r, g, b; - -/* Always in hex! Strip off leading "#" (TK-ism) if present. */ - - if (*optarg == '#') - rgb = optarg + 1; - else - rgb = optarg; - -/* Get number in hex */ - - bgcolor = strtol(rgb, NULL, 16); - -/* Must be either a 3 or 6 digit hex number */ -/* If 3 digits, each is "doubled" (i.e. ABC becomes AABBCC). */ - - switch (strlen(rgb)) { - case 3: - r = (bgcolor & 0xF00) >> 8; - g = (bgcolor & 0x0F0) >> 4; - b = (bgcolor & 0x00F); - - r = r | (r << 4); - g = g | (g << 4); /* doubling */ - b = b | (b << 4); - break; - - case 6: - r = (bgcolor & 0xFF0000) >> 16; - g = (bgcolor & 0x00FF00) >> 8; - b = (bgcolor & 0x0000FF); - break; - - default: - fprintf(stderr, "Unrecognized background color value %s\n", rgb); - return 1; - } - - plscolbg(r, g, b); - - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_ncol0() - * - * Performs appropriate action for option "ncol0": - * Sets number of colors to allocate in cmap 0 (upper bound). -\*--------------------------------------------------------------------------*/ - -static int -opt_ncol0(char *opt, char *optarg, void *client_data) -{ - plsc->ncol0 = atoi(optarg); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_ncol1() - * - * Performs appropriate action for option "ncol1": - * Sets number of colors to allocate in cmap 1 (upper bound). -\*--------------------------------------------------------------------------*/ - -static int -opt_ncol1(char *opt, char *optarg, void *client_data) -{ - plsc->ncol1 = atoi(optarg); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_wplt() - * - * Performs appropriate action for option "wplt": - * Sets (zoom) window into plot (e.g. "0,0,0.5,0.5") -\*--------------------------------------------------------------------------*/ - -static int -opt_wplt(char *opt, char *optarg, void *client_data) -{ - char *field; - PLFLT xl, yl, xr, yr; - - strncpy(opttmp, optarg, OPTMAX-1); - - if ((field = strtok(opttmp, ",")) == NULL) - return 1; - - xl = atof(field); - - if ((field = strtok(NULL, ",")) == NULL) - return 1; - - yl = atof(field); - - if ((field = strtok(NULL, ",")) == NULL) - return 1; - - xr = atof(field); - - if ((field = strtok(NULL, ",")) == NULL) - return 1; - - yr = atof(field); - - plsdiplt(xl, yl, xr, yr); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_drvopt() - * - * Get driver specific options in the form [,option[=value]]* - * If "value" is not specified, it defaults to "1". -\*--------------------------------------------------------------------------*/ - -static int -opt_drvopt(char *opt, char *optarg, void *client_data) -{ - char t, *tt, *option, *value; - int fl = 0; - DrvOptCmd *drvp; - - option = (char *) malloc((size_t)(1+strlen(optarg))*sizeof(char)); - if (option == NULL) - plexit("opt_drvopt: Out of memory!?"); - - value = (char *) malloc((size_t)(1+1)*sizeof(char)); - if (value == NULL) - plexit("opt_drvopt: Out of memory!?"); - - drvp = &drv_opt; - *option = *value = '\0'; - tt = option; - while((t = *optarg++)) { - switch (t) { - case ',': - if (fl) - fl = 0; - else { - value[0] = '1'; - value[1] = '\0'; - } - - *tt = '\0'; tt = option; - drvp->option = plstrdup(option); /* it should not be release, because of familying */ - drvp->value = plstrdup(value); /* don't release */ - drvp->next = (DrvOptCmd *) malloc(sizeof(DrvOptCmd)); /* don't release */ - if (drvp->next == NULL) - plexit("opt_drvopt: Out of memory!?\n"); - - drvp = drvp->next; - break; - - case '=': - fl = 1; - *tt = '\0'; tt = value; - break; - - default: - *tt++ = t; - } - } - - *tt = '\0'; - if (!fl) { - value[0] = '1'; - value[1] = '\0'; - } - - drvp->option = plstrdup(option); /* don't release */ - drvp->value = plstrdup(value); /* don't release */ - drvp->next = NULL; - -#ifdef DEBUG - fprintf(stderr, "\nopt_drvopt: -drvopt parsed options:\n"); - drvp = &drv_opt; - do - fprintf(stderr, "%s %s\n", drvp->option, drvp->value); - while(drvp = drvp->next); - fprintf(stderr, "\n"); -#endif - - free(option); free(value); - - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_fam() - * - * Performs appropriate action for option "fam": - * Enables family output files -\*--------------------------------------------------------------------------*/ - -static int -opt_fam(char *opt, char *optarg, void *client_data) -{ - plsfam(1, -1, -1); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_fsiz() - * - * Performs appropriate action for option "fsiz": - * Sets size of a family member file (may be somewhat larger since eof must - * occur at a page break). Also turns on familying. Example usage: - * - * -fsiz 5M (5 MB) - * -fsiz 300K (300 KB) - * -fsiz .3M (same) - * -fsiz .5G (half a GB) - * - * Note case of the trailing suffix doesn't matter. - * If no suffix, defaults to MB. -\*--------------------------------------------------------------------------*/ - -static int -opt_fsiz(char *opt, char *optarg, void *client_data) -{ - PLINT bytemax; - int len = strlen(optarg); - char lastchar = optarg[len-1]; - PLFLT multiplier = 1.0e6; - char *spec = (char*)malloc(len+1); - -/* Interpret optional suffix */ - - switch (lastchar) { - case 'k': - case 'K': - multiplier = 1.0e3; len--; - break; - case 'm': - case 'M': - multiplier = 1.0e6; len--; - break; - case 'g': - case 'G': - multiplier = 1.0e9; len--; - break; - } - strncpy(spec, optarg, len); - spec[len] = '\0'; - - bytemax = multiplier * atof(spec); - if (bytemax == 0) { - fprintf(stderr, "?invalid bytemax\n"); - return 1; - } - plsfam(1, -1, bytemax); - - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_fbeg() - * - * Performs appropriate action for option "fbeg": - * Starts with the specified family member number. -\*--------------------------------------------------------------------------*/ - -static int -opt_fbeg(char *opt, char *optarg, void *client_data) -{ - plsc->member = atoi(optarg); - - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_finc() - * - * Performs appropriate action for option "finc": - * Specify increment between family members. -\*--------------------------------------------------------------------------*/ - -static int -opt_finc(char *opt, char *optarg, void *client_data) -{ - plsc->finc = atoi(optarg); - - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_fflen() - * - * Performs appropriate action for option "fflen": - * Specify minimum field length for family member number. -\*--------------------------------------------------------------------------*/ - -static int -opt_fflen(char *opt, char *optarg, void *client_data) -{ - plsc->fflen = atoi(optarg); - - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_np() - * - * Performs appropriate action for option "np": - * Disables pause between pages -\*--------------------------------------------------------------------------*/ - -static int -opt_np(char *opt, char *optarg, void *client_data) -{ - plspause(0); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_nopixmap() - * - * Performs appropriate action for option "nopixmap": - * Disables use of pixmaps in X drivers -\*--------------------------------------------------------------------------*/ - -static int -opt_nopixmap(char *opt, char *optarg, void *client_data) -{ - plsc->nopixmap = 1; - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_db() - * - * Performs appropriate action for option "db": - * Double buffer X output (update only done on eop or Expose) -\*--------------------------------------------------------------------------*/ - -static int -opt_db(char *opt, char *optarg, void *client_data) -{ - plsc->db = 1; - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_bufmax() - * - * Performs appropriate action for option "bufmax": - * Sets size of data buffer for tk driver -\*--------------------------------------------------------------------------*/ - -static int -opt_bufmax(char *opt, char *optarg, void *client_data) -{ - plsc->bufmax = atoi(optarg); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_server_name() - * - * Performs appropriate action for option "server_name": - * Sets main window name of server (Tcl/TK/DP driver only) -\*--------------------------------------------------------------------------*/ - -static int -opt_server_name(char *opt, char *optarg, void *client_data) -{ - plsc->server_name = optarg; - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_server_host() - * - * Performs appropriate action for option "server_host": - * Sets host to run server on (Tcl/TK/DP driver only) -\*--------------------------------------------------------------------------*/ - -static int -opt_server_host(char *opt, char *optarg, void *client_data) -{ - plsc->server_host = optarg; - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_server_port() - * - * Performs appropriate action for option "server_port": - * Sets port to talk to server on (Tcl/TK/DP driver only) -\*--------------------------------------------------------------------------*/ - -static int -opt_server_port(char *opt, char *optarg, void *client_data) -{ - plsc->server_port = optarg; - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_user() - * - * Performs appropriate action for option "user": - * Sets user name on remote node (for remsh), dp driver only -\*--------------------------------------------------------------------------*/ - -static int -opt_user(char *opt, char *optarg, void *client_data) -{ - plsc->user = optarg; - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_plserver() - * - * Performs appropriate action for option "plserver": - * Sets name to use when invoking server (Tcl/TK/DP driver only) -\*--------------------------------------------------------------------------*/ - -static int -opt_plserver(char *opt, char *optarg, void *client_data) -{ - plsc->plserver = optarg; - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_plwindow() - * - * Performs appropriate action for option "plwindow": - * Sets PLplot window name -\*--------------------------------------------------------------------------*/ - -static int -opt_plwindow(char *opt, char *optarg, void *client_data) -{ - plsc->plwindow = (char *) malloc((size_t)(1+strlen(optarg))*sizeof(char)); - strcpy (plsc->plwindow, optarg); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_tcl_cmd() - * - * Performs appropriate action for option "tcl_cmd": - * Sets TCL command(s) to eval on startup -\*--------------------------------------------------------------------------*/ - -static int -opt_tcl_cmd(char *opt, char *optarg, void *client_data) -{ - plsc->tcl_cmd = optarg; - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_auto_path() - * - * Performs appropriate action for option "auto_path": - * Sets additional directories to autoload -\*--------------------------------------------------------------------------*/ - -static int -opt_auto_path(char *opt, char *optarg, void *client_data) -{ - plsc->auto_path = optarg; - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_px() - * - * Performs appropriate action for option "px": - * Set packing in x -\*--------------------------------------------------------------------------*/ - -static int -opt_px(char *opt, char *optarg, void *client_data) -{ - plssub(atoi(optarg), -1); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_py() - * - * Performs appropriate action for option "py": - * Set packing in y -\*--------------------------------------------------------------------------*/ - -static int -opt_py(char *opt, char *optarg, void *client_data) -{ - plssub(-1, atoi(optarg)); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_geo() - * - * Performs appropriate action for option "geo": - * Set geometry for output window - * e.g., "-geometry 400x400+100+0" - * or with offsets alone "-geometry +Xoff+Yoff" - * e.g., "-geometry +100+0" -\*--------------------------------------------------------------------------*/ - -static int -opt_geo(char *opt, char *optarg, void *client_data) -{ - char *field; - PLFLT xdpi = 0., ydpi = 0.; - PLINT xwid = 0, ywid = 0, xoff = 0, yoff = 0; - -/* The TK driver uses the geometry string directly */ - - plsc->geometry = (char *) malloc((size_t)(1+strlen(optarg))*sizeof(char)); - strcpy (plsc->geometry, optarg); - -/* Set up plplot dimensions */ - - strncpy(opttmp, optarg, OPTMAX-1); - if (strchr (opttmp, 'x')) { - - /* -geometry WxH or -geometry WxH+Xoff+Yoff */ - - field = strtok (opttmp, "x"); - xwid = atoi (field); - if (xwid == 0) - fprintf (stderr, "?invalid xwid\n"); - - if ((field = strtok (NULL, "+")) == NULL) - return 1; - - ywid = atoi (field); - if (ywid == 0) - fprintf (stderr, "?invalid ywid\n"); - - field = strtok (NULL, "+"); - } - else { - - /* -geometry +Xoff or -geometry +Xoff+Yoff only */ - - field = strtok (opttmp, "+"); - } - - if (field != NULL) { - xoff = atoi (field); - if ((field = strtok (NULL, "+")) != NULL) - yoff = atoi (field); - } - - plspage (xdpi, ydpi, xwid, ywid, xoff, yoff); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_tk_file() - * - * File name for plserver tk_file option -\*--------------------------------------------------------------------------*/ - -static int -opt_tk_file(char *opt, char *optarg, void *client_data) -{ - plsc->tk_file = (char *) malloc((size_t)(1+strlen(optarg))*sizeof(char)); - strcpy (plsc->tk_file, optarg); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_dpi() - * - * Performs appropriate action for option "dpi": - * Set dpi resolution for output device - * e.g., "-dpi 600x300", will set X dpi to 600 and Y dpi to 300 - * or - * e.g., "-dpi 1200" - * Will set both X and Y dpi to 1200 dpi -\*--------------------------------------------------------------------------*/ - -static int -opt_dpi(char *opt, char *optarg, void *client_data) -{ - char *field; - PLFLT xdpi = 0., ydpi = 0.; - PLINT xwid = 0, ywid = 0, xoff = 0, yoff = 0; - - strncpy(opttmp, optarg, OPTMAX-1); - if (strchr (opttmp, 'x')) { - field = strtok (opttmp, "x"); - xdpi = atof (field); - if (xdpi == 0) - fprintf (stderr, "?invalid xdpi\n"); - - if ((field = strtok (NULL, " ")) == NULL) - return 1; - - ydpi = atof (field); - if (ydpi == 0) - fprintf (stderr, "?invalid ydpi\n"); - - } else { - xdpi = atof (opttmp); - ydpi=xdpi; - if (xdpi==0) return 1; - } - - plspage (xdpi, ydpi, xwid, ywid, xoff, yoff); - return 0; -} - -/*--------------------------------------------------------------------------*\ - * opt_dev_compression() - * - * Sets device compression -\*--------------------------------------------------------------------------*/ - -static int -opt_dev_compression(char *opt, char *optarg, void *client_data) -{ - PLINT comp = 0; - - comp = atoi(optarg); - if (comp == 0) { - fprintf(stderr, "?invalid compression\n"); - return 1; - } - plscompression (comp); - - return 0; -} diff --git a/src/plot/plplot/plbox.c b/src/plot/plplot/plbox.c deleted file mode 100644 index b55bc8fa70..0000000000 --- a/src/plot/plplot/plbox.c +++ /dev/null @@ -1,1352 +0,0 @@ -/* $Id: plbox.c,v 1.2 2005/03/17 21:39:21 eli Exp $ - - Routines for drawing axes & box around the current viewport. -*/ - -#include "plplotP.h" - -static PLFLT xlog[8] = -{ - 0.301030, 0.477121, 0.602060, 0.698970, - 0.778151, 0.845098, 0.903090, 0.954243 -}; - -/* Static function prototypes */ - -static void -plxybx(const char *opt, const char *label, PLFLT wx1, PLFLT wy1, - PLFLT wx2, PLFLT wy2, PLFLT vmin, PLFLT vmax, - PLFLT tick, PLINT nsub, PLINT nolast, PLINT *digits); - -static void -plzbx(const char *opt, const char *label, PLINT right, PLFLT dx, PLFLT dy, - PLFLT wx, PLFLT wy1, PLFLT wy2, PLFLT vmin, PLFLT vmax, - PLFLT tick, PLINT nsub, PLINT *digits); - -static void -plxytx(PLFLT wx1, PLFLT wy1, PLFLT wx2, PLFLT wy2, - PLFLT disp, PLFLT pos, PLFLT just, const char *text); - -static void -plztx(const char *opt, PLFLT dx, PLFLT dy, PLFLT wx, PLFLT wy1, - PLFLT wy2, PLFLT disp, PLFLT pos, PLFLT just, const char *text); - -static void -plform(PLFLT value, PLINT scale, PLINT prec, char *result, PLINT ll, PLINT lf); - -static void -grid_box(const char *xopt, PLFLT xtick1, PLINT nxsub1, - const char *yopt, PLFLT ytick1, PLINT nysub1); - -static void -label_box(const char *xopt, PLFLT xtick1, const char *yopt, PLFLT ytick1); - -/*--------------------------------------------------------------------------*\ - * void plbox() - * - * This draws a box around the current viewport, complete with axes, ticks, - * numeric labels, and grids, according to input specification. Just a - * front-end to plaxes(), which allows arbitrary placement of coordinate - * axes when plotted (here the origin is at 0,0). See the documentation for - * plaxes() for more info. -\*--------------------------------------------------------------------------*/ - -void -c_plbox(const char *xopt, PLFLT xtick, PLINT nxsub, - const char *yopt, PLFLT ytick, PLINT nysub) -{ - c_plaxes(0.0, 0.0, xopt, xtick, nxsub, yopt, ytick, nysub); -} - -/*--------------------------------------------------------------------------*\ - * void plaxes() - * - * This draws a box around the current viewport, complete with axes, - * ticks, numeric labels, and grids, according to input specification. - * - * x0 and y0 specify the origin of the axes. - * - * xopt and yopt are character strings which define the box as follows: - * - * a: Draw axis (X is horizontal line Y=0, Y is vertical line X=0) - * b: Draw bottom (X) or left (Y) edge of frame - * c: Draw top (X) or right (Y) edge of frame - * f: Always use fixed point numeric labels - * g: Draws a grid at the major tick interval - * h: Draws a grid at the minor tick interval - * i: Inverts tick marks - * l: Logarithmic axes, major ticks at decades, minor ticks at units - * n: Write numeric label at conventional location - * m: Write numeric label at unconventional location - * t: Draw major tick marks - * s: Draw minor tick marks - * v: (for Y only) Label vertically - * - * xtick, ytick are the major tick intervals required, zero for - * automatic selection - * - * nxsub, nysub are the number of subtick intervals in a major tick - * interval -\*--------------------------------------------------------------------------*/ - -void -c_plaxes(PLFLT x0, PLFLT y0, - const char *xopt, PLFLT xtick, PLINT nxsub, - const char *yopt, PLFLT ytick, PLINT nysub) -{ - PLINT lax, lbx, lcx, lgx, lix, llx, lsx, ltx; - PLINT lay, lby, lcy, lgy, liy, lly, lsy, lty; - PLINT xmajor, xminor, ymajor, yminor; - PLINT i, i1x, i2x, i3x, i4x, i1y, i2y, i3y, i4y; - PLINT nxsub1, nysub1; - PLINT lxmin, lxmax, lymin, lymax; - PLINT pxmin, pxmax, pymin, pymax; - PLINT vppxmi, vppxma, vppymi, vppyma; - PLFLT xtick1, ytick1, vpwxmi, vpwxma, vpwymi, vpwyma; - PLFLT vpwxmin, vpwxmax, vpwymin, vpwymax; - PLFLT xp0, yp0, tn, tp, temp; - - if (plsc->level < 3) { - plabort("plbox: Please set up window first"); - return; - } - -/* Open the clip limits to the subpage limits */ - - plP_gclp(&lxmin, &lxmax, &lymin, &lymax); - plP_gphy(&pxmin, &pxmax, &pymin, &pymax); - plP_sclp(pxmin, pxmax, pymin, pymax); - - vppxmi = plsc->vppxmi; - vppxma = plsc->vppxma; - vppymi = plsc->vppymi; - vppyma = plsc->vppyma; - -/* Convert world coordinates to physical */ - - xp0 = plP_wcpcx(x0); - yp0 = plP_wcpcy(y0); - -/* Set plot options from input */ - - lax = plP_stsearch(xopt, 'a'); - lbx = plP_stsearch(xopt, 'b'); - lcx = plP_stsearch(xopt, 'c'); - lgx = plP_stsearch(xopt, 'g'); - lix = plP_stsearch(xopt, 'i'); - llx = plP_stsearch(xopt, 'l'); - lsx = plP_stsearch(xopt, 's'); - ltx = plP_stsearch(xopt, 't'); - - lay = plP_stsearch(yopt, 'a'); - lby = plP_stsearch(yopt, 'b'); - lcy = plP_stsearch(yopt, 'c'); - lgy = plP_stsearch(yopt, 'g'); - liy = plP_stsearch(yopt, 'i'); - lly = plP_stsearch(yopt, 'l'); - lsy = plP_stsearch(yopt, 's'); - lty = plP_stsearch(yopt, 't'); - -/* Tick and subtick sizes in device coords */ - - xmajor = MAX(ROUND(plsc->majht * plsc->ypmm), 1); - ymajor = MAX(ROUND(plsc->majht * plsc->xpmm), 1); - xminor = MAX(ROUND(plsc->minht * plsc->ypmm), 1); - yminor = MAX(ROUND(plsc->minht * plsc->xpmm), 1); - - nxsub1 = nxsub; - nysub1 = nysub; - xtick1 = llx ? 1.0 : xtick; - ytick1 = lly ? 1.0 : ytick; - - plgvpw(&vpwxmin, &vpwxmax, &vpwymin, &vpwymax); -/* n.b. large change; vpwxmi always numerically less than vpwxma, and - * similarly for vpwymi */ - vpwxmi = (vpwxmax > vpwxmin) ? vpwxmin : vpwxmax; - vpwxma = (vpwxmax > vpwxmin) ? vpwxmax : vpwxmin; - vpwymi = (vpwymax > vpwymin) ? vpwymin : vpwymax; - vpwyma = (vpwymax > vpwymin) ? vpwymax : vpwymin; - - lax = lax && vpwymi < y0 && y0 < vpwyma ; - lay = lay && vpwxmi < x0 && x0 < vpwxma ; - -/* Calculate tick spacing */ - - if (ltx || lgx) - pldtik(vpwxmi, vpwxma, &xtick1, &nxsub1); - - if (lty || lgy) - pldtik(vpwymi, vpwyma, &ytick1, &nysub1); -/* n.b. large change; xtick1, nxsub1, ytick1, nysub1 always positive. */ - -/* Set up tick variables */ - - if (lix) { - i1x = xminor; - i2x = 0; - i3x = xmajor; - i4x = 0; - } - else { - i1x = 0; - i2x = xminor; - i3x = 0; - i4x = xmajor; - } - - if (liy) { - i1y = yminor; - i2y = 0; - i3y = ymajor; - i4y = 0; - } - else { - i1y = 0; - i2y = yminor; - i3y = 0; - i4y = ymajor; - } - -/* Draw the bottom edge of the box */ - - if (lbx) { - plP_movphy(vppxmi, vppymi); - if (ltx) { - tp = xtick1 * floor(vpwxmi / xtick1); - for (;;) { - tn = tp + xtick1; - if (lsx) { - if (llx) { - for (i = 0; i <= 7; i++) { - temp = tp + xlog[i]; - if (BETW(temp, vpwxmi, vpwxma)) - plxtik(plP_wcpcx(temp), vppymi, i1x, i2x); - } - } - else { - for (i = 1; i <= nxsub1 - 1; i++) { - temp = tp + i * xtick1 / nxsub1; - if (BETW(temp, vpwxmi, vpwxma)) - plxtik(plP_wcpcx(temp), vppymi, i1x, i2x); - } - } - } - if (!BETW(tn, vpwxmi, vpwxma)) - break; - plxtik(plP_wcpcx(tn), vppymi, i3x, i4x); - tp = tn; - } - } - plP_draphy(vppxma, vppymi); - } - -/* Draw right-hand edge of box */ - - if (lcy) { - plP_movphy(vppxma, vppymi); - if (lty) { - tp = ytick1 * floor(vpwymi / ytick1); - for (;;) { - tn = tp + ytick1; - if (lsy) { - if (lly) { - for (i = 0; i <= 7; i++) { - temp = tp + xlog[i]; - if (BETW(temp, vpwymi, vpwyma)) - plytik(vppxma, plP_wcpcy(temp), i2y, i1y); - } - } - else { - for (i = 1; i <= nysub1 - 1; i++) { - temp = tp + i * ytick1 / nysub1; - if (BETW(temp, vpwymi, vpwyma)) - plytik(vppxma, plP_wcpcy(temp), i2y, i1y); - } - } - } - if (!BETW(tn, vpwymi, vpwyma)) - break; - plytik(vppxma, plP_wcpcy(tn), i4y, i3y); - tp = tn; - } - } - plP_draphy(vppxma, vppyma); - } - -/* Draw the top edge of the box */ - - if (lcx) { - plP_movphy(vppxma, vppyma); - if (ltx) { - tp = xtick1 * (floor(vpwxma / xtick1) + 1); - for (;;) { - tn = tp - xtick1; - if (lsx) { - if (llx) { - for (i = 7; i >= 0; i--) { - temp = tn + xlog[i]; - if (BETW(temp, vpwxmi, vpwxma)) - plxtik(plP_wcpcx(temp), vppyma, i2x, i1x); - } - } - else { - for (i = nxsub1 - 1; i >= 1; i--) { - temp = tn + i * xtick1 / nxsub1; - if (BETW(temp, vpwxmi, vpwxma)) - plxtik(plP_wcpcx(temp), vppyma, i2x, i1x); - } - } - } - if (!BETW(tn, vpwxmi, vpwxma)) - break; - plxtik(plP_wcpcx(tn), vppyma, i4x, i3x); - tp = tn; - } - } - plP_draphy(vppxmi, vppyma); - } - -/* Draw left-hand edge of box */ - - if (lby) { - plP_movphy(vppxmi, vppyma); - if (lty) { - tp = ytick1 * (floor(vpwyma / ytick1) + 1); - for (;;) { - tn = tp - ytick1; - if (lsy) { - if (lly) { - for (i = 7; i >= 0; i--) { - temp = tn + xlog[i]; - if (BETW(temp, vpwymi, vpwyma)) - plytik(vppxmi, plP_wcpcy(temp), i1y, i2y); - } - } - else { - for (i = nysub1 - 1; i >= 1; i--) { - temp = tn + i * ytick1 / nysub1; - if (BETW(temp, vpwymi, vpwyma)) - plytik(vppxmi, plP_wcpcy(temp), i1y, i2y); - } - } - } - if (!BETW(tn, vpwymi, vpwyma)) - break; - plytik(vppxmi, plP_wcpcy(tn), i3y, i4y); - tp = tn; - } - } - plP_draphy(vppxmi, vppymi); - } - -/* Draw the horizontal axis */ - - if (lax) { - plP_movphy(vppxmi, yp0); - if (ltx) { - tp = xtick1 * floor(vpwxmi / xtick1); - for (;;) { - tn = tp + xtick1; - if (lsx) { - if (llx) { - for (i = 0; i <= 7; i++) { - temp = tp + xlog[i]; - if (BETW(temp, vpwxmi, vpwxma)) - plxtik(plP_wcpcx(temp), yp0, xminor, xminor); - } - } - else { - for (i = 1; i <= nxsub1 - 1; i++) { - temp = tp + i * xtick1 / nxsub1; - if (BETW(temp, vpwxmi, vpwxma)) - plxtik(plP_wcpcx(temp), yp0, xminor, xminor); - } - } - } - if (!BETW(tn, vpwxmi, vpwxma)) - break; - plxtik(plP_wcpcx(tn), yp0, xmajor, xmajor); - tp = tn; - } - } - plP_draphy(vppxma, yp0); - } - -/* Draw the vertical axis */ - - if (lay) { - plP_movphy(xp0, vppymi); - if (lty) { - tp = ytick1 * floor(vpwymi / ytick1); - for (;;) { - tn = tp + ytick1; - if (lsy) { - if (lly) { - for (i = 0; i <= 7; i++) { - temp = tp + xlog[i]; - if (BETW(temp, vpwymi, vpwyma)) - plytik(xp0, plP_wcpcy(temp), yminor, yminor); - } - } - else { - for (i = 1; i <= nysub1 - 1; i++) { - temp = tp + i * ytick1 / nysub1; - if (BETW(temp, vpwymi, vpwyma)) - plytik(xp0, plP_wcpcy(temp), yminor, yminor); - } - } - } - if (!BETW(tn, vpwymi, vpwyma)) - break; - plytik(xp0, plP_wcpcy(tn), ymajor, ymajor); - tp = tn; - } - } - plP_draphy(xp0, vppyma); - } - -/* Draw grids */ - - grid_box(xopt, xtick1, nxsub1, yopt, ytick1, nysub1); - -/* Write labels */ - - label_box(xopt, xtick1, yopt, ytick1); - -/* Restore the clip limits to viewport edge */ - - plP_sclp(lxmin, lxmax, lymin, lymax); -} - -/*--------------------------------------------------------------------------*\ - * void plbox3() - * - * This is the 3-d analogue of plbox(). -\*--------------------------------------------------------------------------*/ - -MZ_DLLEXPORT -void -c_plbox3(const char *xopt, const char *xlabel, PLFLT xtick, PLINT nsubx, - const char *yopt, const char *ylabel, PLFLT ytick, PLINT nsuby, - const char *zopt, const char *zlabel, PLFLT ztick, PLINT nsubz) -{ - PLFLT dx, dy, tx, ty, ux, uy; - PLFLT xmin, xmax, ymin, ymax, zmin, zmax, zscale; - PLFLT cxx, cxy, cyx, cyy, cyz; - PLINT ln; - PLINT *zbflg, *zbcol; - PLFLT *zbtck; - PLINT xdigmax, xdigits; - PLINT ydigmax, ydigits; - PLINT zdigmax, zdigits; - - if (plsc->level < 3) { - plabort("plbox3: Please set up window first"); - return; - } - - plP_gw3wc(&cxx, &cxy, &cyx, &cyy, &cyz); - plP_gdom(&xmin, &xmax, &ymin, &ymax); - plP_grange(&zscale, &zmin, &zmax); - - plgxax(&xdigmax, &xdigits); - plgyax(&ydigmax, &ydigits); - plgzax(&zdigmax, &zdigits); - - xdigits = xdigmax; - ydigits = ydigmax; - zdigits = zdigmax; - -/* We have to wait until after the plot is drawn to draw back */ -/* grid so store this stuff. */ - - plP_gzback(&zbflg, &zbcol, &zbtck); - *zbflg = plP_stsearch(zopt, 'd'); - if (*zbflg) { - *zbtck = ztick; /* save tick spacing */ - *zbcol = plsc->icol0; /* and color */ - } - - if (cxx >= 0.0 && cxy <= 0.0) { - ln = plP_stsearch(xopt, 'n'); - tx = plP_w3wcx(xmin, ymin, zmin); - ty = plP_w3wcy(xmin, ymin, zmin); - ux = plP_w3wcx(xmax, ymin, zmin); - uy = plP_w3wcy(xmax, ymin, zmin); - plxybx(xopt, xlabel, tx, ty, ux, uy, - xmin, xmax, xtick, nsubx, 0, &xdigits); - - dx = ux - tx; - dy = uy - ty; - plzbx(zopt, zlabel, 1, dx, dy, ux, uy, - plP_w3wcy(xmax, ymin, zmax), zmin, zmax, ztick, nsubz, &zdigits); - - tx = plP_w3wcx(xmin, ymax, zmin); - ty = plP_w3wcy(xmin, ymax, zmin); - ux = plP_w3wcx(xmin, ymin, zmin); - uy = plP_w3wcy(xmin, ymin, zmin); - plxybx(yopt, ylabel, tx, ty, ux, uy, - ymax, ymin, ytick, nsuby, ln, &ydigits); - - dx = ux - tx; - dy = uy - ty; -/* restore zdigits to initial value for second call */ - zdigits = zdigmax; - plzbx(zopt, zlabel, 0, dx, dy, tx, ty, - plP_w3wcy(xmin, ymax, zmax), zmin, zmax, ztick, nsubz, &zdigits); - } - else if (cxx <= 0.0 && cxy <= 0.0) { - ln = plP_stsearch(yopt, 'n'); - tx = plP_w3wcx(xmin, ymax, zmin); - ty = plP_w3wcy(xmin, ymax, zmin); - ux = plP_w3wcx(xmin, ymin, zmin); - uy = plP_w3wcy(xmin, ymin, zmin); - plxybx(yopt, ylabel, tx, ty, ux, uy, - ymax, ymin, ytick, nsuby, 0, &ydigits); - - dx = ux - tx; - dy = uy - ty; - plzbx(zopt, zlabel, 1, dx, dy, ux, uy, - plP_w3wcy(xmin, ymin, zmax), zmin, zmax, ztick, nsubz, &zdigits); - - tx = plP_w3wcx(xmax, ymax, zmin); - ty = plP_w3wcy(xmax, ymax, zmin); - ux = plP_w3wcx(xmin, ymax, zmin); - uy = plP_w3wcy(xmin, ymax, zmin); - plxybx(xopt, xlabel, tx, ty, ux, uy, - xmax, xmin, xtick, nsubx, ln, &xdigits); - - dx = ux - tx; - dy = uy - ty; -/* restore zdigits to initial value for second call */ - zdigits = zdigmax; - plzbx(zopt, zlabel, 0, dx, dy, tx, ty, - plP_w3wcy(xmax, ymax, zmax), zmin, zmax, ztick, nsubz, &zdigits); - } - else if (cxx <= 0.0 && cxy >= 0.0) { - ln = plP_stsearch(xopt, 'n'); - tx = plP_w3wcx(xmax, ymax, zmin); - ty = plP_w3wcy(xmax, ymax, zmin); - ux = plP_w3wcx(xmin, ymax, zmin); - uy = plP_w3wcy(xmin, ymax, zmin); - plxybx(xopt, xlabel, tx, ty, ux, uy, - xmax, xmin, xtick, nsubx, 0, &xdigits); - - dx = ux - tx; - dy = uy - ty; - plzbx(zopt, zlabel, 1, dx, dy, ux, uy, - plP_w3wcy(xmin, ymax, zmax), zmin, zmax, ztick, nsubz, &zdigits); - - tx = plP_w3wcx(xmax, ymin, zmin); - ty = plP_w3wcy(xmax, ymin, zmin); - ux = plP_w3wcx(xmax, ymax, zmin); - uy = plP_w3wcy(xmax, ymax, zmin); - plxybx(yopt, ylabel, tx, ty, ux, uy, - ymin, ymax, ytick, nsuby, ln, &ydigits); - - dx = ux - tx; - dy = uy - ty; -/* restore zdigits to initial value for second call */ - zdigits = zdigmax; - plzbx(zopt, zlabel, 0, dx, dy, tx, ty, - plP_w3wcy(xmax, ymin, zmax), zmin, zmax, ztick, nsubz, &zdigits); - } - else if (cxx >= 0.0 && cxy >= 0.0) { - ln = plP_stsearch(yopt, 'n'); - tx = plP_w3wcx(xmax, ymin, zmin); - ty = plP_w3wcy(xmax, ymin, zmin); - ux = plP_w3wcx(xmax, ymax, zmin); - uy = plP_w3wcy(xmax, ymax, zmin); - plxybx(yopt, ylabel, tx, ty, ux, uy, - ymin, ymax, ytick, nsuby, 0, &ydigits); - - dx = ux - tx; - dy = uy - ty; - plzbx(zopt, zlabel, 1, dx, dy, ux, uy, - plP_w3wcy(xmax, ymax, zmax), zmin, zmax, ztick, nsubz, &zdigits); - - tx = plP_w3wcx(xmin, ymin, zmin); - ty = plP_w3wcy(xmin, ymin, zmin); - ux = plP_w3wcx(xmax, ymin, zmin); - uy = plP_w3wcy(xmax, ymin, zmin); - plxybx(xopt, xlabel, tx, ty, ux, uy, - xmin, xmax, xtick, nsubx, ln, &xdigits); - - dx = ux - tx; - dy = uy - ty; -/* restore zdigits to initial value for second call */ - zdigits = zdigmax; - plzbx(zopt, zlabel, 0, dx, dy, tx, ty, - plP_w3wcy(xmin, ymin, zmax), zmin, zmax, ztick, nsubz, &zdigits); - } - plsxax(xdigmax, xdigits); - plsyax(ydigmax, ydigits); - plszax(zdigmax, zdigits); -} - -/*--------------------------------------------------------------------------*\ - * Support routines for 3d box draw. -\*--------------------------------------------------------------------------*/ - -/*--------------------------------------------------------------------------*\ - * void plxybx() - * - * This draws a sloping line from (wx1,wy1) to (wx2,wy2) which represents an - * axis of a 3-d graph with data values from "vmin" to "vmax". Depending on - * "opt", vertical ticks and/or subticks are placed on the line at major tick - * interval "tick" with "nsub" subticks between major ticks. If "tick" and/or - * "nsub" is zero, automatic tick positions are computed - * - * b: Draw box boundary - * f: Always use fixed point numeric labels - * i: Inverts tick marks (i.e. drawn downwards) - * l: Logarithmic axes, major ticks at decades, minor ticks at units - * n: Write numeric label - * t: Draw major tick marks - * s: Draw minor tick marks - * u: Write label on line -\*--------------------------------------------------------------------------*/ - -static void -plxybx(const char *opt, const char *label, PLFLT wx1, PLFLT wy1, - PLFLT wx2, PLFLT wy2, PLFLT vmin_in, PLFLT vmax_in, - PLFLT tick, PLINT nsub, PLINT nolast, PLINT *digits) -{ - static char string[40]; - PLINT lb, lf, li, ll, ln, ls, lt, lu; - PLINT major, minor, mode, prec, scale; - PLINT i, i1, i2, i3, i4; - PLINT nsub1; - PLFLT pos, tn, tp, temp, height, tick1, vmin, vmax; -/* Note that 'tspace' is the minimim distance away (in fractional number - * of ticks) from the boundary that an X or Y numerical label can be drawn. */ - PLFLT dwx, dwy, lambda, tcrit, tspace = 0.1; - - vmin = (vmax_in > vmin_in) ? vmin_in : vmax_in; - vmax = (vmax_in > vmin_in) ? vmax_in : vmin_in; - - dwx = wx2 - wx1; - dwy = wy2 - wy1; - -/* Tick and subtick sizes in device coords */ - - major = MAX(ROUND(plsc->majht * plsc->ypmm), 1); - minor = MAX(ROUND(plsc->minht * plsc->ypmm), 1); - - tick1 = tick; - nsub1 = nsub; - - lb = plP_stsearch(opt, 'b'); - lf = plP_stsearch(opt, 'f'); - li = plP_stsearch(opt, 'i'); - ll = plP_stsearch(opt, 'l'); - ln = plP_stsearch(opt, 'n'); - ls = plP_stsearch(opt, 's'); - lt = plP_stsearch(opt, 't'); - lu = plP_stsearch(opt, 'u'); - - if (lu) - plxytx(wx1, wy1, wx2, wy2, 3.2, 0.5, 0.5, label); - if (!lb) - return; - - if (ll) - tick1 = (vmax > vmin) ? 1.0 : -1.0 ; - if (lt) - pldtik(vmin, vmax, &tick1, &nsub1); - - if (li) { - i1 = minor; - i2 = 0; - i3 = major; - i4 = 0; - } - else { - i1 = 0; - i2 = minor; - i3 = 0; - i4 = major; - } - -/* Draw the line */ - - plP_movwor(wx1, wy1); - if (lt) { - tp = tick1 * floor(vmin / tick1); - for (;;) { - tn = tp + tick1; - if (ls) { - if (ll) { - for (i = 0; i <= 7; i++) { - temp = tp + xlog[i]; - if (BETW(temp, vmin, vmax)) { - lambda = (vmax_in > vmin_in)? - (temp - vmin) / (vmax - vmin): - (vmax - temp) / (vmax - vmin); - plxtik(plP_wcpcx((PLFLT) (wx1 + lambda * dwx)), - plP_wcpcy((PLFLT) (wy1 + lambda * dwy)), - i1, i2); - } - } - } - else { - for (i = 1; i <= nsub1 - 1; i++) { - temp = tp + i * (tn - tp) / nsub1; - if (BETW(temp, vmin, vmax)) { - lambda = (vmax_in > vmin_in)? - (temp - vmin) / (vmax - vmin): - (vmax - temp) / (vmax - vmin); - plxtik(plP_wcpcx((PLFLT) (wx1 + lambda * dwx)), - plP_wcpcy((PLFLT) (wy1 + lambda * dwy)), - i1, i2); - } - } - } - } - temp = tn; - if (!BETW(temp, vmin, vmax)) - break; - - lambda = (vmax_in > vmin_in)? - (temp - vmin) / (vmax - vmin): - (vmax - temp) / (vmax - vmin); - plxtik(plP_wcpcx((PLFLT) (wx1 + lambda * dwx)), - plP_wcpcy((PLFLT) (wy1 + lambda * dwy)), i3, i4); - tp = tn; - } - } - - plP_drawor(wx2, wy2); - -/* Label the line */ - - if (ln && lt) { - pldprec(vmin, vmax, tick1, lf, &mode, &prec, *digits, &scale); - pos = 1.0; - height = 3.2; - tcrit = tspace*tick1; - tp = tick1 * (1. + floor(vmin / tick1)); - for (tn = tp; BETW(tn, vmin, vmax); tn += tick1) { - if(BETW(tn, vmin+tcrit, vmax-tcrit)) { - plform(tn, scale, prec, string, ll, lf); - pos = (vmax_in > vmin_in)? - (tn - vmin) / (vmax - vmin): - (vmax - tn) / (vmax - vmin); - plxytx(wx1, wy1, wx2, wy2, 1.5, pos, 0.5, string); - } - } - *digits = 2; - if (!ll && mode) { - sprintf(string, "(x10#u%d#d)", (int) scale); - plxytx(wx1, wy1, wx2, wy2, height, 1.0, 0.5, string); - } - } -} - -/*--------------------------------------------------------------------------*\ - * void plxytx() - * - * Prints out text along a sloping axis joining world coordinates - * (wx1,wy1) to (wx2,wy2). Parameters are as for plmtext. -\*--------------------------------------------------------------------------*/ - -static void -plxytx(PLFLT wx1, PLFLT wy1, PLFLT wx2, PLFLT wy2, - PLFLT disp, PLFLT pos, PLFLT just, const char *text) -{ - PLINT x, y, refx, refy; - PLFLT shift, cc, ss, wx, wy; - PLFLT xdv, ydv, xmm, ymm, refxmm, refymm, xform[4], diag; - PLFLT dispx, dispy; - PLFLT chrdef, chrht; - - cc = plsc->wmxscl * (wx2 - wx1); - ss = plsc->wmyscl * (wy2 - wy1); - diag = sqrt(cc * cc + ss * ss); - cc /= diag; - ss /= diag; - wx = wx1 + pos * (wx2 - wx1); - wy = wy1 + pos * (wy2 - wy1); - - xform[0] = cc; - xform[1] = 0.0; - xform[2] = ss; - xform[3] = 1.0; - - xdv = plP_wcdcx(wx); - ydv = plP_wcdcy(wy); - - dispx = 0.; - dispy = -disp; - - plgchr(&chrdef, &chrht); - shift = (just == 0.0) ? 0.0 : plstrl(text) * just; - - xmm = plP_dcmmx(xdv) + dispx * chrht; - ymm = plP_dcmmy(ydv) + dispy * chrht; - refxmm = xmm - shift * xform[0]; - refymm = ymm - shift * xform[2]; - - x = plP_mmpcx(xmm); - y = plP_mmpcy(ymm); - refx = plP_mmpcx(refxmm); - refy = plP_mmpcy(refymm); - - plP_text(0, just, xform, x, y, refx, refy, text); -} - -/*--------------------------------------------------------------------------*\ - * void plzbx() - * - * This draws a vertical line from (wx,wy1) to (wx,wy2) which represents the - * vertical axis of a 3-d graph with data values from "vmin" to "vmax". - * Depending on "opt", ticks and/or subticks are placed on the line at major - * tick interval "tick" with "nsub" subticks between major ticks. If "tick" - * and/or "nsub" is zero, automatic tick positions are computed - * - * b: Draws left-hand axis - * c: Draws right-hand axis - * f: Always use fixed point numeric labels - * i: Inverts tick marks (i.e. drawn to the left) - * l: Logarithmic axes, major ticks at decades, minor ticks at units - * m: Write numeric label on right axis - * n: Write numeric label on left axis - * s: Draw minor tick marks - * t: Draw major tick marks - * u: Writes left-hand label - * v: Writes right-hand label -\*--------------------------------------------------------------------------*/ - -static void -plzbx(const char *opt, const char *label, PLINT right, PLFLT dx, PLFLT dy, - PLFLT wx, PLFLT wy1, PLFLT wy2, PLFLT vmin_in, PLFLT vmax_in, - PLFLT tick, PLINT nsub, PLINT *digits) -{ - static char string[40]; - PLINT lb, lc, lf, li, ll, lm, ln, ls, lt, lu, lv; - PLINT i, mode, prec, scale; - PLINT nsub1, lstring; - PLFLT pos, tn, tp, temp, height, tick1; - PLFLT dwy, lambda, diag, major, minor, xmajor, xminor; - PLFLT ymajor, yminor, dxm, dym, vmin, vmax; - - vmin = (vmax_in > vmin_in) ? vmin_in : vmax_in; - vmax = (vmax_in > vmin_in) ? vmax_in : vmin_in; - - dwy = wy2 - wy1; - -/* Tick and subtick sizes in device coords */ - - major = plsc->majht; - minor = plsc->minht; - - tick1 = tick; - nsub1 = nsub; - - lb = plP_stsearch(opt, 'b'); - lc = plP_stsearch(opt, 'c'); - lf = plP_stsearch(opt, 'f'); - li = plP_stsearch(opt, 'i'); - ll = plP_stsearch(opt, 'l'); - lm = plP_stsearch(opt, 'm'); - ln = plP_stsearch(opt, 'n'); - ls = plP_stsearch(opt, 's'); - lt = plP_stsearch(opt, 't'); - lu = plP_stsearch(opt, 'u'); - lv = plP_stsearch(opt, 'v'); - - if (lu && !right) - plztx("h", dx, dy, wx, wy1, wy2, 5.0, 0.5, 0.5, label); - - if (lv && right) - plztx("h", dx, dy, wx, wy1, wy2, -5.0, 0.5, 0.5, label); - - if (right && !lc) - return; - - if (!right && !lb) - return; - - if (ll) - tick1 = 1.0; - - if (lt) - pldtik(vmin, vmax, &tick1, &nsub1); - - if ((li && !right) || (!li && right)) { - minor = -minor; - major = -major; - } - - dxm = dx * plsc->wmxscl; - dym = dy * plsc->wmyscl; - diag = sqrt(dxm * dxm + dym * dym); - - xminor = minor * dxm / diag; - xmajor = major * dxm / diag; - yminor = minor * dym / diag; - ymajor = major * dym / diag; - -/* Draw the line */ - - plP_movwor(wx, wy1); - if (lt) { - tp = tick1 * floor(vmin / tick1); - for (;;) { - tn = tp + tick1; - if (ls) { - if (ll) { - for (i = 0; i <= 7; i++) { - temp = tp + xlog[i]; - if (BETW(temp, vmin, vmax)) { - lambda = (vmax_in > vmin_in)? - (temp - vmin) / (vmax - vmin): - (vmax - temp) / (vmax - vmin); - plstik(plP_wcmmx(wx), - plP_wcmmy((PLFLT) (wy1 + lambda * dwy)), - xminor, yminor); - } - } - } - else { - for (i = 1; i <= nsub1 - 1; i++) { - temp = tp + i * tick1 / nsub1; - if (BETW(temp, vmin, vmax)) { - lambda = (vmax_in > vmin_in)? - (temp - vmin) / (vmax - vmin): - (vmax - temp) / (vmax - vmin); - plstik(plP_wcmmx(wx), - plP_wcmmy((PLFLT) (wy1 + lambda * dwy)), - xminor, yminor); - } - } - } - } - temp = tn; - if (!BETW(temp, vmin, vmax)) - break; - lambda = (vmax_in > vmin_in)? - (temp - vmin) / (vmax - vmin): - (vmax - temp) / (vmax - vmin); - plstik(plP_wcmmx(wx), plP_wcmmy((PLFLT) (wy1 + lambda * dwy)), - xmajor, ymajor); - tp = tn; - } - } - - plP_drawor(wx, wy2); - -/* Label the line */ - - if ((ln || lm) && lt) { - pldprec(vmin, vmax, tick1, lf, &mode, &prec, *digits, &scale); - *digits = 0; - tp = tick1 * floor(vmin / tick1); - for (tn = tp + tick1; BETW(tn, vmin, vmax); tn += tick1) { - plform(tn, scale, prec, string, ll, lf); - pos = (vmax_in > vmin_in)? - (tn - vmin) / (vmax - vmin): - (vmax - tn) / (vmax - vmin); - if (ln && !right) - plztx("v", dx, dy, wx, wy1, wy2, 0.5, pos, 1.0, string); - - if (lm && right) - plztx("v", dx, dy, wx, wy1, wy2, -0.5, pos, 0.0, string); - - lstring = strlen(string); - *digits = MAX(*digits, lstring); - } - if (!ll && mode) { - sprintf(string, "(x10#u%d#d)", (int) scale); - pos = 1.15; - height = 0.5; - if (ln && !right) { - plztx("v", dx, dy, wx, wy1, wy2, height, pos, 0.5, string); - } - if (lm && right) { - plztx("v", dx, dy, wx, wy1, wy2, - (PLFLT) -height, pos, 0.5, string); - } - } - } -} - -/*--------------------------------------------------------------------------*\ - * void plztx() - * - * Prints out text along a vertical axis for a 3d plot joining - * world coordinates (wx,wy1) to (wx,wy2). -\*--------------------------------------------------------------------------*/ - -static void -plztx(const char *opt, PLFLT dx, PLFLT dy, PLFLT wx, PLFLT wy1, - PLFLT wy2, PLFLT disp, PLFLT pos, PLFLT just, const char *text) -{ - PLINT refx = 0, refy = 0, x = 0, y = 0, vert = 0; - PLFLT shift, cc, ss, wy; - PLFLT xdv, ydv, xmm, ymm, refxmm, refymm, xform[4], diag; - PLFLT dispx, dispy; - PLFLT chrdef, chrht; - - cc = plsc->wmxscl * dx; - ss = plsc->wmyscl * dy; - diag = sqrt(cc * cc + ss * ss); - cc /= diag; - ss /= diag; - wy = wy1 + pos * (wy2 - wy1); - - if (plP_stsearch(opt, 'v')) - vert = 0; - else if (plP_stsearch(opt, 'h')) - vert = 1; - - if (vert) { - xform[0] = 0.0; - xform[1] = -cc; - xform[2] = 1.0; - xform[3] = -ss; - } else { - xform[0] = cc; - xform[1] = 0.0; - xform[2] = ss; - xform[3] = 1.0; - } - - xdv = plP_wcdcx(wx); - ydv = plP_wcdcy(wy); - - dispx = -disp * cc; - dispy = -disp * ss; - - plgchr(&chrdef, &chrht); - shift = (just == 0.0) ? 0.0 : plstrl(text) * just; - - xmm = plP_dcmmx(xdv) + dispx * chrht; - ymm = plP_dcmmy(ydv) + dispy * chrht; - refxmm = xmm - shift * xform[0]; - refymm = ymm - shift * xform[2]; - - x = plP_mmpcx(xmm); - y = plP_mmpcy(ymm); - refx = plP_mmpcx(refxmm); - refy = plP_mmpcy(refymm); - - plP_text(0, just, xform, x, y, refx, refy, text); -} - -/*--------------------------------------------------------------------------*\ - * void grid_box() - * - * Draws grids at tick locations (major and/or minor). - * - * Note that 'tspace' is the minimim distance away (in fractional number - * of ticks or subticks) from the boundary a grid line can be drawn. If - * you are too close, it looks bad. -\*--------------------------------------------------------------------------*/ - -static void -grid_box(const char *xopt, PLFLT xtick1, PLINT nxsub1, - const char *yopt, PLFLT ytick1, PLINT nysub1) -{ - PLINT lgx, lhx, llx; - PLINT lgy, lhy, lly; - PLFLT vpwxmi, vpwxma, vpwymi, vpwyma; - PLFLT vpwxmin, vpwxmax, vpwymin, vpwymax; - PLFLT tn, temp, tcrit, tspace = 0.1; - PLINT i; - -/* Set plot options from input */ - - lgx = plP_stsearch(xopt, 'g'); - lhx = plP_stsearch(xopt, 'h'); - llx = plP_stsearch(xopt, 'l'); - - lgy = plP_stsearch(yopt, 'g'); - lhy = plP_stsearch(yopt, 'h'); - lly = plP_stsearch(yopt, 'l'); - - plgvpw(&vpwxmin, &vpwxmax, &vpwymin, &vpwymax); -/* n.b. large change; vpwxmi always numerically less than vpwxma, and - * similarly for vpwymi */ - vpwxmi = (vpwxmax > vpwxmin) ? vpwxmin : vpwxmax; - vpwxma = (vpwxmax > vpwxmin) ? vpwxmax : vpwxmin; - vpwymi = (vpwymax > vpwymin) ? vpwymin : vpwymax; - vpwyma = (vpwymax > vpwymin) ? vpwymax : vpwymin; - -/* Draw grid in x direction. */ - - if (lgx) { - for (tn = xtick1 * floor(vpwxmi/xtick1); - tn <= vpwxma; tn += xtick1) { - if (lhx) { - if (llx) { - PLFLT otemp = tn; - for (i = 0; i <= 7; i++) { - temp = tn + xlog[i]; - tcrit = (temp - otemp)*tspace; - otemp = temp; - if (BETW(temp, vpwxmi+tcrit, vpwxma-tcrit)) - pljoin(temp, vpwymi, temp, vpwyma); - } - } - else { - for (i = 1; i <= nxsub1 - 1; i++) { - temp = tn + i * xtick1 / nxsub1; - tcrit = xtick1 / nxsub1 * tspace; - if (BETW(temp, vpwxmi+tcrit, vpwxma-tcrit)) - pljoin(temp, vpwymi, temp, vpwyma); - } - } - } - tcrit = xtick1*tspace; - if (BETW(tn, vpwxmi+tcrit, vpwxma-tcrit)) - pljoin(tn, vpwymi, tn, vpwyma); - } - } - -/* Draw grid in y direction */ - - if (lgy) { - tn = ytick1 * floor(vpwymi / ytick1 + tspace); - for (tn = ytick1 * floor(vpwymi/ytick1); - tn <= vpwyma; tn += ytick1) { - if (lhy) { - if (lly) { - PLFLT otemp = tn; - for (i = 0; i <= 7; i++) { - temp = tn + xlog[i]; - tcrit = (temp - otemp)*tspace; - otemp = temp; - if (BETW(temp, vpwymi+tcrit, vpwyma-tcrit)) - pljoin(vpwxmi, temp, vpwxma, temp); - } - } - else { - for (i = 1; i <= nysub1 - 1; i++) { - temp = tn + i * ytick1 / nysub1; - tcrit = ytick1 / nysub1 * tspace; - if (BETW(temp, vpwymi+tcrit, vpwyma-tcrit)) - pljoin(vpwxmi, temp, vpwxma, temp); - } - } - } - tcrit = ytick1*tspace; - if (BETW(tn, vpwymi+tcrit, vpwyma-tcrit)) - pljoin(vpwxmi, tn, vpwxma, tn); - } - } -} - -/*--------------------------------------------------------------------------*\ - * void label_box() - * - * Writes numeric labels on side(s) of box. -\*--------------------------------------------------------------------------*/ - -static void -label_box(const char *xopt, PLFLT xtick1, const char *yopt, PLFLT ytick1) -{ - static char string[40]; - PLINT lfx, lix, llx, lmx, lnx, ltx; - PLINT lfy, liy, lly, lmy, lny, lty, lvy; - PLFLT vpwxmi, vpwxma, vpwymi, vpwyma; - PLFLT vpwxmin, vpwxmax, vpwymin, vpwymax; - PLFLT pos, tn, tp, offset, height; - -/* Set plot options from input */ - - lfx = plP_stsearch(xopt, 'f'); - lix = plP_stsearch(xopt, 'i'); - llx = plP_stsearch(xopt, 'l'); - lmx = plP_stsearch(xopt, 'm'); - lnx = plP_stsearch(xopt, 'n'); - ltx = plP_stsearch(xopt, 't'); - - lfy = plP_stsearch(yopt, 'f'); - liy = plP_stsearch(yopt, 'i'); - lly = plP_stsearch(yopt, 'l'); - lmy = plP_stsearch(yopt, 'm'); - lny = plP_stsearch(yopt, 'n'); - lty = plP_stsearch(yopt, 't'); - lvy = plP_stsearch(yopt, 'v'); - - plgvpw(&vpwxmin, &vpwxmax, &vpwymin, &vpwymax); -/* n.b. large change; vpwxmi always numerically less than vpwxma, and - * similarly for vpwymi */ - vpwxmi = (vpwxmax > vpwxmin) ? vpwxmin : vpwxmax; - vpwxma = (vpwxmax > vpwxmin) ? vpwxmax : vpwxmin; - vpwymi = (vpwymax > vpwymin) ? vpwymin : vpwymax; - vpwyma = (vpwymax > vpwymin) ? vpwymax : vpwymin; - -/* Write horizontal label(s) */ - - if ((lmx || lnx) && ltx) { - PLINT xmode, xprec, xdigmax, xdigits, xscale; - - plgxax(&xdigmax, &xdigits); - pldprec(vpwxmi, vpwxma, xtick1, lfx, &xmode, &xprec, xdigmax, &xscale); - - tp = xtick1 * (1. + floor(vpwxmi / xtick1)); - for (tn = tp; BETW(tn, vpwxmi, vpwxma); tn += xtick1) { - plform(tn, xscale, xprec, string, llx, lfx); - height = lix ? 1.75 : 1.5; - pos = (vpwxmax > vpwxmin)? - (tn - vpwxmi) / (vpwxma - vpwxmi): - (vpwxma - tn) / (vpwxma - vpwxmi); - if (lnx) - plmtex("b", height, pos, 0.5, string); - if (lmx) - plmtex("t", height, pos, 0.5, string); - } - xdigits = 2; - plsxax(xdigmax, xdigits); - - /* Write separate exponential label if mode = 1. */ - - if (!llx && xmode) { - pos = 1.0; - height = 3.2; - sprintf(string, "(x10#u%d#d)", (int) xscale); - if (lnx) - plmtex("b", height, pos, 0.5, string); - if (lmx) - plmtex("t", height, pos, 0.5, string); - } - } - -/* Write vertical label(s) */ - - if ((lmy || lny) && lty) { - PLINT ymode, yprec, ydigmax, ydigits, yscale; - - plgyax(&ydigmax, &ydigits); - pldprec(vpwymi, vpwyma, ytick1, lfy, &ymode, &yprec, ydigmax, &yscale); - - ydigits = 0; - tp = ytick1 * (1. + floor(vpwymi / ytick1)); - for (tn = tp; BETW(tn, vpwymi, vpwyma); tn += ytick1) { - plform(tn, yscale, yprec, string, lly, lfy); - pos = (vpwymax > vpwymin)? - (tn - vpwymi) / (vpwyma - vpwymi): - (vpwyma - tn) / (vpwyma - vpwymi); - if (lny) { - if (lvy) { - height = liy ? 1.0 : 0.5; - plmtex("lv", height, pos, 1.0, string); - } else { - height = liy ? 1.75 : 1.5; - plmtex("l", height, pos, 0.5, string); - } - } - if (lmy) { - if (lvy) { - height = liy ? 1.0 : 0.5; - plmtex("rv", height, pos, 0.0, string); - } else { - height = liy ? 1.75 : 1.5; - plmtex("r", height, pos, 0.5, string); - } - } - ydigits = MAX(ydigits, strlen(string)); - } - if (!lvy) - ydigits = 2; - - plsyax(ydigmax, ydigits); - - /* Write separate exponential label if mode = 1. */ - - if (!lly && ymode) { - sprintf(string, "(x10#u%d#d)", (int) yscale); - offset = 0.02; - height = 2.0; - if (lny) { - pos = 0.0 - offset; - plmtex("t", height, pos, 1.0, string); - } - if (lmy) { - pos = 1.0 + offset; - plmtex("t", height, pos, 0.0, string); - } - } - } -} - -/*--------------------------------------------------------------------------*\ - * void plform() - * - * Formats a PLFLT value in one of the following formats. - * - * If ll (logarithmic), then: - * - * - If lf (fixed), then used fixed point notation, i.e. .1, 1, 10, etc, - * with unnecessary trailing .'s or 0's removed. - * - * - If !lf (default), then use exponential notation, i.e. 10^-1, etc. - * - * If !ll (linear), then: - * - * - If scale == 0, use fixed point format with "prec" places after the - * decimal point. - * - * - If scale == 1, use scientific notation with one place before the - * decimal point and "prec" places after. In this case, the value - * must be divided by 10^scale. -\*--------------------------------------------------------------------------*/ - -static void -plform(PLFLT value, PLINT scale, PLINT prec, char *string, PLINT ll, PLINT lf) -{ - if (ll) { - - /* Logarithmic */ - - if (lf) { - - /* Fixed point, i.e. .1, 1, 10, etc */ - - int exponent = ROUND(value); - - value = pow(10.0, exponent); - if (exponent < 0) { - char form[10]; - sprintf(form, "%%.%df", ABS(exponent)); - sprintf(string, form, value); - } - else { - sprintf(string, "%d", (int) value); - } - } - else { - - /* Exponential, i.e. 10^-1, 10^0, 10^1, etc */ - - sprintf(string, "10#u%d", (int) ROUND(value)); - } - } - else { - - /* Linear */ - - PLINT setpre, precis; - char form[10], temp[30]; - double scale2; - - plP_gprec(&setpre, &precis); - - if (setpre) - prec = precis; - - if (scale) - value /= pow(10.,(double)scale); - - /* This is necessary to prevent labels like "-0.0" on some systems */ - - scale2 = pow(10., prec); - value = floor((value * scale2) + .5) / scale2; - - sprintf(form, "%%.%df", (int) prec); - sprintf(temp, form, value); - strcpy(string, temp); - } -} diff --git a/src/plot/plplot/plbuf.c b/src/plot/plplot/plbuf.c deleted file mode 100644 index ffe50adebd..0000000000 --- a/src/plot/plplot/plbuf.c +++ /dev/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 - -/* 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); -} diff --git a/src/plot/plplot/plcdemos.h b/src/plot/plplot/plcdemos.h deleted file mode 100644 index 1891cd1756..0000000000 --- a/src/plot/plplot/plcdemos.h +++ /dev/null @@ -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 -#include -#include - -/* 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__ */ diff --git a/src/plot/plplot/plcont.c b/src/plot/plplot/plcont.c deleted file mode 100644 index e05846c021..0000000000 --- a/src/plot/plplot/plcont.c +++ /dev/null @@ -1,1296 +0,0 @@ -/* $Id: plcont.c,v 1.4 2005/03/17 21:39:21 eli Exp $ - - Contour plotter. -*/ - -#include - -#include "plplotP.h" - -#ifdef MSDOS -#pragma optimize("",off) -#endif - -/* Static function prototypes. */ - -static void -plcntr(PLFLT (*plf2eval) (PLINT, PLINT, PLPointer), - PLPointer plf2eval_data, - PLINT nx, PLINT ny, PLINT kx, PLINT lx, - PLINT ky, PLINT ly, PLFLT flev, PLINT *iscan, - PLINT *ixstor, PLINT *iystor, PLINT nstor, - void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), - PLPointer pltr_data); - -static void -pldrawcn(PLFLT (*plf2eval) (PLINT, PLINT, PLPointer), - PLPointer plf2eval_data, - PLINT nx, PLINT ny, PLINT kx, PLINT lx, - PLINT ky, PLINT ly, PLFLT flev, char *flabel, PLINT kcol, PLINT krow, - PLINT *p_kscan, PLINT *p_kstor, PLINT *iscan, - PLINT *ixstor, PLINT *iystor, PLINT nstor, - void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), - PLPointer pltr_data); - -static void -plccal(PLFLT (*plf2eval) (PLINT, PLINT, PLPointer), - PLPointer plf2eval_data, - PLFLT flev, PLINT ix, PLINT iy, - PLINT ixg, PLINT iyg, PLFLT *dist); - -static void -plr45 (PLINT *ix, PLINT *iy, PLINT isens); - -static void -plr135 (PLINT *ix, PLINT *iy, PLINT isens); - -static void -plfloatlabel(PLFLT value, char *string); - -static PLFLT -plP_pcwcx(PLINT x); - -static PLFLT -plP_pcwcy(PLINT y); - -static void -pl_drawcontlabel(PLFLT tpx, PLFLT tpy, char *flabel, PLFLT *distance, PLINT *lastindex); - -/* Error flag for aborts */ - -static int error; - -/****************************************/ -/* */ -/* Defaults for contour label printing. */ -/* */ -/****************************************/ - -/* Font height for contour labels (normalized) */ -static PLFLT -contlabel_size = 0.3; - -/* Offset of label from contour line (if set to 0.0, labels are printed on the lines). */ -static PLFLT -contlabel_offset = 0.006; - -/* Spacing parameter for contour labels */ -static PLFLT -contlabel_space = 0.1; - -/* Activate labels, default off */ -static PLINT -contlabel_active = 0; - -/* If the contour label exceed 10^(limexp) or 10^(-limexp), the exponential format is used */ -static PLINT -limexp = 4; - -/* Number of significant digits */ -static PLINT -sigprec = 2; - -/******** contour lines storage ****************************/ - -static CONT_LEVEL *startlev = NULL; -static CONT_LEVEL *currlev; -static CONT_LINE *currline; - -static int cont3d = 0; - -static CONT_LINE * -alloc_line(CONT_LEVEL *node) -{ - CONT_LINE *line; - - line = (CONT_LINE *) malloc(sizeof(CONT_LINE)); - line->x = (PLFLT *) malloc(LINE_ITEMS*sizeof(PLFLT)); - line->y = (PLFLT *) malloc(LINE_ITEMS*sizeof(PLFLT)); - line->npts = 0; - line->next = NULL; - - return line; -} - -static CONT_LEVEL * -alloc_level(PLFLT level) -{ - CONT_LEVEL *node; - - node = (CONT_LEVEL *) malloc(sizeof(CONT_LEVEL)); - node->level = level; - node->next = NULL; - node->line = alloc_line(node); - - return node; -} - -static void -realloc_line(CONT_LINE *line) -{ - line->x = (PLFLT *) realloc(line->x, - (line->npts + LINE_ITEMS)*sizeof(PLFLT)); - line->y = (PLFLT *) realloc(line->y, - (line->npts + LINE_ITEMS)*sizeof(PLFLT)); -} - - -/* new contour level */ -static void -cont_new_store(PLFLT level) -{ - if (cont3d) { - if (startlev == NULL) { - startlev = alloc_level(level); - currlev = startlev; - } else { - currlev->next = alloc_level(level); - currlev = currlev->next; - } - currline = currlev->line; - } -} - -void -cont_clean_store(CONT_LEVEL *ct) -{ - CONT_LINE *tline, *cline; - CONT_LEVEL *tlev, *clevel; - - if (ct != NULL) { - clevel = ct; - - do { - cline = clevel->line; - do { -#ifdef CONT_PLOT_DEBUG /* for 2D plots. For 3D plots look at plot3.c:plotsh3di() */ - plP_movwor(cline->x[0],cline->y[0]); - for (j=1; jnpts; j++) - plP_drawor(cline->x[j], cline->y[j]); -#endif - tline = cline->next; - free(cline->x); - free(cline->y); - free(cline); - cline = tline; - } - while(cline != NULL); - tlev = clevel->next; - free(clevel); - clevel = tlev; - } - while(clevel != NULL); - startlev = NULL; - } -} - -static void -cont_xy_store(PLFLT xx, PLFLT yy) -{ - if (cont3d) { - PLINT pts = currline->npts; - - if (pts % LINE_ITEMS == 0) - realloc_line(currline); - - currline->x[pts] = xx; - currline->y[pts] = yy; - currline->npts++; - } else - plP_drawor(xx, yy); -} - -static void -cont_mv_store(PLFLT xx, PLFLT yy) -{ - if (cont3d) { - if (currline->npts != 0) { /* not an empty list, allocate new */ - currline->next = alloc_line(currlev); - currline = currline->next; - } - - /* and fill first element */ - currline->x[0] = xx; - currline->y[0] = yy; - currline->npts = 1; - } else - plP_movwor(xx, yy); -} - -/* small routine to set offset and spacing of contour labels, see desciption above */ -void c_pl_setcontlabelparam(PLFLT offset, PLFLT size, PLFLT spacing, PLINT active) -{ - contlabel_offset = offset; - contlabel_size = size; - contlabel_space = spacing; - contlabel_active = active; -} - -/* small routine to set the format of the contour labels, description of limexp and prec see above */ -void c_pl_setcontlabelformat(PLINT lexp, PLINT sigdig) -{ - limexp = lexp; - sigprec = sigdig; -} - -static void pl_drawcontlabel(PLFLT tpx, PLFLT tpy, char *flabel, PLFLT *distance, PLINT *lastindex) -{ - PLFLT currx_old, curry_old, delta_x, delta_y; - - delta_x = plP_pcdcx(plsc->currx)-plP_pcdcx(plP_wcpcx(tpx)); - delta_y = plP_pcdcy(plsc->curry)-plP_pcdcy(plP_wcpcy(tpy)); - - currx_old = plsc->currx; - curry_old = plsc->curry; - - *distance += sqrt(delta_x*delta_x + delta_y*delta_y); - - plP_drawor(tpx, tpy); - - if ((int )(fabs(*distance/contlabel_space)) > *lastindex) { - PLFLT scale, vec_x, vec_y, mx, my, dev_x, dev_y, off_x, off_y; - - vec_x = tpx-plP_pcwcx(currx_old); - vec_y = tpy-plP_pcwcy(curry_old); - - mx = (double )plsc->wpxscl/(double )plsc->phyxlen; - my = (double )plsc->wpyscl/(double )plsc->phyylen; - - dev_x = -my*vec_y/mx; - dev_y = mx*vec_x/my; - - scale = sqrt((mx*mx*dev_x*dev_x + my*my*dev_y*dev_y)/ - (contlabel_offset*contlabel_offset)); - - off_x = dev_x/scale; - off_y = dev_y/scale; - - plptex(tpx+off_x, tpy+off_y, vec_x, vec_y, 0.5, flabel); - plP_movwor(tpx, tpy); - (*lastindex)++; - - } else - plP_movwor(tpx, tpy); -} - - -/* Format contour labels. Arguments: - * value: floating point number to be formatted - * string: the formatted label, plptex must be called with it to actually - * print the label - */ - -static void plfloatlabel(PLFLT value, char *string) -{ - PLINT setpre, precis; - char form[32], tmpstring[32]; /* PLTSCHEME: used to be size 10, which lead to a buffer overrun */ - PLINT exponent = 0; - PLFLT mant, tmp; - - PLINT prec = sigprec; - - plP_gprec(&setpre, &precis); - - if (setpre) - prec = precis; - - if (value > 0.0) - tmp = log10(value); - else if (value < 0.0) - tmp = log10(-value); - else - tmp = 0; - - if (tmp >= 0.0) - exponent = (int )tmp; - else if (tmp < 0.0) { - tmp = -tmp; - if (floor(tmp) < tmp) - exponent = -(int )(floor(tmp) + 1.0); - else - exponent = -(int )(floor(tmp)); - } - - mant = value/pow(10.0, exponent); - - if (mant != 0.0) - mant = (int )(mant*pow(10.0, prec-1) + 0.5*mant/fabs(mant))/pow(10.0, prec-1); - - sprintf(form, "%%.%df", prec-1); - sprintf(string, form, mant); - /* sprintf(tmpstring, "#(229)10#u%d", exponent); */ - sprintf(tmpstring, "#(229)10#u%d", exponent); - strcat(string, tmpstring); - - if (abs(exponent) < limexp || value == 0.0) { - value = pow(10.0, exponent) * mant; - - if (exponent >= 0) - prec = prec - 1 - exponent; - else - prec = prec - 1 + abs(exponent); - - if (prec < 0) - prec = 0; - - sprintf(form, "%%.%df", (int) prec); - sprintf(string, form, value); - } -} - -/* physical coords (x) to world coords */ - -static PLFLT -plP_pcwcx(PLINT x) -{ - return ((x-plsc->wpxoff)/plsc->wpxscl); -} - -/* physical coords (y) to world coords */ - -static PLFLT -plP_pcwcy(PLINT y) -{ - return ((y-plsc->wpyoff)/plsc->wpyscl); -} - - - -/*--------------------------------------------------------------------------*\ - * plf2eval2() - * - * Does a lookup from a 2d function array. Array is of type (PLFLT **), - * and is column dominant (normal C ordering). -\*--------------------------------------------------------------------------*/ - -PLFLT -plf2eval2(PLINT ix, PLINT iy, PLPointer plf2eval_data) -{ - PLFLT value; - PLfGrid2 *grid = (PLfGrid2 *) plf2eval_data; - - value = grid->f[ix][iy]; - - return value; -} - -/*--------------------------------------------------------------------------*\ - * plf2eval() - * - * Does a lookup from a 2d function array. Array is of type (PLFLT *), and - * is column dominant (normal C ordering). You MUST fill the ny maximum - * array index entry in the PLfGrid struct. -\*--------------------------------------------------------------------------*/ - -PLFLT -plf2eval(PLINT ix, PLINT iy, PLPointer plf2eval_data) -{ - PLFLT value; - PLfGrid *grid = (PLfGrid *) plf2eval_data; - - value = grid->f[ix * grid->ny + iy]; - - return value; -} - -/*--------------------------------------------------------------------------*\ - * plf2evalr() - * - * Does a lookup from a 2d function array. Array is of type (PLFLT *), and - * is row dominant (Fortran ordering). You MUST fill the nx maximum array - * index entry in the PLfGrid struct. -\*--------------------------------------------------------------------------*/ - -PLFLT -plf2evalr(PLINT ix, PLINT iy, PLPointer plf2eval_data) -{ - PLFLT value; - PLfGrid *grid = (PLfGrid *) plf2eval_data; - - value = grid->f[ix + iy * grid->nx]; - - return value; -} - -/*--------------------------------------------------------------------------*\ - * - * cont_store: - * - * Draw contour lines in memory. - * cont_clean_store() must be called after use to release allocated memory. - * -\*--------------------------------------------------------------------------*/ - -void -cont_store(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT kx, PLINT lx, - PLINT ky, PLINT ly, PLFLT *clevel, PLINT nlevel, CONT_LEVEL **contour) -{ - PLcGrid grid1; - - cont3d = 1; - - grid1.nx = nx; grid1.ny = ny; grid1.xg = x; grid1.yg = y; - plcont(z, nx, ny, 1, nx, 1, ny, clevel, nlevel, - pltr1, (void *) & grid1 ); - - *contour = startlev; - cont3d = 0; -} - -/*--------------------------------------------------------------------------*\ - * void plcont() - * - * Draws a contour plot from data in f(nx,ny). Is just a front-end to - * plfcont, with a particular choice for f2eval and f2eval_data. -\*--------------------------------------------------------------------------*/ - -MZ_DLLEXPORT -void -c_plcont(PLFLT **f, PLINT nx, PLINT ny, PLINT kx, PLINT lx, - PLINT ky, PLINT ly, PLFLT *clevel, PLINT nlevel, - void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), - PLPointer pltr_data) -{ - PLfGrid2 grid; - - grid.f = f; - plfcont(plf2eval2, (PLPointer) &grid, - nx, ny, kx, lx, ky, ly, clevel, nlevel, - pltr, pltr_data); -} - -/*--------------------------------------------------------------------------*\ - * void plfcont() - * - * Draws a contour plot using the function evaluator f2eval and data stored - * by way of the f2eval_data pointer. This allows arbitrary organizations - * of 2d array data to be used. - * - * The subrange of indices used for contouring is kx to lx in the x - * direction and from ky to ly in the y direction. The array of contour - * levels is clevel(nlevel), and "pltr" is the name of a function which - * transforms array indices into world coordinates. - * - * Note that the fortran-like minimum and maximum indices (kx, lx, ky, ly) - * are translated into more C-like ones. I've only kept them as they are - * for the plcontf() argument list because of backward compatibility. -\*--------------------------------------------------------------------------*/ - -void -plfcont(PLFLT (*f2eval) (PLINT, PLINT, PLPointer), - PLPointer f2eval_data, - PLINT nx, PLINT ny, PLINT kx, PLINT lx, - PLINT ky, PLINT ly, PLFLT *clevel, PLINT nlevel, - void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), - PLPointer pltr_data) -{ - PLINT i, mx, my, nstor, *heapc; - - mx = lx - kx + 1; - my = ly - ky + 1; - - if (kx < 1 || kx >= lx) { - plabort("plfcont: indices must satisfy 1 <= kx <= lx <= nx"); - return; - } - if (ky < 1 || ky >= ly) { - plabort("plfcont: indices must satisfy 1 <= ky <= ly <= ny"); - return; - } - - nstor = mx * my; - heapc = (PLINT *) malloc((size_t) (2*mx + 10 * nstor) * sizeof(PLINT)); - if (heapc == NULL) { - plabort("plfcont: out of memory in heap allocation"); - return; - } - - for (i = 0; i < nlevel; i++) { - plcntr(f2eval, f2eval_data, - nx, ny, kx-1, lx-1, ky-1, ly-1, clevel[i], &heapc[0], - &heapc[nx], &heapc[nx + nstor], nstor, pltr, pltr_data); - - if (error) { - error = 0; - goto done; - } - } - - done: - free((void *) heapc); -} - -/*--------------------------------------------------------------------------*\ - * void plcntr() - * - * The contour for a given level is drawn here. Note iscan has nx - * elements. ixstor and iystor each have nstor elements. -\*--------------------------------------------------------------------------*/ - -static void -plcntr(PLFLT (*f2eval) (PLINT, PLINT, PLPointer), - PLPointer f2eval_data, - PLINT nx, PLINT ny, PLINT kx, PLINT lx, - PLINT ky, PLINT ly, PLFLT flev, PLINT *iscan, - PLINT *ixstor, PLINT *iystor, PLINT nstor, - void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), - PLPointer pltr_data) -{ - PLINT kcol, krow, kstor, kscan, l, ixt, iyt, jstor, next; - - char flabel[30]; - - cont_new_store(flev); - - /* format contour label for plptex and define the font height of the labels */ - plfloatlabel(flev, flabel); - plschr(0.0, contlabel_size); - - /* Initialize memory pointers */ - - kstor = 0; - kscan = 0; - - for (krow = ky; krow <= ly; krow++) { - for (kcol = kx + 1; kcol <= lx; kcol++) { - - /* Follow and draw a contour */ - - pldrawcn(f2eval, f2eval_data, - nx, ny, kx, lx, ky, ly, flev, flabel, kcol, krow, - &kscan, &kstor, iscan, ixstor, iystor, nstor, - pltr, pltr_data); - - if (error) - return; - } - - /* Search of row complete */ - /* Set up memory of next row in iscan and edit ixstor and iystor */ - - if (krow < ny-1) { - jstor = 0; - kscan = 0; - next = krow + 1; - for (l = 1; l <= kstor; l++) { - ixt = ixstor[l - 1]; - iyt = iystor[l - 1]; - - /* Memory of next row into iscan */ - - if (iyt == next) { - kscan = kscan + 1; - iscan[kscan - 1] = ixt; - } - - /* Retain memory of rows to come, and forget rest */ - - else if (iyt > next) { - jstor = jstor + 1; - ixstor[jstor - 1] = ixt; - iystor[jstor - 1] = iyt; - } - } - kstor = jstor; - } - } - plschr(0.0, 1.0); -} - -/*--------------------------------------------------------------------------*\ - * void pldrawcn() - * - * Follow and draw a contour. -\*--------------------------------------------------------------------------*/ - -static void -pldrawcn(PLFLT (*f2eval) (PLINT, PLINT, PLPointer), - PLPointer f2eval_data, - PLINT nx, PLINT ny, PLINT kx, PLINT lx, - PLINT ky, PLINT ly, PLFLT flev, char *flabel, PLINT kcol, PLINT krow, - PLINT *p_kscan, PLINT *p_kstor, PLINT *iscan, - PLINT *ixstor, PLINT *iystor, PLINT nstor, - void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), - PLPointer pltr_data) -{ - PLINT iwbeg, ixbeg, iybeg, izbeg; - PLINT iboun, iw, ix, iy, iz, ifirst, istep, ixgo, iygo; - PLINT l, ixg, iyg, ia, ib; - - PLFLT dist, dx, dy, xnew, ynew, fxl, fxr; - PLFLT xlas = 0., ylas = 0., tpx, tpy, xt, yt; - PLFLT f1, f2, f3, f4, fcheck; - - PLINT lastindex = 0; - PLFLT distance = 0.0; - -/* Check if a contour has been crossed */ - - fxl = f2eval(kcol-1, krow, f2eval_data); - fxr = f2eval(kcol, krow, f2eval_data); - - if (fxl < flev && fxr >= flev) { - ixbeg = kcol - 1; - iwbeg = kcol; - } - else if (fxr < flev && fxl > flev) { - ixbeg = kcol; - iwbeg = kcol - 1; - } - else - return; - - iybeg = krow; - izbeg = krow; - -/* A contour has been crossed. */ -/* Check to see if it is a new one. */ - - for (l = 0; l < *p_kscan; l++) { - if (ixbeg == iscan[l]) - return; - } - - for (iboun = 1; iboun >= -1; iboun -= 2) { - - /* Set up starting point and initial search directions */ - - ix = ixbeg; - iy = iybeg; - iw = iwbeg; - iz = izbeg; - ifirst = 1; - istep = 0; - ixgo = iw - ix; - iygo = iz - iy; - - for (;;) { - plccal(f2eval, f2eval_data, - flev, ix, iy, ixgo, iygo, &dist); - - dx = dist * ixgo; - dy = dist * iygo; - xnew = ix + dx; - ynew = iy + dy; - - /* Has a step occured in search? */ - - if (istep != 0) { - if (ixgo * iygo == 0) { - - /* This was a diagonal step, so interpolate missed point. */ - /* Rotating 45 degrees to get it */ - - ixg = ixgo; - iyg = iygo; - plr45(&ixg, &iyg, iboun); - ia = iw - ixg; - ib = iz - iyg; - plccal(f2eval, f2eval_data, - flev, ia, ib, ixg, iyg, &dist); - - (*pltr) (xlas, ylas, &tpx, &tpy, pltr_data); - - if (contlabel_active) - pl_drawcontlabel(tpx, tpy, flabel, &distance, &lastindex); - else - cont_xy_store(tpx,tpy); /* plP_drawor(tpx, tpy); */ - - dx = dist * ixg; - dy = dist * iyg; - xlas = ia + dx; - ylas = ib + dy; - } - else { - if (dist > 0.5) { - xt = xlas; - xlas = xnew; - xnew = xt; - yt = ylas; - ylas = ynew; - ynew = yt; - } - } - } - if (ifirst != 1) { - (*pltr) (xlas, ylas, &tpx, &tpy, pltr_data); - if (contlabel_active) - pl_drawcontlabel(tpx, tpy, flabel, &distance, &lastindex); - else - cont_xy_store(tpx,tpy); /* plP_drawor(tpx, tpy); */ - } - else { - (*pltr) (xnew, ynew, &tpx, &tpy, pltr_data); - cont_mv_store(tpx,tpy); /* plP_movwor(tpx, tpy); */ - } - xlas = xnew; - ylas = ynew; - - /* Check if the contour is closed */ - - if (ifirst != 1 && - ix == ixbeg && iy == iybeg && iw == iwbeg && iz == izbeg) { - (*pltr) (xlas, ylas, &tpx, &tpy, pltr_data); - if (contlabel_active) - pl_drawcontlabel(tpx, tpy, flabel, &distance, &lastindex); - else - cont_xy_store(tpx,tpy); /* plP_drawor(tpx, tpy); */ - return; - } - ifirst = 0; - - /* Now the rotation */ - - istep = 0; - plr45(&ixgo, &iygo, iboun); - iw = ix + ixgo; - iz = iy + iygo; - - /* Check if out of bounds */ - - if (iw < kx || iw > lx || iz < ky || iz > ly) - break; - - /* Has contact been lost with the contour? */ - - if (ixgo * iygo == 0) - fcheck = f2eval(iw, iz, f2eval_data); - else { - f1 = f2eval(ix, iy, f2eval_data); - f2 = f2eval(iw, iz, f2eval_data); - f3 = f2eval(ix, iz, f2eval_data); - f4 = f2eval(iw, iy, f2eval_data); - - fcheck = MAX(f2, (f1 + f2 + f3 + f4) / 4.); - } - - if (fcheck < flev) { - - /* Yes, lost contact => step to new center */ - - istep = 1; - ix = iw; - iy = iz; - plr135(&ixgo, &iygo, iboun); - iw = ix + ixgo; - iz = iy + iygo; - - /* And do the contour memory */ - - if (iy == krow) { - *p_kscan = *p_kscan + 1; - iscan[*p_kscan - 1] = ix; - } - else if (iy > krow) { - *p_kstor = *p_kstor + 1; - if (*p_kstor > nstor) { - plabort("plfcont: heap exhausted"); - error = 1; - return; - } - ixstor[*p_kstor - 1] = ix; - iystor[*p_kstor - 1] = iy; - } - } - } - /* Reach here only if boundary encountered - Draw last bit */ - - (*pltr) (xnew, ynew, &tpx, &tpy, pltr_data); - /* distance = 0.0; */ - - cont_xy_store(tpx,tpy); /* plP_drawor(tpx, tpy); */ - } -} - -/*--------------------------------------------------------------------------*\ - * void plccal() - * - * Function to interpolate the position of a contour which is known to be - * next to ix,iy in the direction ixg,iyg. The unscaled distance along - * ixg,iyg is returned as dist. -\*--------------------------------------------------------------------------*/ - -static void -plccal(PLFLT (*f2eval) (PLINT, PLINT, PLPointer), - PLPointer f2eval_data, - PLFLT flev, PLINT ix, PLINT iy, - PLINT ixg, PLINT iyg, PLFLT *dist) -{ - PLINT ia, ib; - PLFLT dbot, dtop, fmid; - PLFLT fxy, fab, fay, fxb, flow; - - ia = ix + ixg; - ib = iy + iyg; - fxy = f2eval(ix, iy, f2eval_data); - fab = f2eval(ia, ib, f2eval_data); - fxb = f2eval(ix, ib, f2eval_data); - fay = f2eval(ia, iy, f2eval_data); - - if (ixg == 0 || iyg == 0) { - dtop = flev - fxy; - dbot = fab - fxy; - *dist = 0.0; - if (dbot != 0.0) - *dist = dtop / dbot; - } - else { - fmid = (fxy + fab + fxb + fay) / 4.0; - *dist = 0.5; - - if ((fxy - flev) * (fab - flev) <= 0.) { - - if (fmid >= flev) { - dtop = flev - fxy; - dbot = fmid - fxy; - if (dbot != 0.0) - *dist = 0.5 * dtop / dbot; - } - else { - dtop = flev - fab; - dbot = fmid - fab; - if (dbot != 0.0) - *dist = 1.0 - 0.5 * dtop / dbot; - } - } - else { - flow = (fxb + fay) / 2.0; - dtop = fab - flev; - dbot = fab + fxy - 2.0 * flow; - if (dbot != 0.0) - *dist = 1. - dtop / dbot; - } - } - if (*dist > 1.) - *dist = 1.; -} - -/*--------------------------------------------------------------------------*\ - * Rotators -\*--------------------------------------------------------------------------*/ - -static void -plr45 (PLINT *ix, PLINT *iy, PLINT isens) -{ - PLINT ixx, iyy; - - ixx = *ix - isens * (*iy); - iyy = *ix * isens + *iy; - *ix = ixx / MAX(1, ABS(ixx)); - *iy = iyy / MAX(1, ABS(iyy)); -} - -static void -plr135 (PLINT *ix, PLINT *iy, PLINT isens) -{ - *ix = -*ix; - *iy = -*iy; - plr45(ix, iy, isens); -} - -/*--------------------------------------------------------------------------*\ - * pltr0() - * - * Identity transformation. -\*--------------------------------------------------------------------------*/ - -void -pltr0(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data) -{ - *tx = x; - *ty = y; -} - -/*--------------------------------------------------------------------------*\ - * pltr1() - * - * Does linear interpolation from singly dimensioned coord arrays. - * - * Just abort for now if coordinates are out of bounds (don't think it's - * possible, but if so we could use linear extrapolation). -\*--------------------------------------------------------------------------*/ - -MZ_DLLEXPORT -void -pltr1(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data) -{ - PLINT ul, ur, vl, vr; - PLFLT du, dv; - PLFLT xl, xr, yl, yr; - - PLcGrid *grid = (PLcGrid *) pltr_data; - PLFLT *xg = grid->xg; - PLFLT *yg = grid->yg; - PLINT nx = grid->nx; - PLINT ny = grid->ny; - - ul = (PLINT) x; - ur = ul + 1; - du = x - ul; - - vl = (PLINT) y; - vr = vl + 1; - dv = y - vl; - - if (x < 0 || x > nx - 1 || y < 0 || y > ny - 1) { - - /* fprintf(stderr, "nx : %d, ny : %d",nx,ny); */ - plexit("pltr1: Invalid coordinates"); - } - -/* Look up coordinates in row-dominant array. - * Have to handle right boundary specially -- if at the edge, we'd better - * not reference the out of bounds point. - */ - - xl = xg[ul]; - yl = yg[vl]; - - if (ur == nx) { - *tx = xl; - } - else { - xr = xg[ur]; - *tx = xl * (1 - du) + xr * du; - } - if (vr == ny) { - *ty = yl; - } - else { - yr = yg[vr]; - *ty = yl * (1 - dv) + yr * dv; - } -} - -/*--------------------------------------------------------------------------*\ - * pltr2() - * - * Does linear interpolation from doubly dimensioned coord arrays (column - * dominant, as per normal C 2d arrays). - * - * This routine includes lots of checks for out of bounds. This would occur - * occasionally due to some bugs in the contour plotter (now fixed). If an - * out of bounds coordinate is obtained, the boundary value is provided - * along with a warning. These checks should stay since no harm is done if - * if everything works correctly. -\*--------------------------------------------------------------------------*/ - -void -pltr2(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data) -{ - PLINT ul, ur, vl, vr; - PLFLT du, dv; - PLFLT xll, xlr, xrl, xrr; - PLFLT yll, ylr, yrl, yrr; - PLFLT xmin, xmax, ymin, ymax; - - PLcGrid2 *grid = (PLcGrid2 *) pltr_data; - PLFLT **xg = grid->xg; - PLFLT **yg = grid->yg; - PLINT nx = grid->nx; - PLINT ny = grid->ny; - - ul = (PLINT) x; - ur = ul + 1; - du = x - ul; - - vl = (PLINT) y; - vr = vl + 1; - dv = y - vl; - - xmin = 0; - xmax = nx - 1; - ymin = 0; - ymax = ny - 1; - - if (x < xmin || x > xmax || y < ymin || y > ymax) { - plwarn("pltr2: Invalid coordinates"); - if (x < xmin) { - - if (y < ymin) { - *tx = xg[0][0]; - *ty = yg[0][0]; - } - else if (y > ymax) { - *tx = xg[0][ny-1]; - *ty = yg[0][ny-1]; - } - else { - xll = xg[0][vl]; - yll = yg[0][vl]; - xlr = xg[0][vr]; - ylr = yg[0][vr]; - - *tx = xll * (1 - dv) + xlr * (dv); - *ty = yll * (1 - dv) + ylr * (dv); - } - } - else if (x > xmax) { - - if (y < ymin) { - *tx = xg[nx-1][0]; - *ty = yg[nx-1][0]; - } - else if (y > ymax) { - *tx = xg[nx-1][ny-1]; - *ty = yg[nx-1][ny-1]; - } - else { - xll = xg[nx-1][vl]; - yll = yg[nx-1][vl]; - xlr = xg[nx-1][vr]; - ylr = yg[nx-1][vr]; - - *tx = xll * (1 - dv) + xlr * (dv); - *ty = yll * (1 - dv) + ylr * (dv); - } - } - else { - if (y < ymin) { - xll = xg[ul][0]; - xrl = xg[ur][0]; - yll = yg[ul][0]; - yrl = yg[ur][0]; - - *tx = xll * (1 - du) + xrl * (du); - *ty = yll * (1 - du) + yrl * (du); - } - else if (y > ymax) { - xlr = xg[ul][ny-1]; - xrr = xg[ur][ny-1]; - ylr = yg[ul][ny-1]; - yrr = yg[ur][ny-1]; - - *tx = xlr * (1 - du) + xrr * (du); - *ty = ylr * (1 - du) + yrr * (du); - } - } - } - -/* Normal case. - * Look up coordinates in row-dominant array. - * Have to handle right boundary specially -- if at the edge, we'd - * better not reference the out of bounds point. - */ - - else { - - xll = xg[ul][vl]; - yll = yg[ul][vl]; - - /* ur is out of bounds */ - - if (ur == nx && vr < ny) { - - xlr = xg[ul][vr]; - ylr = yg[ul][vr]; - - *tx = xll * (1 - dv) + xlr * (dv); - *ty = yll * (1 - dv) + ylr * (dv); - } - - /* vr is out of bounds */ - - else if (ur < nx && vr == ny) { - - xrl = xg[ur][vl]; - yrl = yg[ur][vl]; - - *tx = xll * (1 - du) + xrl * (du); - *ty = yll * (1 - du) + yrl * (du); - } - - /* both ur and vr are out of bounds */ - - else if (ur == nx && vr == ny) { - - *tx = xll; - *ty = yll; - } - - /* everything in bounds */ - - else { - - xrl = xg[ur][vl]; - xlr = xg[ul][vr]; - xrr = xg[ur][vr]; - - yrl = yg[ur][vl]; - ylr = yg[ul][vr]; - yrr = yg[ur][vr]; - - *tx = xll * (1 - du) * (1 - dv) + xlr * (1 - du) * (dv) + - xrl * (du) * (1 - dv) + xrr * (du) * (dv); - - *ty = yll * (1 - du) * (1 - dv) + ylr * (1 - du) * (dv) + - yrl * (du) * (1 - dv) + yrr * (du) * (dv); - } - } -} - -/*--------------------------------------------------------------------------*\ - * pltr2p() - * - * Just like pltr2() but uses pointer arithmetic to get coordinates from 2d - * grid tables. This form of grid tables is compatible with those from - * PLplot 4.0. The grid data must be pointed to by a PLcGrid structure. -\*--------------------------------------------------------------------------*/ - -void -pltr2p(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data) -{ - PLINT ul, ur, vl, vr; - PLFLT du, dv; - PLFLT xll, xlr, xrl, xrr; - PLFLT yll, ylr, yrl, yrr; - PLFLT xmin, xmax, ymin, ymax; - - PLcGrid *grid = (PLcGrid *) pltr_data; - PLFLT *xg = grid->xg; - PLFLT *yg = grid->yg; - PLINT nx = grid->nx; - PLINT ny = grid->ny; - - ul = (PLINT) x; - ur = ul + 1; - du = x - ul; - - vl = (PLINT) y; - vr = vl + 1; - dv = y - vl; - - xmin = 0; - xmax = nx - 1; - ymin = 0; - ymax = ny - 1; - - if (x < xmin || x > xmax || y < ymin || y > ymax) { - plwarn("pltr2p: Invalid coordinates"); - if (x < xmin) { - - if (y < ymin) { - *tx = *xg; - *ty = *yg; - } - else if (y > ymax) { - *tx = *(xg + (ny - 1)); - *ty = *(yg + (ny - 1)); - } - else { - ul = 0; - xll = *(xg + ul * ny + vl); - yll = *(yg + ul * ny + vl); - xlr = *(xg + ul * ny + vr); - ylr = *(yg + ul * ny + vr); - - *tx = xll * (1 - dv) + xlr * (dv); - *ty = yll * (1 - dv) + ylr * (dv); - } - } - else if (x > xmax) { - - if (y < ymin) { - *tx = *(xg + (ny - 1) * nx); - *ty = *(yg + (ny - 1) * nx); - } - else if (y > ymax) { - *tx = *(xg + (ny - 1) + (nx - 1) * ny); - *ty = *(yg + (ny - 1) + (nx - 1) * ny); - } - else { - ul = nx - 1; - xll = *(xg + ul * ny + vl); - yll = *(yg + ul * ny + vl); - xlr = *(xg + ul * ny + vr); - ylr = *(yg + ul * ny + vr); - - *tx = xll * (1 - dv) + xlr * (dv); - *ty = yll * (1 - dv) + ylr * (dv); - } - } - else { - if (y < ymin) { - vl = 0; - xll = *(xg + ul * ny + vl); - xrl = *(xg + ur * ny + vl); - yll = *(yg + ul * ny + vl); - yrl = *(yg + ur * ny + vl); - - *tx = xll * (1 - du) + xrl * (du); - *ty = yll * (1 - du) + yrl * (du); - } - else if (y > ymax) { - vr = ny - 1; - xlr = *(xg + ul * ny + vr); - xrr = *(xg + ur * ny + vr); - ylr = *(yg + ul * ny + vr); - yrr = *(yg + ur * ny + vr); - - *tx = xlr * (1 - du) + xrr * (du); - *ty = ylr * (1 - du) + yrr * (du); - } - } - } - -/* Normal case. - * Look up coordinates in row-dominant array. - * Have to handle right boundary specially -- if at the edge, we'd better - * not reference the out of bounds point. - */ - - else { - - xll = *(xg + ul * ny + vl); - yll = *(yg + ul * ny + vl); - - /* ur is out of bounds */ - - if (ur == nx && vr < ny) { - - xlr = *(xg + ul * ny + vr); - ylr = *(yg + ul * ny + vr); - - *tx = xll * (1 - dv) + xlr * (dv); - *ty = yll * (1 - dv) + ylr * (dv); - } - - /* vr is out of bounds */ - - else if (ur < nx && vr == ny) { - - xrl = *(xg + ur * ny + vl); - yrl = *(yg + ur * ny + vl); - - *tx = xll * (1 - du) + xrl * (du); - *ty = yll * (1 - du) + yrl * (du); - } - - /* both ur and vr are out of bounds */ - - else if (ur == nx && vr == ny) { - - *tx = xll; - *ty = yll; - } - - /* everything in bounds */ - - else { - - xrl = *(xg + ur * ny + vl); - xlr = *(xg + ul * ny + vr); - xrr = *(xg + ur * ny + vr); - - yrl = *(yg + ur * ny + vl); - ylr = *(yg + ul * ny + vr); - yrr = *(yg + ur * ny + vr); - - *tx = xll * (1 - du) * (1 - dv) + xlr * (1 - du) * (dv) + - xrl * (du) * (1 - dv) + xrr * (du) * (dv); - - *ty = yll * (1 - du) * (1 - dv) + ylr * (1 - du) * (dv) + - yrl * (du) * (1 - dv) + yrr * (du) * (dv); - } - } -} diff --git a/src/plot/plplot/plcore.c b/src/plot/plplot/plcore.c deleted file mode 100644 index b42e9d7bed..0000000000 --- a/src/plot/plplot/plcore.c +++ /dev/null @@ -1,2833 +0,0 @@ -/* $Id: plcore.c,v 1.2 2005/03/17 21:39:21 eli Exp $ - - Central dispatch facility for PLplot. - Also contains the PLplot main data structures, external access - routines, and initialization calls. - - This stuff used to be in "dispatch.h", "dispatch.c", and "base.c". -*/ - -#define DEBUG - -#define NEED_PLDEBUG -#include "plcore.h" - -#ifdef ENABLE_DYNDRIVERS -#include -#endif - -/*--------------------------------------------------------------------------*\ - * Driver Interface - * - * These routines are the low-level interface to the driver -- all calls to - * driver functions must pass through here. For implementing driver- - * specific functions, the escape function is provided. The command stream - * gets duplicated to the plot buffer here. - * - * All functions that result in graphics actually being plotted (rather than - * just a change of state) are filtered as necessary before being passed on. - * The default settings do not require any filtering, i.e. PLplot physical - * coordinates are the same as the device physical coordinates (currently - * this can't be changed anyway), and a global view equal to the entire page - * is used. - * - * The reason one wants to put view-specific filtering here is that if - * enabled, the plot buffer should receive the unfiltered data stream. This - * allows a specific view to be used from an interactive device (e.g. TCL/TK - * driver) but be restored to the full view at any time merely by - * reprocessing the contents of the plot buffer. - * - * The metafile, on the other hand, *should* be affected by changes in the - * view, since this is a crucial editing capability. It is recommended that - * the initial metafile be created without a restricted global view, and - * modification of the view done on a per-plot basis as desired during - * subsequent processing. - * -\*--------------------------------------------------------------------------*/ - -enum {AT_BOP, DRAWING, AT_EOP}; - -/* Initialize device. */ -/* The plot buffer must be called last */ - -void -plP_init(void) -{ - plsc->page_status = AT_EOP; - - (*plsc->dispatch_table->pl_init) ((struct PLStream_struct *) plsc); - - if (plsc->plbuf_write) - plbuf_init(plsc); -} - -/* End of page */ -/* The plot buffer must be called first */ -/* Ignore instruction if there's nothing drawn */ - -void -plP_eop(void) -{ - int skip_driver_eop = 0; - - if (plsc->page_status != DRAWING) - return; - - plsc->page_status = AT_EOP; - - if (plsc->plbuf_write) - plbuf_eop(plsc); - -/* Call user eop handler if present. */ - - if (plsc->eop_handler != NULL) - (*plsc->eop_handler) (plsc->eop_data, &skip_driver_eop); - - if (!skip_driver_eop) - (*plsc->dispatch_table->pl_eop) ((struct PLStream_struct *) plsc); -} - -/* Set up new page. */ -/* The plot buffer must be called last */ -/* Ignore if the bop was already issued. */ -/* It's not actually necessary to be AT_EOP here, so don't check for it. */ - -void -plP_bop(void) -{ - int skip_driver_bop = 0; - - plP_subpInit(); - if (plsc->page_status == AT_BOP) - return; - - plsc->page_status = AT_BOP; - plsc->nplwin = 0; - -/* Call user bop handler if present. */ - - if (plsc->bop_handler != NULL) - (*plsc->bop_handler) (plsc->bop_data, &skip_driver_bop); - - if (!skip_driver_bop) - (*plsc->dispatch_table->pl_bop) ((struct PLStream_struct *) plsc); - - if (plsc->plbuf_write) - plbuf_bop(plsc); -} - -/* Tidy up device (flush buffers, close file, etc). */ - -void -plP_tidy(void) -{ - if (plsc->tidy) { - (*plsc->tidy) (plsc->tidy_data); - plsc->tidy = NULL; - plsc->tidy_data = NULL; - } - - (*plsc->dispatch_table->pl_tidy) ((struct PLStream_struct *) plsc); - - if (plsc->plbuf_write) - plbuf_tidy(plsc); - - plsc->OutFile = NULL; - free_mem(plsc->FileName); -} - -/* Change state. */ - -void -plP_state(PLINT op) -{ - (*plsc->dispatch_table->pl_state) ((struct PLStream_struct *) plsc, op); - - if (plsc->plbuf_write) - plbuf_state(plsc, op); -} - -/* Escape function, for driver-specific commands. */ - -void -plP_esc(PLINT op, void *ptr) -{ - (*plsc->dispatch_table->pl_esc) ((struct PLStream_struct *) plsc, op, ptr); - - if (plsc->plbuf_write) - plbuf_esc(plsc, op, ptr); -} - -/* Set up plot window parameters. */ -/* The plot buffer must be called first */ -/* Some drivers (metafile, Tk) need access to this data */ - -void -plP_swin(PLWindow *plwin) -{ - PLWindow *w; - PLINT clpxmi, clpxma, clpymi, clpyma; - -/* Provide plot buffer with unfiltered window data */ - - if (plsc->plbuf_write) - plbuf_esc(plsc, PLESC_SWIN, (void *) plwin); - - w = &plsc->plwin[plsc->nplwin++ % PL_MAXWINDOWS]; - - w->dxmi = plwin->dxmi; - w->dxma = plwin->dxma; - w->dymi = plwin->dymi; - w->dyma = plwin->dyma; - - if (plsc->difilt) { - xscl[0] = plP_dcpcx(w->dxmi); - xscl[1] = plP_dcpcx(w->dxma); - yscl[0] = plP_dcpcy(w->dymi); - yscl[1] = plP_dcpcy(w->dyma); - - difilt(xscl, yscl, 2, &clpxmi, &clpxma, &clpymi, &clpyma); - - w->dxmi = plP_pcdcx(xscl[0]); - w->dxma = plP_pcdcx(xscl[1]); - w->dymi = plP_pcdcy(yscl[0]); - w->dyma = plP_pcdcy(yscl[1]); - } - - w->wxmi = plwin->wxmi; - w->wxma = plwin->wxma; - w->wymi = plwin->wymi; - w->wyma = plwin->wyma; - -/* If the driver wants to process swin commands, call it now */ -/* It must use the filtered data, which it can get from *plsc */ - - if (plsc->dev_swin) { - (*plsc->dispatch_table->pl_esc) ( (struct PLStream_struct *) plsc, - PLESC_SWIN, NULL ); - } -} - -/*--------------------------------------------------------------------------*\ - * Drawing commands. -\*--------------------------------------------------------------------------*/ - -/* Draw line between two points */ -/* The plot buffer must be called first so it gets the unfiltered data */ - -void -plP_line(short *x, short *y) -{ - PLINT i, npts = 2, clpxmi, clpxma, clpymi, clpyma; - - plsc->page_status = DRAWING; - - if (plsc->plbuf_write) - plbuf_line(plsc, x[0], y[0], x[1], y[1]); - - if (plsc->difilt) { - for (i = 0; i < npts; i++) { - xscl[i] = x[i]; - yscl[i] = y[i]; - } - difilt(xscl, yscl, npts, &clpxmi, &clpxma, &clpymi, &clpyma); - plP_pllclp(xscl, yscl, npts, clpxmi, clpxma, clpymi, clpyma, grline); - } - else { - grline(x, y, npts); - } -} - -/* Draw polyline */ -/* The plot buffer must be called first */ - -void -plP_polyline(short *x, short *y, PLINT npts) -{ - PLINT i, clpxmi, clpxma, clpymi, clpyma; - - plsc->page_status = DRAWING; - - if (plsc->plbuf_write) - plbuf_polyline(plsc, x, y, npts); - - if (plsc->difilt) { - for (i = 0; i < npts; i++) { - xscl[i] = x[i]; - yscl[i] = y[i]; - } - difilt(xscl, yscl, npts, &clpxmi, &clpxma, &clpymi, &clpyma); - plP_pllclp(xscl, yscl, npts, clpxmi, clpxma, clpymi, clpyma, - grpolyline); - } - else { - grpolyline(x, y, npts); - } -} - -/* Fill polygon */ -/* The plot buffer must be called first */ -/* Here if the desired area fill capability isn't present, we mock up */ -/* something in software */ - -static int foo; - -void -plP_fill(short *x, short *y, PLINT npts) -{ - PLINT i, clpxmi, clpxma, clpymi, clpyma; - - plsc->page_status = DRAWING; - - if (plsc->plbuf_write) { - plsc->dev_npts = npts; - plsc->dev_x = x; - plsc->dev_y = y; - plbuf_esc(plsc, PLESC_FILL, NULL); - } - -/* Account for driver ability to do fills */ - - if (plsc->patt == 0 && ! plsc->dev_fill0) { - if ( ! foo) { - plwarn("Driver does not support hardware solid fills, switching to software fill.\n"); - foo = 1; - } - plsc->patt = 8; - plpsty(plsc->patt); - } - if (plsc->dev_fill1) { - plsc->patt = -ABS(plsc->patt); - } - -/* Perform fill. Here we MUST NOT allow the software fill to pass through the - driver interface filtering twice, else we get the infamous 2*rotation for - software fills on orientation swaps. -*/ - - if (plsc->patt > 0) - plfill_soft(x, y, npts); - - else { - if (plsc->difilt) { - for (i = 0; i < npts; i++) { - xscl[i] = x[i]; - yscl[i] = y[i]; - } - difilt(xscl, yscl, npts, &clpxmi, &clpxma, &clpymi, &clpyma); - plP_plfclp(xscl, yscl, npts, clpxmi, clpxma, clpymi, clpyma, - grfill); - } - else { - grfill(x, y, npts); - } - } -} - -/* Account for driver ability to draw text itself */ -/* -#define DEBUG_TEXT -*/ - -void -plP_text(PLINT base, PLFLT just, PLFLT *xform, PLINT x, PLINT y, - PLINT refx, PLINT refy, const char *string) -{ - if (plsc->dev_text) { - EscText args; - - args.base = base; - args.just = just; - args.xform = xform; - args.x = x; - args.y = y; - args.refx = refx; - args.refy = refy; - args.string = string; - - if (plsc->plbuf_write) - plbuf_esc(plsc, PLESC_HAS_TEXT, &args); - - plP_esc(PLESC_HAS_TEXT, &args); -#ifndef DEBUG_TEXT - } else { -#endif - plstr(base, xform, refx, refy, string); - } -} - -static void -grline(short *x, short *y, PLINT npts) -{ - (*plsc->dispatch_table->pl_line) ( (struct PLStream_struct *) plsc, - x[0], y[0], x[1], y[1] ); -} - -static void -grpolyline(short *x, short *y, PLINT npts) -{ - (*plsc->dispatch_table->pl_polyline) ( (struct PLStream_struct *) plsc, - x, y, npts ); -} - -static void -grfill(short *x, short *y, PLINT npts) -{ - plsc->dev_npts = npts; - plsc->dev_x = x; - plsc->dev_y = y; - - (*plsc->dispatch_table->pl_esc) ( (struct PLStream_struct *) plsc, - PLESC_FILL, NULL ); -} - -/*--------------------------------------------------------------------------*\ - * void difilt - * - * Driver interface filter -- passes all coordinates through a variety - * of filters. These include filters to change : - * - * - mapping of meta to physical coordinates - * - plot orientation - * - window into plot (zooms) - * - window into device (i.e set margins) - * - * The filters are applied in the order specified above. Because the - * orientation change comes first, subsequent window specifications affect - * the new coordinates (i.e. after a 90 degree flip, what was x is now y). - * This is the only way that makes sense from a graphical interface - * (e.g. TCL/TK driver). - * - * Where appropriate, the page clip limits are modified. -\*--------------------------------------------------------------------------*/ - -void -difilt(PLINT *xscl, PLINT *yscl, PLINT npts, - PLINT *clpxmi, PLINT *clpxma, PLINT *clpymi, PLINT *clpyma) -{ - PLINT i, x, y; - -/* Map meta coordinates to physical coordinates */ - - if (plsc->difilt & PLDI_MAP) { - for (i = 0; i < npts; i++) { - xscl[i] = plsc->dimxax * xscl[i] + plsc->dimxb; - yscl[i] = plsc->dimyay * yscl[i] + plsc->dimyb; - } - } - -/* Change orientation */ - - if (plsc->difilt & PLDI_ORI) { - for (i = 0; i < npts; i++) { - x = plsc->dioxax * xscl[i] + plsc->dioxay * yscl[i] + plsc->dioxb; - y = plsc->dioyax * xscl[i] + plsc->dioyay * yscl[i] + plsc->dioyb; - xscl[i] = x; - yscl[i] = y; - } - } - -/* Change window into plot space */ - - if (plsc->difilt & PLDI_PLT) { - for (i = 0; i < npts; i++) { - xscl[i] = plsc->dipxax * xscl[i] + plsc->dipxb; - yscl[i] = plsc->dipyay * yscl[i] + plsc->dipyb; - } - } - -/* Change window into device space and set clip limits */ -/* (this is the only filter that modifies them) */ - - if (plsc->difilt & PLDI_DEV) { - for (i = 0; i < npts; i++) { - xscl[i] = plsc->didxax * xscl[i] + plsc->didxb; - yscl[i] = plsc->didyay * yscl[i] + plsc->didyb; - } - *clpxmi = plsc->diclpxmi; - *clpxma = plsc->diclpxma; - *clpymi = plsc->diclpymi; - *clpyma = plsc->diclpyma; - } - else { - *clpxmi = plsc->phyxmi; - *clpxma = plsc->phyxma; - *clpymi = plsc->phyymi; - *clpyma = plsc->phyyma; - } -} - -void -sdifilt(short *xscl, short *yscl, PLINT npts, - PLINT *clpxmi, PLINT *clpxma, PLINT *clpymi, PLINT *clpyma) -{ - int i; - short x, y; - -/* Map meta coordinates to physical coordinates */ - - if (plsc->difilt & PLDI_MAP) { - for (i = 0; i < npts; i++) { - xscl[i] = plsc->dimxax * xscl[i] + plsc->dimxb; - yscl[i] = plsc->dimyay * yscl[i] + plsc->dimyb; - } - } - -/* Change orientation */ - - if (plsc->difilt & PLDI_ORI) { - for (i = 0; i < npts; i++) { - x = plsc->dioxax * xscl[i] + plsc->dioxay * yscl[i] + plsc->dioxb; - y = plsc->dioyax * xscl[i] + plsc->dioyay * yscl[i] + plsc->dioyb; - xscl[i] = x; - yscl[i] = y; - } - } - -/* Change window into plot space */ - - if (plsc->difilt & PLDI_PLT) { - for (i = 0; i < npts; i++) { - xscl[i] = plsc->dipxax * xscl[i] + plsc->dipxb; - yscl[i] = plsc->dipyay * yscl[i] + plsc->dipyb; - } - } - -/* Change window into device space and set clip limits */ -/* (this is the only filter that modifies them) */ - - if (plsc->difilt & PLDI_DEV) { - for (i = 0; i < npts; i++) { - xscl[i] = plsc->didxax * xscl[i] + plsc->didxb; - yscl[i] = plsc->didyay * yscl[i] + plsc->didyb; - } - *clpxmi = plsc->diclpxmi; - *clpxma = plsc->diclpxma; - *clpymi = plsc->diclpymi; - *clpyma = plsc->diclpyma; - } - else { - *clpxmi = plsc->phyxmi; - *clpxma = plsc->phyxma; - *clpymi = plsc->phyymi; - *clpyma = plsc->phyyma; - } -} - -/*--------------------------------------------------------------------------*\ - * void pldi_ini - * - * Updates driver interface, making sure everything is in order. - * Even if filter is not being used, the defaults need to be set up. -\*--------------------------------------------------------------------------*/ - -static void -setdef_diplt() -{ - plsc->dipxmin = 0.0; - plsc->dipxmax = 1.0; - plsc->dipymin = 0.0; - plsc->dipymax = 1.0; -} - -static void -setdef_didev() -{ - plsc->mar = 0.0; - plsc->aspect = 0.0; - plsc->jx = 0.0; - plsc->jy = 0.0; -} - -static void -setdef_diori() -{ - plsc->diorot = 0.; -} - -static void -pldi_ini(void) -{ - if (plsc->level >= 1) { - if (plsc->difilt & PLDI_MAP) /* Coordinate mapping */ - calc_dimap(); - - if (plsc->difilt & PLDI_ORI) /* Orientation */ - calc_diori(); - else - setdef_diori(); - - if (plsc->difilt & PLDI_PLT) /* Plot window */ - calc_diplt(); - else - setdef_diplt(); - - if (plsc->difilt & PLDI_DEV) /* Device window */ - calc_didev(); - else - setdef_didev(); - } -} - -/*--------------------------------------------------------------------------*\ - * void pldid2pc - * - * Converts input values from relative device coordinates to relative plot - * coordinates. This function must be called when selecting a plot window - * from a display driver, since the coordinates chosen by the user are - * necessarily device-specific. -\*--------------------------------------------------------------------------*/ - -void -pldid2pc(PLFLT *xmin, PLFLT *ymin, PLFLT *xmax, PLFLT *ymax) -{ - PLFLT pxmin, pymin, pxmax, pymax; - PLFLT sxmin, symin, sxmax, symax; - PLFLT rxmin, rymin, rxmax, rymax; - - if (plsc->difilt & PLDI_DEV) { - - pldebug("pldid2pc", - "Relative device coordinates (in): %f, %f, %f, %f\n", - *xmin, *ymin, *xmax, *ymax); - - pxmin = plP_dcpcx(*xmin); - pymin = plP_dcpcy(*ymin); - pxmax = plP_dcpcx(*xmax); - pymax = plP_dcpcy(*ymax); - - sxmin = (pxmin - plsc->didxb) / plsc->didxax; - symin = (pymin - plsc->didyb) / plsc->didyay; - sxmax = (pxmax - plsc->didxb) / plsc->didxax; - symax = (pymax - plsc->didyb) / plsc->didyay; - - rxmin = plP_pcdcx(sxmin); - rymin = plP_pcdcy(symin); - rxmax = plP_pcdcx(sxmax); - rymax = plP_pcdcy(symax); - - *xmin = (rxmin < 0) ? 0 : rxmin; - *xmax = (rxmax > 1) ? 1 : rxmax; - *ymin = (rymin < 0) ? 0 : rymin; - *ymax = (rymax > 1) ? 1 : rymax; - - pldebug("pldid2pc", - "Relative plot coordinates (out): %f, %f, %f, %f\n", - rxmin, rymin, rxmax, rymax); - } -} - -/*--------------------------------------------------------------------------*\ - * void pldip2dc - * - * Converts input values from relative plot coordinates to relative - * device coordinates. -\*--------------------------------------------------------------------------*/ - -void -pldip2dc(PLFLT *xmin, PLFLT *ymin, PLFLT *xmax, PLFLT *ymax) -{ - PLFLT pxmin, pymin, pxmax, pymax; - PLFLT sxmin, symin, sxmax, symax; - PLFLT rxmin, rymin, rxmax, rymax; - - if (plsc->difilt & PLDI_DEV) { - - pldebug("pldip2pc", - "Relative plot coordinates (in): %f, %f, %f, %f\n", - *xmin, *ymin, *xmax, *ymax); - - pxmin = plP_dcpcx(*xmin); - pymin = plP_dcpcy(*ymin); - pxmax = plP_dcpcx(*xmax); - pymax = plP_dcpcy(*ymax); - - sxmin = pxmin * plsc->didxax + plsc->didxb; - symin = pymin * plsc->didyay + plsc->didyb; - sxmax = pxmax * plsc->didxax + plsc->didxb; - symax = pymax * plsc->didyay + plsc->didyb; - - rxmin = plP_pcdcx(sxmin); - rymin = plP_pcdcy(symin); - rxmax = plP_pcdcx(sxmax); - rymax = plP_pcdcy(symax); - - *xmin = (rxmin < 0) ? 0 : rxmin; - *xmax = (rxmax > 1) ? 1 : rxmax; - *ymin = (rymin < 0) ? 0 : rymin; - *ymax = (rymax > 1) ? 1 : rymax; - - pldebug("pldip2pc", - "Relative device coordinates (out): %f, %f, %f, %f\n", - rxmin, rymin, rxmax, rymax); - } -} - -/*--------------------------------------------------------------------------*\ - * void plsdiplt - * - * Set window into plot space -\*--------------------------------------------------------------------------*/ - -void -c_plsdiplt(PLFLT xmin, PLFLT ymin, PLFLT xmax, PLFLT ymax) -{ - plsc->dipxmin = (xmin < xmax) ? xmin : xmax; - plsc->dipxmax = (xmin < xmax) ? xmax : xmin; - plsc->dipymin = (ymin < ymax) ? ymin : ymax; - plsc->dipymax = (ymin < ymax) ? ymax : ymin; - - if (xmin == 0. && xmax == 1. && ymin == 0. && ymax == 1.) { - plsc->difilt &= ~PLDI_PLT; - return; - } - - plsc->difilt |= PLDI_PLT; - pldi_ini(); -} - -/*--------------------------------------------------------------------------*\ - * void plsdiplz - * - * Set window into plot space incrementally (zoom) -\*--------------------------------------------------------------------------*/ - -void -c_plsdiplz(PLFLT xmin, PLFLT ymin, PLFLT xmax, PLFLT ymax) -{ - if (plsc->difilt & PLDI_PLT) { - xmin = plsc->dipxmin + (plsc->dipxmax - plsc->dipxmin) * xmin; - ymin = plsc->dipymin + (plsc->dipymax - plsc->dipymin) * ymin; - xmax = plsc->dipxmin + (plsc->dipxmax - plsc->dipxmin) * xmax; - ymax = plsc->dipymin + (plsc->dipymax - plsc->dipymin) * ymax; - } - - plsdiplt(xmin, ymin, xmax, ymax); -} - -/*--------------------------------------------------------------------------*\ - * void calc_diplt - * - * Calculate transformation coefficients to set window into plot space. - * - * Note: if driver has requested to handle these commands itself, we must - * send the appropriate escape command. If the driver succeeds it will - * cancel the filter operation. The command is deferred until this point - * to ensure that the driver has been initialized. -\*--------------------------------------------------------------------------*/ - -static void -calc_diplt(void) -{ - PLINT pxmin, pxmax, pymin, pymax, pxlen, pylen; - - if (plsc->dev_di) { - (*plsc->dispatch_table->pl_esc) ( (struct PLStream_struct *) plsc, - PLESC_DI, NULL ); - } - - if ( ! (plsc->difilt & PLDI_PLT)) - return; - - pxmin = plP_dcpcx(plsc->dipxmin); - pxmax = plP_dcpcx(plsc->dipxmax); - pymin = plP_dcpcy(plsc->dipymin); - pymax = plP_dcpcy(plsc->dipymax); - - pxlen = pxmax - pxmin; - pylen = pymax - pymin; - pxlen = MAX(1, pxlen); - pylen = MAX(1, pylen); - - plsc->dipxax = plsc->phyxlen / (double) pxlen; - plsc->dipyay = plsc->phyylen / (double) pylen; - plsc->dipxb = plsc->phyxmi - plsc->dipxax * pxmin; - plsc->dipyb = plsc->phyymi - plsc->dipyay * pymin; -} - -/*--------------------------------------------------------------------------*\ - * void plgdiplt - * - * Retrieve current window into plot space -\*--------------------------------------------------------------------------*/ - -void -c_plgdiplt(PLFLT *p_xmin, PLFLT *p_ymin, PLFLT *p_xmax, PLFLT *p_ymax) -{ - *p_xmin = plsc->dipxmin; - *p_xmax = plsc->dipxmax; - *p_ymin = plsc->dipymin; - *p_ymax = plsc->dipymax; -} - -/*--------------------------------------------------------------------------*\ - * void plsdidev - * - * Set window into device space using margin, aspect ratio, and - * justification. If you want to just use the previous value for any of - * these, just pass in the magic value PL_NOTSET. - * - * It is unlikely that one should ever need to change the aspect ratio - * but it's in there for completeness. -\*--------------------------------------------------------------------------*/ - -void -c_plsdidev(PLFLT mar, PLFLT aspect, PLFLT jx, PLFLT jy) -{ - plsetvar(plsc->mar, mar); - plsetvar(plsc->aspect, aspect); - plsetvar(plsc->jx, jx); - plsetvar(plsc->jy, jy); - - if (mar == 0. && aspect == 0. && jx == 0. && jy == 0. && - ! (plsc->difilt & PLDI_ORI)) { - plsc->difilt &= ~PLDI_DEV; - return; - } - - plsc->difilt |= PLDI_DEV; - pldi_ini(); -} - -/*--------------------------------------------------------------------------*\ - * void calc_didev - * - * Calculate transformation coefficients to set window into device space. - * Calculates relative window bounds and calls plsdidxy to finish the job. -\*--------------------------------------------------------------------------*/ - -static void -calc_didev(void) -{ - PLFLT lx, ly, aspect, aspdev; - PLFLT xmin, xmax, xlen, ymin, ymax, ylen; - PLINT pxmin, pxmax, pymin, pymax, pxlen, pylen; - - if (plsc->dev_di) { - (*plsc->dispatch_table->pl_esc) ( (struct PLStream_struct *) plsc, - PLESC_DI, NULL ); - } - - if ( ! (plsc->difilt & PLDI_DEV)) - return; - -/* Calculate aspect ratio of physical device */ - - lx = plsc->phyxlen / plsc->xpmm; - ly = plsc->phyylen / plsc->ypmm; - aspdev = lx / ly; - - if (plsc->difilt & PLDI_ORI) - aspect = plsc->aspori; - else - aspect = plsc->aspect; - - if (aspect <= 0.) - aspect = plsc->aspdev; - -/* Failsafe */ - - plsc->mar = (plsc->mar > 0.5) ? 0.5 : plsc->mar; - plsc->mar = (plsc->mar < 0.0) ? 0.0 : plsc->mar; - plsc->jx = (plsc->jx > 0.5) ? 0.5 : plsc->jx; - plsc->jx = (plsc->jx < -0.5) ? -0.5 : plsc->jx; - plsc->jy = (plsc->jy > 0.5) ? 0.5 : plsc->jy; - plsc->jy = (plsc->jy < -0.5) ? -0.5 : plsc->jy; - -/* Relative device coordinates that neutralize aspect ratio difference */ - - xlen = (aspect < aspdev) ? (aspect / aspdev) : 1.0; - ylen = (aspect < aspdev) ? 1.0 : (aspdev / aspect); - - xlen *= (1.0 - 2.*plsc->mar); - ylen *= (1.0 - 2.*plsc->mar); - - xmin = (1. - xlen) * (0.5 + plsc->jx); - xmax = xmin + xlen; - - ymin = (1. - ylen) * (0.5 + plsc->jy); - ymax = ymin + ylen; - -/* Calculate transformation coefficients */ - - pxmin = plP_dcpcx(xmin); - pxmax = plP_dcpcx(xmax); - pymin = plP_dcpcy(ymin); - pymax = plP_dcpcy(ymax); - - pxlen = pxmax - pxmin; - pylen = pymax - pymin; - pxlen = MAX(1, pxlen); - pylen = MAX(1, pylen); - - plsc->didxax = pxlen / (double) plsc->phyxlen; - plsc->didyay = pylen / (double) plsc->phyylen; - plsc->didxb = pxmin - plsc->didxax * plsc->phyxmi; - plsc->didyb = pymin - plsc->didyay * plsc->phyymi; - -/* Set clip limits to conform to new page size */ - - plsc->diclpxmi = plsc->didxax * plsc->phyxmi + plsc->didxb; - plsc->diclpxma = plsc->didxax * plsc->phyxma + plsc->didxb; - plsc->diclpymi = plsc->didyay * plsc->phyymi + plsc->didyb; - plsc->diclpyma = plsc->didyay * plsc->phyyma + plsc->didyb; -} - -/*--------------------------------------------------------------------------*\ - * void plgdidev - * - * Retrieve current window into device space -\*--------------------------------------------------------------------------*/ - -void -c_plgdidev(PLFLT *p_mar, PLFLT *p_aspect, PLFLT *p_jx, PLFLT *p_jy) -{ - *p_mar = plsc->mar; - *p_aspect = plsc->aspect; - *p_jx = plsc->jx; - *p_jy = plsc->jy; -} - -/*--------------------------------------------------------------------------*\ - * void plsdiori - * - * Set plot orientation, specifying rotation in units of pi/2. -\*--------------------------------------------------------------------------*/ - -void -c_plsdiori(PLFLT rot) -{ - plsc->diorot = rot; - if (rot == 0.) { - plsc->difilt &= ~PLDI_ORI; - pldi_ini(); - return; - } - - plsc->difilt |= PLDI_ORI; - pldi_ini(); -} - -/*--------------------------------------------------------------------------*\ - * void calc_diori - * - * Calculate transformation coefficients to arbitrarily orient plot. - * Preserve aspect ratios so the output doesn't suck. -\*--------------------------------------------------------------------------*/ - -static void -calc_diori(void) -{ - PLFLT r11, r21, r12, r22, cost, sint; - PLFLT x0, y0, lx, ly, aspect; - - if (plsc->dev_di) { - (*plsc->dispatch_table->pl_esc) ( (struct PLStream_struct *) plsc, - PLESC_DI, NULL ); - } - - if ( ! (plsc->difilt & PLDI_ORI)) - return; - -/* Center point of rotation */ - - x0 = (plsc->phyxma + plsc->phyxmi) / 2.; - y0 = (plsc->phyyma + plsc->phyymi) / 2.; - -/* Rotation matrix */ - - r11 = cos(plsc->diorot * PI / 2.); - r21 = sin(plsc->diorot * PI / 2.); - r12 = -r21; - r22 = r11; - - cost = ABS(r11); - sint = ABS(r21); - -/* Flip aspect ratio as necessary. Grungy but I don't see a better way */ - - aspect = plsc->aspect; - if (aspect == 0.) - aspect = plsc->aspdev; - - if (plsc->freeaspect) - plsc->aspori = aspect; - else - plsc->aspori = (aspect * cost + sint) / (aspect * sint + cost); - - if ( ! (plsc->difilt & PLDI_DEV)) { - plsc->difilt |= PLDI_DEV; - setdef_didev(); - } - calc_didev(); - -/* Compute scale factors */ - - lx = plsc->phyxlen; - ly = plsc->phyylen; - -/* Transformation coefficients */ - - plsc->dioxax = r11; - plsc->dioxay = r21 * (lx / ly); - plsc->dioxb = (1. - r11) * x0 - r21 * y0 * (lx / ly); - - plsc->dioyax = r12 * (ly / lx); - plsc->dioyay = r22; - plsc->dioyb = (1. - r22) * y0 - r12 * x0 * (ly / lx); -} - -/*--------------------------------------------------------------------------*\ - * void plgdiori - * - * Get plot orientation -\*--------------------------------------------------------------------------*/ - -void -c_plgdiori(PLFLT *p_rot) -{ - *p_rot = plsc->diorot; -} - -/*--------------------------------------------------------------------------*\ - * void plsdimap - * - * Set up transformation from metafile coordinates. The size of the plot is - * scaled so as to preserve aspect ratio. This isn't intended to be a - * general-purpose facility just yet (not sure why the user would need it, - * for one). -\*--------------------------------------------------------------------------*/ - -void -c_plsdimap(PLINT dimxmin, PLINT dimxmax, PLINT dimymin, PLINT dimymax, - PLFLT dimxpmm, PLFLT dimypmm) -{ - plsetvar(plsc->dimxmin, dimxmin); - plsetvar(plsc->dimxmax, dimxmax); - plsetvar(plsc->dimymin, dimymin); - plsetvar(plsc->dimymax, dimymax); - plsetvar(plsc->dimxpmm, dimxpmm); - plsetvar(plsc->dimypmm, dimypmm); - - plsc->difilt |= PLDI_MAP; - pldi_ini(); -} - -/*--------------------------------------------------------------------------*\ - * void calc_dimap - * - * Set up transformation from metafile coordinates. The size of the plot is - * scaled so as to preserve aspect ratio. This isn't intended to be a - * general-purpose facility just yet (not sure why the user would need it, - * for one). -\*--------------------------------------------------------------------------*/ - -static void -calc_dimap() -{ - PLFLT lx, ly; - PLINT pxmin, pxmax, pymin, pymax; - PLFLT dimxlen, dimylen, pxlen, pylen; - - if ((plsc->dimxmin == plsc->phyxmi) && (plsc->dimxmax == plsc->phyxma) && - (plsc->dimymin == plsc->phyymi) && (plsc->dimymax == plsc->phyyma) && - (plsc->dimxpmm == plsc->xpmm) && (plsc->dimypmm == plsc->ypmm)) { - plsc->difilt &= ~PLDI_MAP; - return; - } - -/* Set default aspect ratio */ - - lx = (plsc->dimxmax - plsc->dimxmin + 1) / plsc->dimxpmm; - ly = (plsc->dimymax - plsc->dimymin + 1) / plsc->dimypmm; - - plsc->aspdev = lx / ly; - -/* Build transformation to correct physical coordinates */ - - dimxlen = plsc->dimxmax - plsc->dimxmin; - dimylen = plsc->dimymax - plsc->dimymin; - - pxmin = plsc->phyxmi; - pxmax = plsc->phyxma; - pymin = plsc->phyymi; - pymax = plsc->phyyma; - pxlen = pxmax - pxmin; - pylen = pymax - pymin; - - plsc->dimxax = pxlen / dimxlen; - plsc->dimyay = pylen / dimylen; - plsc->dimxb = pxmin - pxlen * plsc->dimxmin / dimxlen; - plsc->dimyb = pymin - pylen * plsc->dimymin / dimylen; -} - -/*--------------------------------------------------------------------------*\ - * void plflush() - * - * Flushes the output stream. Use sparingly, if at all. -\*--------------------------------------------------------------------------*/ - -void -c_plflush(void) -{ - if (plsc->dev_flush) { - (*plsc->dispatch_table->pl_esc) ( (struct PLStream_struct *) plsc, - PLESC_FLUSH, NULL ); - } - else { - if (plsc->OutFile != NULL) - fflush(plsc->OutFile); - } -} - -/*--------------------------------------------------------------------------*\ - * Startup routines. -\*--------------------------------------------------------------------------*/ - -/*--------------------------------------------------------------------------*\ - * void pllib_init() - * - * Initialize library. Called internally by every startup routine. - * Everything you want to always be initialized before plinit() is called - * you should put here. E.g. dispatch table setup, rcfile read, etc. -\*--------------------------------------------------------------------------*/ - -void -pllib_init() -{ - if (lib_initialized) return; - lib_initialized = 1; - -#ifdef ENABLE_DYNDRIVERS -/* Create libltdl resources */ - lt_dlinit(); -#endif - -/* Initialize the dispatch table with the info from the static drivers table - and the available dynamic drivers. */ - - plInitDispatchTable(); -} - -/*--------------------------------------------------------------------------*\ - * void plstar(nx, ny) - * - * Initialize PLplot, passing in the windows/page settings. -\*--------------------------------------------------------------------------*/ - -void -c_plstar(PLINT nx, PLINT ny) -{ - pllib_init(); - - if (plsc->level != 0) - plend1(); - - plssub(nx, ny); - - c_plinit(); -} - -/*--------------------------------------------------------------------------*\ - * void plstart(devname, nx, ny) - * - * Initialize PLplot, passing the device name and windows/page settings. -\*--------------------------------------------------------------------------*/ - -void -c_plstart(const char *devname, PLINT nx, PLINT ny) -{ - pllib_init(); - - if (plsc->level != 0) - plend1(); - - plssub(nx, ny); - plsdev(devname); - - c_plinit(); -} - -/*--------------------------------------------------------------------------*\ - * void plinit() - * - * Initializes PLplot, using preset or default options. -\*--------------------------------------------------------------------------*/ - -MZ_DLLEXPORT -void * -c_plinit(void) -{ - PLFLT lx, ly, xpmm_loc, ypmm_loc, aspect_old, aspect_new; - PLINT mk = 0, sp = 0, inc = 0, del = 2000; - - pllib_init(); - - if (plsc->level != 0) - plend1(); - -/* Set stream number */ - - plsc->ipls = ipls; - -/* Set up devices */ - - pllib_devinit(); - -/* Auxiliary stream setup */ - - plstrm_init(); - -/* Initialize device & first page */ - - plP_init(); - plP_bop(); - plsc->level = 1; - -/* Calculate factor such that the character aspect ratio is preserved - * when the overall aspect ratio is changed, i.e., if portrait mode is - * requested (only honored for subset of drivers) or if the aspect ratio - * is specified in any way, or if a 90 deg rotation occurs with - * -freeaspect. */ - -/* Case where plsc->aspect has a value.... (e.g., -a aspect on the - * command line or 2nd parameter of plsdidev specified) */ - if (plsc->aspect > 0.) { - lx = plsc->phyxlen / plsc->xpmm; - ly = plsc->phyylen / plsc->ypmm; - aspect_old = lx / ly; - aspect_new = plsc->aspect; - plsc->caspfactor = sqrt(aspect_old/aspect_new); - } -/* Case of 90 deg rotations with -freeaspect (this is also how portraite - * mode is implemented for the drivers that honor -portrait). */ - else if (plsc->freeaspect && ABS(cos(plsc->diorot * PI / 2.)) <= 1.e-5) { - lx = plsc->phyxlen / plsc->xpmm; - ly = plsc->phyylen / plsc->ypmm; - aspect_old = lx / ly; - aspect_new = ly / lx; - plsc->caspfactor = sqrt(aspect_old/aspect_new); - } - - else - plsc->caspfactor = 1.; - -/* Load fonts */ - - plsc->cfont = 1; - plfntld(initfont); - -/* Set up subpages */ - - plP_subpInit(); - -/* Set up number of allowed digits before switching to scientific notation */ -/* The user can always change this */ - - if (plsc->xdigmax == 0) - plsc->xdigmax = 4; - - if (plsc->ydigmax == 0) - plsc->ydigmax = 4; - - if (plsc->zdigmax == 0) - plsc->zdigmax = 3; - -/* Switch to graphics mode and set color */ - - plgra(); - plcol(1); - - plstyl(0, &mk, &sp); - plpat(1, &inc, &del); - -/* Set clip limits. */ - - plsc->clpxmi = plsc->phyxmi; - plsc->clpxma = plsc->phyxma; - plsc->clpymi = plsc->phyymi; - plsc->clpyma = plsc->phyyma; - -/* Page aspect ratio. */ - - lx = plsc->phyxlen / plsc->xpmm; - ly = plsc->phyylen / plsc->ypmm; - plsc->aspdev = lx / ly; - -/* Initialize driver interface */ - - pldi_ini(); - -/* Apply compensating factor to original xpmm and ypmm so that - * character aspect ratio is preserved when overall aspect ratio - * is changed. This must appear here in the code because previous - * code in this routine and in routines that it calls must use the original - * values of xpmm and ypmm before the compensating factor is applied. */ - - plP_gpixmm(&xpmm_loc, &ypmm_loc); - plP_setpxl(xpmm_loc*plsc->caspfactor, ypmm_loc/plsc->caspfactor); - - return plsc->dev; -} - -/*--------------------------------------------------------------------------*\ - * void plend() - * - * End a plotting session for all open streams. -\*--------------------------------------------------------------------------*/ - -MZ_DLLEXPORT -void -c_plend(void) -{ - PLINT i; - - for (i = PL_NSTREAMS-1; i >= 0; i--) { - if (pls[i] != NULL) { - plsstrm(i); - c_plend1(); - } - } - plfontrel(); -#ifdef ENABLE_DYNDRIVERS -/* Release the libltdl resources */ - lt_dlexit(); -#endif -} - -/*--------------------------------------------------------------------------*\ - * void plend1() - * - * End a plotting session for the current stream only. After the stream is - * ended the memory associated with the stream's PLStream data structure is - * freed (for stream > 0), and the stream counter is set to 0 (the default). -\*--------------------------------------------------------------------------*/ - -void -c_plend1(void) -{ - if (plsc->level > 0) { - plP_eop(); - plP_tidy(); - plsc->level = 0; - } - -/* Free all malloc'ed stream memory */ - - free_mem(plsc->cmap0); - free_mem(plsc->cmap1); - free_mem(plsc->plwindow); - free_mem(plsc->geometry); - free_mem(plsc->dev); - free_mem(plsc->BaseName); - -/* Free malloc'ed stream if not in initial stream, else clear it out */ - - if (ipls > 0) { - free_mem(plsc); - pls[ipls] = NULL; - plsstrm(0); - } - else { - memset((char *) pls[ipls], 0, sizeof(PLStream)); - } -} - -/*--------------------------------------------------------------------------*\ - * void plsstrm - * - * Set stream number. If the data structure for a new stream is - * unallocated, we allocate it here. -\*--------------------------------------------------------------------------*/ - -void -c_plsstrm(PLINT strm) -{ - if (strm < 0 || strm >= PL_NSTREAMS) { - fprintf(stderr, - "plsstrm: Illegal stream number %d, must be in [0, %d]\n", - (int) strm, PL_NSTREAMS); - } - else { - ipls = strm; - if (pls[ipls] == NULL) { - pls[ipls] = (PLStream *) malloc((size_t) sizeof(PLStream)); - if (pls[ipls] == NULL) - plexit("plsstrm: Out of memory."); - - memset((char *) pls[ipls], 0, sizeof(PLStream)); - } - plsc = pls[ipls]; - plsc->ipls = ipls; - } -} - -/*--------------------------------------------------------------------------*\ - * void plgstrm - * - * Get current stream number. -\*--------------------------------------------------------------------------*/ - -void -c_plgstrm(PLINT *p_strm) -{ - *p_strm = ipls; -} - -/*--------------------------------------------------------------------------*\ - * void plmkstrm - * - * Creates a new stream and makes it the default. Differs from using - * plsstrm(), in that a free stream number is found, and returned. - * - * Unfortunately, I /have/ to start at stream 1 and work upward, since - * stream 0 is preallocated. One of the BIG flaws in the PLplot API is - * that no initial, library-opening call is required. So stream 0 must be - * preallocated, and there is no simple way of determining whether it is - * already in use or not. -\*--------------------------------------------------------------------------*/ - -void -c_plmkstrm(PLINT *p_strm) -{ - int i; - - for (i = 1; i < PL_NSTREAMS; i++) { - if (pls[i] == NULL) - break; - } - - if (i == PL_NSTREAMS) { - fprintf(stderr, "plmkstrm: Cannot create new stream\n"); - *p_strm = -1; - } - else { - *p_strm = i; - plsstrm(i); - } - plstrm_init(); -} - -/*--------------------------------------------------------------------------*\ - * void plstrm_init - * - * Does required startup initialization of a stream. Should be called right - * after creating one (for allocating extra memory, etc). Users shouldn't - * need to call this directly. - * - * This function can be called multiple times for a given stream, in which - * case only the first call produces any effect. For streams >= 1, which - * are created dynamically, this is called by the routine that allocates - * the stream. Stream 0, which is preallocated, is much harder to deal with - * because any of a number of different calls may be the first call to the - * library. This is handled by just calling plstrm_init() from every - * function that might be called first. Sucks, but it should work. -\*--------------------------------------------------------------------------*/ - -void -plstrm_init(void) -{ - if ( ! plsc->initialized) { - plsc->initialized = 1; - - if (plsc->cmap0 == NULL) - plscmap0n(0); - - if (plsc->cmap1 == NULL) - plscmap1n(0); - } -} - -/*--------------------------------------------------------------------------*\ - * pl_cpcolor - * - * Utility to copy one PLColor to another. -\*--------------------------------------------------------------------------*/ - -void -pl_cpcolor(PLColor *to, PLColor *from) -{ - to->r = from->r; - to->g = from->g; - to->b = from->b; -} - -/*--------------------------------------------------------------------------*\ - * void plcpstrm - * - * Copies state parameters from the reference stream to the current stream. - * Tell driver interface to map device coordinates unless flags == 1. - * - * This function is used for making save files of selected plots (e.g. - * from the TK driver). After initializing, you can get a copy of the - * current plot to the specified device by switching to this stream and - * issuing a plcpstrm() and a plreplot(), with calls to plbop() and - * pleop() as appropriate. The plot buffer must have previously been - * enabled (done automatically by some display drivers, such as X). -\*--------------------------------------------------------------------------*/ - -void -c_plcpstrm(PLINT iplsr, PLINT flags) -{ - int i; - PLStream *plsr; - - plsr = pls[iplsr]; - if (plsr == NULL) { - fprintf(stderr, "plcpstrm: stream %d not in use\n", (int) iplsr); - return; - } - -/* May be debugging */ - - plsc->debug = plsr->debug; - -/* Plot buffer -- need to copy file pointer so that plreplot() works */ -/* This also prevents inadvertent writes into the plot buffer */ - - plsc->plbufFile = plsr->plbufFile; - -/* Driver interface */ -/* Transformation must be recalculated in current driver coordinates */ - - if (plsr->difilt & PLDI_PLT) - plsdiplt(plsr->dipxmin, plsr->dipymin, plsr->dipxmax, plsr->dipymax); - - if (plsr->difilt & PLDI_DEV) - plsdidev(plsr->mar, plsr->aspect, plsr->jx, plsr->jy); - - if (plsr->difilt & PLDI_ORI) - plsdiori(plsr->diorot); - -/* Map device coordinates */ - - if ( ! (flags & 0x01)) { - pldebug("plcpstrm", "mapping parameters: %d %d %d %d %f %f\n", - plsr->phyxmi, plsr->phyxma, plsr->phyymi, plsr->phyyma, - plsr->xpmm, plsr->ypmm); - plsdimap(plsr->phyxmi, plsr->phyxma, plsr->phyymi, plsr->phyyma, - plsr->xpmm, plsr->ypmm); - } - -/* current color */ - - pl_cpcolor(&plsc->curcolor, &plsr->curcolor); - -/* cmap 0 */ - - plsc->icol0 = plsr->icol0; - plsc->ncol0 = plsr->ncol0; - if (plsc->cmap0 != NULL) - free((void *) plsc->cmap0); - - plsc->cmap0 = (PLColor *) calloc(1, plsc->ncol0 * sizeof(PLColor)); - for (i = 0; i < plsc->ncol0; i++) - pl_cpcolor(&plsc->cmap0[i], &plsr->cmap0[i]); - -/* cmap 1 */ - - plsc->icol1 = plsr->icol1; - plsc->ncol1 = plsr->ncol1; - if (plsc->cmap1 != NULL) - free((void *) plsc->cmap1); - - plsc->cmap1 = (PLColor *) calloc(1, plsc->ncol1 * sizeof(PLColor)); - for (i = 0; i < plsc->ncol1; i++) - pl_cpcolor(&plsc->cmap1[i], &plsr->cmap1[i]); - -/* Initialize if it hasn't been done yet. */ - - if (plsc->level == 0) - plinit(); -} - -/*--------------------------------------------------------------------------*\ - * pllib_devinit() - * - * Does preliminary setup of device driver. - * - * This function (previously plGetDev) used to be what is now shown as - * plSelectDev below. However, the situation is a bit more complicated now in - * the dynloadable drivers era. We now have to: - * - * 1) Make sure the dispatch table is initialized to the union of static - * drivers and available dynamic drivers (done from pllib_init now). - * 2) Allow the user to select the desired device. - * 3) Initialize the dispatch table entries for the selected device, in the - * case that it is a dynloadable driver that has not yet been loaded. - * - * Also made non-static, in order to allow some device calls to be made prior - * to calling plinit(). E.g. plframe needs to tell the X driver to create its - * internal data structure during widget construction time (using the escape - * function), but doesn't call plinit() until the plframe is actually mapped. -\*--------------------------------------------------------------------------*/ - -void -pllib_devinit() -{ - if (plsc->dev_initialized) return; - plsc->dev_initialized = 1; - - plSelectDev(); - - plLoadDriver(); - -/* offset by one since table is zero-based, but input list is not */ - plsc->dispatch_table = dispatch_table[plsc->device - 1]; -} - -#ifdef ENABLE_DYNDRIVERS - -static char* -plGetDrvDir () -{ - char* drvdir; - -/* Get drivers directory in PLPLOT_DRV_DIR or DATA_DIR/DRV_DIR, - * on this order - */ - - pldebug("plGetDrvDir", "Trying to read env var PLPLOT_DRV_DIR\n"); - drvdir = getenv ("PLPLOT_DRV_DIR"); - - if (drvdir == NULL) { - pldebug("plGetDrvDir", - "Will use drivers dir: " DATA_DIR "/" DRV_DIR "\n"); - drvdir = DATA_DIR "/" DRV_DIR; - } - - return drvdir; -} - -#endif - - -/*--------------------------------------------------------------------------*\ - * void plInitDispatchTable() - * - * ... -\*--------------------------------------------------------------------------*/ - -static int plDispatchSequencer( const void *p1, const void *p2 ) -{ - const PLDispatchTable* t1 = *(PLDispatchTable **) p1; - const PLDispatchTable* t2 = *(PLDispatchTable **) p2; - -/* printf( "sorting: t1.name=%s t1.seq=%d t2.name=%s t2.seq=%d\n", */ -/* t1->pl_DevName, t1->pl_seq, t2->pl_DevName, t2->pl_seq ); */ - - return t1->pl_seq - t2->pl_seq; -} - -static void -plInitDispatchTable() -{ - int n; - -#ifdef ENABLE_DYNDRIVERS - char buf[300]; - char* drvdir; - char *devnam, *devdesc, *devtype, *driver, *tag, *seqstr; - int seq; - int i, j, driver_found, done=0; - FILE *fp_drvdb = NULL; - DIR* dp_drvdir = NULL; - struct dirent* entry; - lt_dlhandle dlhand; - -/* Open a temporary file in which all the plD_DEVICE_INFO_ strings - will be stored */ - fp_drvdb = tmpfile (); - -/* Open the drivers directory */ - drvdir = plGetDrvDir (); - dp_drvdir = opendir (drvdir); - if (dp_drvdir == NULL) - plabort ("plInitDispatchTable: Could not open drivers directory"); - -/* Loop over each entry in the drivers directory */ - - pldebug ("plInitDispatchTable", "Scanning dyndrivers dir\n"); - while ((entry = readdir (dp_drvdir)) != NULL) - { - char* name = entry->d_name; - int len = strlen (name) - 3; - - pldebug ("plInitDispatchTable", - "Consider file %s\n", name); - -/* Only consider entries that have the ".rc" suffix */ - if ((len > 0) && (strcmp (name + len, ".rc") == 0)) { - char path[300]; - char buf[300]; - FILE* fd; - -/* Open the driver's info file */ - sprintf (path, "%s/%s", drvdir, name); - fd = fopen (path, "r"); - if (fd == NULL) { - sprintf (buf, - "plInitDispatchTable: Could not open driver info file %s\n", - name); - plabort (buf); - } - -/* Each line in the .rc file corresponds to a specific device. - * Write it to the drivers db file and take care of leading newline - * character */ - - pldebug ("plInitDispatchTable", - "Opened driver info file %s\n", name); - while (fgets (buf, 300, fd) != NULL) - { - fprintf (fp_drvdb, "%s", buf); - if ( buf [strlen (buf) - 1] != '\n' ) - fprintf (fp_drvdb, "\n"); - npldynamicdevices++; - } - fclose (fd); - } - } - -/* Make sure that the temporary file containing the driversr database - * is ready to read and close the directory handle */ - fflush (fp_drvdb); - closedir (dp_drvdir); - -#endif - -/* Allocate space for the dispatch table. */ - dispatch_table = (PLDispatchTable **) - malloc( (nplstaticdevices + npldynamicdevices) * sizeof(PLDispatchTable *) ); - -/* Initialize the dispatch table entries for the static devices by calling - the dispatch table initialization function for each static device. This - is the same function that would be called at load time for dynamic - drivers. */ - - for( n=0; n < nplstaticdevices; n++ ) - { - dispatch_table[n] = (PLDispatchTable *)malloc( sizeof(PLDispatchTable) ); - - (*static_device_initializers[n])( dispatch_table[n] ); - } - npldrivers = nplstaticdevices; - -#ifdef ENABLE_DYNDRIVERS - -/* Allocate space for the device and driver specs. We may not use all of - * these driver descriptors, but we obviously won't need more drivers than - * devices... */ - loadable_device_list = malloc( npldynamicdevices * sizeof(PLLoadableDevice) ); - loadable_driver_list = malloc( npldynamicdevices * sizeof(PLLoadableDriver) ); - - rewind( fp_drvdb ); - - i = 0; - done = !(i < npldynamicdevices); - while( !done ) { - char *p = fgets( buf, 300, fp_drvdb ); - - if (p == 0) { - done = 1; - continue; - } - - devnam = strtok( buf, ":" ); - devdesc = strtok( 0, ":" ); - devtype = strtok( 0, ":" ); - driver = strtok( 0, ":" ); - seqstr = strtok( 0, ":" ); - tag = strtok( 0, "\n" ); - - seq = atoi(seqstr); - - n = npldrivers++; - - dispatch_table[n] = malloc( sizeof(PLDispatchTable) ); - - /* Fill in the dispatch table entries. */ - dispatch_table[n]->pl_MenuStr = plstrdup(devdesc); - dispatch_table[n]->pl_DevName = plstrdup(devnam); - dispatch_table[n]->pl_type = atoi(devtype); - dispatch_table[n]->pl_seq = seq; - dispatch_table[n]->pl_init = 0; - dispatch_table[n]->pl_line = 0; - dispatch_table[n]->pl_polyline = 0; - dispatch_table[n]->pl_eop = 0; - dispatch_table[n]->pl_bop = 0; - dispatch_table[n]->pl_tidy = 0; - dispatch_table[n]->pl_state = 0; - dispatch_table[n]->pl_esc = 0; - - /* Add a record to the loadable device list */ - loadable_device_list[i].devnam = plstrdup(devnam); - loadable_device_list[i].description = plstrdup(devdesc); - loadable_device_list[i].drvnam = plstrdup(driver); - loadable_device_list[i].tag = plstrdup(tag); - - /* Now see if this driver has been seen before. If not, add a driver - * entry for it. */ - driver_found = 0; - for( j=0; j < nloadabledrivers; j++ ) - if (strcmp( driver, loadable_driver_list[j].drvnam) == 0) - { - driver_found = 1; - break; - } - - if (!driver_found) - { - loadable_driver_list[nloadabledrivers].drvnam = plstrdup(driver); - loadable_driver_list[nloadabledrivers].dlhand = 0; - nloadabledrivers++; - } - - loadable_device_list[i].drvidx = j; - - /* Get ready for next loadable device spec */ - i++; - } - -/* RML: close fp_drvdb */ - fclose (fp_drvdb); - -#endif - -/* Finally, we need to sort the list into presentation order, based on the - sequence number in the dispatch ttable entries. */ - - qsort( dispatch_table, npldrivers, sizeof(PLDispatchTable*), - plDispatchSequencer ); -} - -/*--------------------------------------------------------------------------*\ - * void plSelectDev() - * - * If the user has not already specified the output device, or the - * one specified is either: (a) not available, (b) "?", or (c) NULL, the - * user is prompted for it. - * - * Prompting quits after 10 unsuccessful tries in case the user has - * run the program in the background with insufficient input. -\*--------------------------------------------------------------------------*/ - -static void -plSelectDev() -{ - int dev, i, count, length; - char response[80]; - -/* Device name already specified. See if it is valid. */ - - if (*(plsc->DevName) != '\0' && *(plsc->DevName) != '?') { - length = strlen(plsc->DevName); - for (i = 0; i < npldrivers; i++) { - if ((*plsc->DevName == *dispatch_table[i]->pl_DevName) && - (strncmp(plsc->DevName, - dispatch_table[i]->pl_DevName, length) == 0)) - break; - } - if (i < npldrivers) { - plsc->device = i + 1; - return; - } - else { - fprintf(stderr, "Requested device %s not available\n", - plsc->DevName); - } - } - - dev = 0; - count = 0; - - if (npldrivers == 1) - dev = 1; - -/* User hasn't specified it correctly yet, so we prompt */ - - while (dev < 1 || dev > npldrivers) { - fprintf(stdout, "\nPlotting Options:\n"); - for (i = 0; i < npldrivers; i++) { - fprintf(stdout, " <%2d> %-10s %s\n", i + 1, - dispatch_table[i]->pl_DevName, - dispatch_table[i]->pl_MenuStr); - } - if (ipls == 0) - fprintf(stdout, "\nEnter device number or keyword: "); - else - fprintf(stdout, "\nEnter device number or keyword (stream %d): ", - (int) ipls); - - if (! (fgets(response, sizeof(response), stdin))) { - return; - } - - /* First check to see if device keyword was entered. */ - /* Final "\n" in response messes things up, so ignore it. */ - - length = strlen(response); - if (*(response - 1 + length) == '\n') - length--; - - for (i = 0; i < npldrivers; i++) { - if ( ! strncmp(response, dispatch_table[i]->pl_DevName, - (unsigned int) length)) - break; - } - if (i < npldrivers) { - dev = i + 1; - } - else { - if ((dev = atoi(response)) < 1) { - fprintf(stdout, "\nInvalid device: %s", response); - dev = 0; - } - } - if (count++ > 10) - plexit("plSelectDev: Too many tries."); - } - plsc->device = dev; - strcpy(plsc->DevName, dispatch_table[dev - 1]->pl_DevName); -} - -/*--------------------------------------------------------------------------*\ - * void plLoadDriver() - * - * Make sure the selected driver is loaded. Static drivers are already - * loaded, but if the user selected a dynamically loadable driver, we may - * have to take care of that now. -\*--------------------------------------------------------------------------*/ - -static void -plLoadDriver(void) -{ -#ifdef ENABLE_DYNDRIVERS - int i, drvidx; - char sym[60]; - char *tag; - - int n=plsc->device - 1; - PLDispatchTable *dev = dispatch_table[n]; - PLLoadableDriver *driver = 0; - -/* If the dispatch table is already filled in, then either the device was - * linked in statically, or else perhaps it was already loaded. In either - * case, we have nothing left to do. */ - if (dev->pl_init) - return; - - pldebug("plLoadDriver", "Device not loaded!\n"); - -/* Now search through the list of loadable devices, looking for the record - * that corresponds to the requested device. */ - for( i=0; i < npldynamicdevices; i++ ) - if (strcmp( dev->pl_DevName, loadable_device_list[i].devnam ) == 0) - break; - -/* If we couldn't find such a record, then there is some sort of internal - * logic flaw since plSelectDev is supposed to only select a valid device. - */ - if (i == npldynamicdevices) { - fprintf( stderr, "No such device: %s.\n", dev->pl_DevName ); - plexit("plLoadDriver detected device logic screwup"); - } - -/* Note the device tag, and the driver index. Note that a given driver could - * supply multiple devices, each with a unique tag to distinguish the driver - * entry points for the differnet supported devices. */ - tag = loadable_device_list[i].tag; - drvidx = loadable_device_list[i].drvidx; - - pldebug("plLoadDriver", "tag=%s, drvidx=%d\n", tag, drvidx ); - - driver = &loadable_driver_list[drvidx]; - -/* Load the driver if it hasn't been loaded yet. */ - if (!driver->dlhand) - { - char drvspec[ 400 ]; - sprintf( drvspec, "%s/%s", plGetDrvDir (), driver->drvnam ); - - pldebug("plLoadDriver", "Trying to load %s on %s\n", - driver->drvnam, drvspec ); - - driver->dlhand = lt_dlopenext( drvspec); - } - -/* If it still isn't loaded, then we're doomed. */ - if (!driver->dlhand) - { - pldebug("plLoadDriver", "lt_dlopenext failed because of " - "the following reason:\n%s\n", lt_dlerror ()); - fprintf( stderr, "Unable to load driver: %s.\n", driver->drvnam ); - plexit("Unable to load driver"); - } - -/* Now we are ready to ask the driver's device dispatch init function to - initialize the entries in the dispatch table. */ - - sprintf( sym, "plD_dispatch_init_%s", tag ); - { - PLDispatchInit dispatch_init = (PLDispatchInit) lt_dlsym( driver->dlhand, sym ); - if (!dispatch_init) - { - fprintf( stderr, - "Unable to locate dispatch table initialization function for driver: %s.\n", - driver->drvnam ); - return; - } - - (*dispatch_init)( dev ); - } -#endif -} - -/*--------------------------------------------------------------------------*\ - * void plfontld() - * - * Load specified font set. -\*--------------------------------------------------------------------------*/ - -void -c_plfontld(PLINT ifont) -{ - if (ifont != 0) - ifont = 1; - - if (plsc->level > 0) - plfntld(ifont); - else - initfont = ifont; -} - -/*--------------------------------------------------------------------------*\ - * void plreplot() - * - * Replays contents of plot buffer to current device/file. -\*--------------------------------------------------------------------------*/ - -void -c_plreplot(void) -{ - if (plsc->plbufFile != NULL) { - plRemakePlot(plsc); - } - else { - plwarn("plreplot: plot buffer not available"); - } -} - -/*--------------------------------------------------------------------------*\ - * void plgFileDevs() - * - * Returns a list of file-oriented device names and their menu strings, - * for use in a graphical interface. The caller must allocate enough - * space for (*p_menustr) and (*p_devname) to hold a pointer for each - * device -- 20 or so is plenty. E.g. char *menustr[20]. The size of - * these arrays should be passed in *p_ndev, which, on exit, holds the - * number of devices actually present. -\*--------------------------------------------------------------------------*/ - -void -plgFileDevs(char ***p_menustr, char ***p_devname, int *p_ndev) -{ - plgdevlst(*p_menustr, *p_devname, p_ndev, 0); -} - -/*--------------------------------------------------------------------------*\ - * void plgDevs() - * - * Like plgFileDevs(), but returns names and menu strings for all devices. -\*--------------------------------------------------------------------------*/ - -void -plgDevs(char ***p_menustr, char ***p_devname, int *p_ndev) -{ - plgdevlst(*p_menustr, *p_devname, p_ndev, -1); -} - -static void -plgdevlst(char **p_menustr, char **p_devname, int *p_ndev, int type) -{ - int i, j; - - pllib_init(); - - for (i = j = 0; i < npldrivers; i++) { - if (type < 0 || dispatch_table[i]->pl_type == type) { - p_menustr[j] = dispatch_table[i]->pl_MenuStr; - p_devname[j] = dispatch_table[i]->pl_DevName; - if (++j + 1 >= *p_ndev) { - plwarn("plgdevlst: too many devices"); - break; - } - } - } - p_menustr[j] = NULL; - p_devname[j] = NULL; - *p_ndev = j; -} - -/*--------------------------------------------------------------------------*\ - * Various external access routines. -\*--------------------------------------------------------------------------*/ - -/* Get output device parameters. */ - -void -c_plgpage(PLFLT *p_xp, PLFLT *p_yp, - PLINT *p_xleng, PLINT *p_yleng, PLINT *p_xoff, PLINT *p_yoff) -{ - *p_xp = plsc->xdpi; - *p_yp = plsc->ydpi; - *p_xleng = plsc->xlength; - *p_yleng = plsc->ylength; - *p_xoff = plsc->xoffset; - *p_yoff = plsc->yoffset; -} - -/* Set output device parameters. Usually ignored by the driver. */ - -MZ_DLLEXPORT -void -c_plspage(PLFLT xp, PLFLT yp, PLINT xleng, PLINT yleng, PLINT xoff, PLINT yoff) -{ - if (xp) - plsc->xdpi = xp; - if (yp) - plsc->ydpi = yp; - - if (xleng) - plsc->xlength = xleng; - if (yleng) - plsc->ylength = yleng; - - if (xoff) - plsc->xoffset = xoff; - if (yoff) - plsc->yoffset = yoff; - - plsc->pageset = 1; -} - -/* Set the number of subwindows in x and y */ - -void -c_plssub(PLINT nx, PLINT ny) -{ - if (nx > 0) - plsc->nsubx = nx; - if (ny > 0) - plsc->nsuby = ny; - -/* Force a page advance */ - - if (plsc->level > 0) { - plP_subpInit(); -/*AWI plP_eop(); - plP_bop();*/ - } -} - -/* Set the device (keyword) name */ - -MZ_DLLEXPORT -void -c_plsdev(const char *devname) -{ - if (plsc->level > 0) { - plwarn("plsdev: Must be called before plinit."); - return; - } - if (devname != NULL) { - strncpy(plsc->DevName, devname, sizeof(plsc->DevName) - 1); - plsc->DevName[sizeof(plsc->DevName) - 1] = '\0'; - } -} - -/* Get the current device (keyword) name */ -/* Note: you MUST have allocated space for this (80 characters is safe) */ - -void -c_plgdev(char *p_dev) -{ - strcpy(p_dev, plsc->DevName); -} - -/* Set the memory area to be plotted (with the 'mem' driver) as the 'dev' - member of the stream structure. Also set the number - of pixels in the memory passed in in 'plotmem'. - Plotmem is a block of memory maxy by maxx by 3 bytes long, say: - 480 x 640 x 3 (Y, X, RGB) - - This memory will be freed by the user! -*/ - -void -c_plsmem(PLINT maxx, PLINT maxy, void *plotmem) -{ - plsc->dev = plotmem; - plP_setphy (0, maxx, 0, maxy); -} - -/* Get the current stream pointer */ - -void -plgpls(PLStream **p_pls) -{ - *p_pls = plsc; -} - -/* Get the (current) run level. - * Valid settings are: - * 0 uninitialized - * 1 initialized - * 2 viewport defined - * 3 world coords defined - */ - -void -c_plglevel(PLINT *p_level) -{ - *p_level = plsc->level; -} - -/* Set the function pointer for the keyboard event handler */ - -void -plsKeyEH(void (*KeyEH) (PLGraphicsIn *, void *, int *), - void *KeyEH_data) -{ - plsc->KeyEH = KeyEH; - plsc->KeyEH_data = KeyEH_data; -} - -/* Set the function pointer for the (mouse) button event handler */ - -void -plsButtonEH(void (*ButtonEH) (PLGraphicsIn *, void *, int *), - void *ButtonEH_data) -{ - plsc->ButtonEH = ButtonEH; - plsc->ButtonEH_data = ButtonEH_data; -} - -/* Sets an optional user bop handler. */ - -void -plsbopH(void (*handler) (void *, int *), void *handler_data) -{ - plsc->bop_handler = handler; - plsc->bop_data = handler_data; -} - -/* Sets an optional user eop handler. */ - -void -plseopH(void (*handler) (void *, int *), void *handler_data) -{ - plsc->eop_handler = handler; - plsc->eop_data = handler_data; -} - -/* Set the variables to be used for storing error info */ - -void -plsError(PLINT *errcode, char *errmsg) -{ - if (errcode != NULL) - plsc->errcode = errcode; - - if (errmsg != NULL) - plsc->errmsg = errmsg; -} - -/* Set orientation. Must be done before calling plinit. */ - -void -c_plsori(PLINT ori) -{ - plsdiori((PLFLT) ori); -} - -/* - * Set pen width. Can be done any time, but before calling plinit is best - * since otherwise it may be volatile (i.e. reset on next page advance). - * If width < 0 or is unchanged by the call, nothing is done. - */ - -MZ_DLLEXPORT -void -c_plwid(PLINT width) -{ - if (width != plsc->width && width >= 0) { - plsc->width = width; - - if (plsc->level > 0) { - if ( ! plsc->widthlock) - plP_state(PLSTATE_WIDTH); - } - } -} - -/* Set the output file pointer */ - -void -plgfile(FILE **p_file) -{ - *p_file = plsc->OutFile; -} - -/* Get the output file pointer */ - -void -plsfile(FILE *file) -{ - plsc->OutFile = file; -} - -/* Get the (current) output file name. Must be preallocated to >=80 bytes */ -/* Beyond that, I truncate it. You have been warned. */ - -void -c_plgfnam(char *fnam) -{ - if (fnam == NULL) { - plabort("filename string must be preallocated to >=80 bytes"); - return; - } - - *fnam = '\0'; - if (plsc->FileName != NULL) { - strncpy(fnam, plsc->FileName, 79); - fnam[79] = '\0'; - } -} - -/* Set the output file name. */ - -MZ_DLLEXPORT -void -c_plsfnam(const char *fnam) -{ - plP_sfnam(plsc, fnam); -} - -/* Set the pause (on end-of-page) status */ - -void -c_plspause(PLINT pause) -{ - plsc->nopause = ! pause; -} - -/* Set the floating point precision (in number of places) in numeric labels. */ - -void -c_plprec(PLINT setp, PLINT prec) -{ - plsc->setpre = setp; - plsc->precis = prec; -} - -/* Get the floating point precision (in number of places) in numeric labels. */ - -void -plP_gprec(PLINT *p_setp, PLINT *p_prec) -{ - *p_setp = plsc->setpre; - *p_prec = plsc->precis; -} - -/* - * Set the escape character for text strings. - * From C you can pass as a character, from Fortran it needs to be the decimal - * ASCII value. Only selected characters are allowed to prevent the user from - * shooting himself in the foot (a '\' isn't allowed since it conflicts with - * C's use of backslash as a character escape). - */ - -void -c_plsesc(char esc) -{ - switch (esc) { - case '!': /* ASCII 33 */ - case '#': /* ASCII 35 */ - case '$': /* ASCII 36 */ - case '%': /* ASCII 37 */ - case '&': /* ASCII 38 */ - case '*': /* ASCII 42 */ - case '@': /* ASCII 64 */ - case '^': /* ASCII 94 */ - case '~': /* ASCII 126 */ - plsc->esc = esc; - break; - - default: - plwarn("plsesc: Invalid escape character, ignoring."); - } -} - -/* Get the escape character for text strings. */ - -void -plgesc(char *p_esc) -{ - if (plsc->esc == '\0') - plsc->esc = '#'; - - *p_esc = plsc->esc; -} - -/* Get the current library version number */ -/* Note: you MUST have allocated space for this (80 characters is safe) */ - -void -c_plgver(char *p_ver) -{ - strcpy(p_ver, VERSION); -} - -/* Set inferior X window */ - -void -plsxwin(PLINT window_id) -{ - plsc->window_id = window_id; -} - -/*--------------------------------------------------------------------------*\ - * These set/get information for family files, and may be called prior - * to plinit to set up the necessary parameters. Arguments: - * - * fam familying flag (boolean) - * num member number - * bmax maximum member size -\*--------------------------------------------------------------------------*/ - -/* Get family file parameters */ - -void -c_plgfam(PLINT *p_fam, PLINT *p_num, PLINT *p_bmax) -{ - *p_fam = plsc->family; - *p_num = plsc->member; - *p_bmax = plsc->bytemax; -} - -/* Set family file parameters */ - -void -c_plsfam(PLINT fam, PLINT num, PLINT bmax) -{ - if (plsc->level > 0) - plwarn("plsfam: Must be called before plinit."); - - if (fam >= 0) - plsc->family = fam; - if (num >= 0) - plsc->member = num; - if (bmax >= 0) - plsc->bytemax = bmax; -} - -/* Advance to the next family file on the next new page */ - -void -c_plfamadv(void) -{ - plsc->famadv = 1; -} - -/*--------------------------------------------------------------------------*\ - * Interface routines for axis labling parameters. - * See pldtik.c for more info. -\*--------------------------------------------------------------------------*/ - -/* Get x axis labeling parameters */ - -void -c_plgxax(PLINT *p_digmax, PLINT *p_digits) -{ - *p_digmax = plsc->xdigmax; - *p_digits = plsc->xdigits; -} - -/* Set x axis labeling parameters */ - -void -c_plsxax(PLINT digmax, PLINT digits) -{ - plsc->xdigmax = digmax; - plsc->xdigits = digits; -} - -/* Get y axis labeling parameters */ - -void -c_plgyax(PLINT *p_digmax, PLINT *p_digits) -{ - *p_digmax = plsc->ydigmax; - *p_digits = plsc->ydigits; -} - -/* Set y axis labeling parameters */ - -void -c_plsyax(PLINT digmax, PLINT digits) -{ - plsc->ydigmax = digmax; - plsc->ydigits = digits; -} - -/* Get z axis labeling parameters */ - -void -c_plgzax(PLINT *p_digmax, PLINT *p_digits) -{ - *p_digmax = plsc->zdigmax; - *p_digits = plsc->zdigits; -} - -/* Set z axis labeling parameters */ - -void -c_plszax(PLINT digmax, PLINT digits) -{ - plsc->zdigmax = digmax; - plsc->zdigits = digits; -} - -/* Get character default height and current (scaled) height */ - -void -c_plgchr(PLFLT *p_def, PLFLT *p_ht) -{ - *p_def = plsc->chrdef; - *p_ht = plsc->chrht; -} - -/* Get viewport boundaries in normalized device coordinates */ - -void -c_plgvpd(PLFLT *p_xmin, PLFLT *p_xmax, PLFLT *p_ymin, PLFLT *p_ymax) -{ - *p_xmin = plsc->vpdxmi; - *p_xmax = plsc->vpdxma; - *p_ymin = plsc->vpdymi; - *p_ymax = plsc->vpdyma; -} - -/* Get viewport boundaries in world coordinates */ - -void -c_plgvpw(PLFLT *p_xmin, PLFLT *p_xmax, PLFLT *p_ymin, PLFLT *p_ymax) -{ - *p_xmin = plsc->vpwxmi; - *p_xmax = plsc->vpwxma; - *p_ymin = plsc->vpwymi; - *p_ymax = plsc->vpwyma; -} - -/*--------------------------------------------------------------------------*\ - * These should not be called by the user. -\*--------------------------------------------------------------------------*/ - -/* 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) -{ - *p_xmin = plsc->domxmi; - *p_xmax = plsc->domxma; - *p_ymin = plsc->domymi; - *p_ymax = plsc->domyma; -} - -/* Get vertical (z) scale parameters for 3-d plot */ - -void -plP_grange(PLFLT *p_zscl, PLFLT *p_zmin, PLFLT *p_zmax) -{ - *p_zscl = plsc->zzscl; - *p_zmin = plsc->ranmi; - *p_zmax = plsc->ranma; -} - -/* Get parameters used in 3d plots */ - -void -plP_gw3wc(PLFLT *p_dxx, PLFLT *p_dxy, PLFLT *p_dyx, PLFLT *p_dyy, PLFLT *p_dyz) -{ - *p_dxx = plsc->cxx; - *p_dxy = plsc->cxy; - *p_dyx = plsc->cyx; - *p_dyy = plsc->cyy; - *p_dyz = plsc->cyz; -} - -/* Get clip boundaries in physical coordinates */ - -void -plP_gclp(PLINT *p_ixmin, PLINT *p_ixmax, PLINT *p_iymin, PLINT *p_iymax) -{ - *p_ixmin = plsc->clpxmi; - *p_ixmax = plsc->clpxma; - *p_iymin = plsc->clpymi; - *p_iymax = plsc->clpyma; -} - -/* Set clip boundaries in physical coordinates */ - -void -plP_sclp(PLINT ixmin, PLINT ixmax, PLINT iymin, PLINT iymax) -{ - plsc->clpxmi = ixmin; - plsc->clpxma = ixmax; - plsc->clpymi = iymin; - plsc->clpyma = iymax; -} - -/* Get physical device limits in physical coordinates */ - -void -plP_gphy(PLINT *p_ixmin, PLINT *p_ixmax, PLINT *p_iymin, PLINT *p_iymax) -{ - *p_ixmin = plsc->phyxmi; - *p_ixmax = plsc->phyxma; - *p_iymin = plsc->phyymi; - *p_iymax = plsc->phyyma; -} - -/* Get number of subpages on physical device and current subpage */ - -void -plP_gsub(PLINT *p_nx, PLINT *p_ny, PLINT *p_cs) -{ - *p_nx = plsc->nsubx; - *p_ny = plsc->nsuby; - *p_cs = plsc->cursub; -} - -/* Set number of subpages on physical device and current subpage */ - -void -plP_ssub(PLINT nx, PLINT ny, PLINT cs) -{ - plsc->nsubx = nx; - plsc->nsuby = ny; - plsc->cursub = cs; -} - -/* Get number of pixels to a millimeter */ - -void -plP_gpixmm(PLFLT *p_x, PLFLT *p_y) -{ - *p_x = plsc->xpmm; - *p_y = plsc->ypmm; -} - -/* All the drivers call this to set physical pixels/mm. */ - -void -plP_setpxl(PLFLT xpmm, PLFLT ypmm) -{ - plsc->xpmm = xpmm; - plsc->ypmm = ypmm; - plsc->umx = 1000.0 / plsc->xpmm; - plsc->umy = 1000.0 / plsc->ypmm; -} - -/* Sets up physical limits of plotting device. */ - -void -plP_setphy(PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax) -{ - if (xmin > xmax || ymin > ymax) - plexit("plP_setphy: device minima must not exceed maxima"); - - plsc->phyxmi = xmin; - plsc->phyxma = xmax; - plsc->phyymi = ymin; - plsc->phyyma = ymax; - plsc->phyxlen = xmax - xmin; - plsc->phyylen = ymax - ymin; -} - -/*--------------------------------------------------------------------------*\ - * void c_plscompression() - * - * Set compression. - * Has to be done before plinit. -\*--------------------------------------------------------------------------*/ - -void -c_plscompression(PLINT compression) -{ - if (plsc->level <= 0) - { - plsc->dev_compression=compression; - } -} - -/*--------------------------------------------------------------------------*\ - * void c_plgcompression() - * - * Get compression -\*--------------------------------------------------------------------------*/ - -void -c_plgcompression(PLINT *compression) -{ - *compression = plsc->dev_compression; -} - - -/*--------------------------------------------------------------------------*\ - * void plP_getinitdriverlist() - * - * Check to see if a driver/stream has been initialised - * Returns a space separated list of matches streams/drivers - * If more than one stream uses the same device, then the device name - * will be returned for each stream. - * Caller must allocate enough memory for "names" to hold the answer. -\*--------------------------------------------------------------------------*/ - -void -plP_getinitdriverlist(char *names) -{ -int i; - -for (i=0;iDevName); - else - { - strcat(names," "); - strcat(names,pls[i]->DevName); - } - } - else - break; - } -} - - -/*--------------------------------------------------------------------------*\ - * PLINT plP_checkdriverinit() - * - * Checks from a list of given drivers which ones have been initialised - * and returns the number of devices matching the list, or -1 if in error. - * Effectively returns the number of streams matching the given stream. -\*--------------------------------------------------------------------------*/ - -PLINT plP_checkdriverinit( char *names) -{ -char *buff; -char *tok=NULL; -PLINT ret=0; /* set up return code to 0, the value if no devices match*/ - -buff=(char *)malloc((size_t) PL_NSTREAMS*8); /* Allocate enough memory for 8 - characters for each possible stream */ - -if (buff!=NULL) - { - memset(buff,0,PL_NSTREAMS*8); /* Make sure we clear it */ - plP_getinitdriverlist(buff); /* Get the list of initialised devices */ - - for (tok = strtok(buff, " ,"); /* Check each device against the "name" */ - tok; tok=strtok(0, " ,")) /* supplied to the subroutine */ - { - if (strstr(names,tok)!=NULL) /* Check to see if the device has been initialised */ - { - ret++; /* Bump the return code if it has */ - } - } - free(buff); /* Clear up that memory we allocated */ - } -else - ret=-1; /* Error flag */ - -return(ret); -} - - -/*--------------------------------------------------------------------------*\ - * plP_image - * - * Author: Alessandro Mirone, Nov 2001 - * - * - * -\*--------------------------------------------------------------------------*/ - -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) -{ - PLINT i, npts; - short *xscl, *yscl; - int plbuf_write; - - plsc->page_status = DRAWING; - - if (plsc->dev_fastimg == 0) { - plimageslow(x, y, z, nx-1, ny-1, - xmin, ymin, dx, dy, zmin, zmax); - return ; - } - - if (plsc->plbuf_write) { - IMG_DT img_dt; - - img_dt.xmin=xmin; - img_dt.ymin=ymin; - img_dt.dx=dx; - img_dt.dy=dy; - - plsc->dev_ix = x; - plsc->dev_iy = y; - plsc->dev_z = z; - plsc->dev_nptsX = nx; - plsc->dev_nptsY = ny; - plsc->dev_zmin = zmin; - plsc->dev_zmax = zmax; - - plbuf_esc(plsc, PLESC_IMAGE, &img_dt); - } - - /* avoid re-saving plot buffer while in plP_esc() */ - plbuf_write = plsc->plbuf_write; - plsc->plbuf_write = 0; - - npts = nx*ny; - if (plsc->difilt) { /* isn't this odd? when replaying the plot buffer, e.g., when resizing the window, difilt() is caled again! the plot buffer should already contain the transformed data--it would save a lot of time! (and allow for differently oriented plots when in multiplot mode) */ - PLINT clpxmi, clpxma, clpymi, clpyma; - - xscl = (short *) malloc(nx*ny*sizeof(short)); - yscl = (short *) malloc(nx*ny*sizeof(short)); - for (i = 0; i < npts; i++) { - xscl[i] = x[i]; - yscl[i] = y[i]; - } - sdifilt(xscl, yscl, npts, &clpxmi, &clpxma, &clpymi, &clpyma); - plsc->imclxmin = clpxmi; - plsc->imclymin = clpymi; - plsc->imclxmax = clpxma; - plsc->imclymax = clpyma; - grimage(xscl, yscl, z, nx, ny); - free(xscl); - free(yscl); - } else { - plsc->imclxmin = plsc->phyxmi; - plsc->imclymin = plsc->phyymi; - plsc->imclxmax = plsc->phyxma; - plsc->imclymax = plsc->phyyma; - grimage(x, y, z, nx, ny ); - } - plsc->plbuf_write = plbuf_write; -} diff --git a/src/plot/plplot/plcore.h b/src/plot/plplot/plcore.h deleted file mode 100644 index 00af09accf..0000000000 --- a/src/plot/plplot/plcore.h +++ /dev/null @@ -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 -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 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__ */ diff --git a/src/plot/plplot/plctrl.c b/src/plot/plplot/plctrl.c deleted file mode 100644 index b5ed250667..0000000000 --- a/src/plot/plplot/plctrl.c +++ /dev/null @@ -1,1745 +0,0 @@ -/* $Id: plctrl.c,v 1.3 2005/03/18 20:32:41 eli Exp $ - - Misc. control routines, like begin, end, exit, change graphics/text - mode, change color. Includes some spillage from plcore.c. If you - don't know where it should go, put it here. -*/ - -#define DEBUG - -#define NEED_PLDEBUG -#include "plplotP.h" -#ifdef macintosh -#include "mac.h" -/* for plMacLibOpen prototype; used in plLibOpen */ -#endif - -#ifdef DJGPP /* dos386/djgpp */ -#ifdef __unix -#undef __unix -#endif -#endif - -#ifdef __unix -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif -#include -#endif - -/* Static functions */ - -/* Used by any external init code to suggest a path */ -MZ_DLLEXPORT -char* plplotLibDir = 0; - -static void -color_set(PLINT i, U_CHAR r, U_CHAR g, U_CHAR b, char *name ); - -static void -strcat_delim(char *dirspec); - -static int -(*exit_handler) (char *errormsg); - -static void -plcmap0_def(int imin, int imax); - -static void -plcmap1_def(void); - -static PLFLT -value(double n1, double n2, double hue); - -/* An additional hardwired location for lib files. */ -/* I have no plans to change these again, ever. */ - -#if defined(DJGPP) -#ifndef PLLIBDEV -#define PLLIBDEV "c:/plplot/lib" -#endif - -#elif defined(MSDOS) -#ifndef PLLIBDEV -#define PLLIBDEV "c:\\plplot\\lib" -#endif - -#else - -/* Anything else is assumed to be Unix */ - -#ifndef PLLIBDEV -#define PLLIBDEV "/usr/local/plplot/lib" -#endif - -#endif - -/*--------------------------------------------------------------------------*\ - * Routines that deal with colors & color maps. -\*--------------------------------------------------------------------------*/ - -/*--------------------------------------------------------------------------*\ - * plcol0() - * - * Set color, map 0. Argument is integer between 0 and plsc->ncol0. -\*--------------------------------------------------------------------------*/ - -MZ_DLLEXPORT -void -c_plcol0(PLINT icol0) -{ - if (plsc->level < 1) { - plabort("plcol0: Please call plinit first"); - return; - } - if (icol0 < 0 || icol0 >= plsc->ncol0) { - char buffer[256]; - sprintf(buffer, "plcol0: Invalid color map entry: %d", (int) icol0); - plabort(buffer); - return; - } - - plsc->icol0 = icol0; - plsc->curcolor.r = plsc->cmap0[icol0].r; - plsc->curcolor.g = plsc->cmap0[icol0].g; - plsc->curcolor.b = plsc->cmap0[icol0].b; - - plsc->curcmap = 0; - plP_state(PLSTATE_COLOR0); -} - -/*--------------------------------------------------------------------------*\ - * plcol1() - * - * Set color, map 1. Argument is a float between 0. and 1. -\*--------------------------------------------------------------------------*/ - -void -c_plcol1(PLFLT col1) -{ - PLINT icol1; - - if (plsc->level < 1) { - plabort("plcol1: Please call plinit first"); - return; - } - if (col1 < 0 || col1 > 1) { - char buffer[256]; - sprintf(buffer, "plcol1: Invalid color map position: %f", (PLFLT) col1); - plabort(buffer); - return; - } - - icol1 = col1 * plsc->ncol1; - icol1 = MIN(icol1, plsc->ncol1-1); - - plsc->icol1 = icol1; - plsc->curcolor.r = plsc->cmap1[plsc->icol1].r; - plsc->curcolor.g = plsc->cmap1[plsc->icol1].g; - plsc->curcolor.b = plsc->cmap1[plsc->icol1].b; - - plsc->curcmap = 1; - plP_state(PLSTATE_COLOR1); -} - -/*--------------------------------------------------------------------------*\ - * plscolbg() - * - * Set the background color (cmap0[0]) by 8 bit RGB value -\*--------------------------------------------------------------------------*/ - -MZ_DLLEXPORT -void -c_plscolbg(PLINT r, PLINT g, PLINT b) -{ - plscol0(0, r, g, b); -} - -/*--------------------------------------------------------------------------*\ - * plgcolbg() - * - * Returns the background color (cmap0[0]) by 8 bit RGB value -\*--------------------------------------------------------------------------*/ - -void -c_plgcolbg(PLINT *r, PLINT *g, PLINT *b) -{ - plgcol0(0, r, g, b); -} - -/*--------------------------------------------------------------------------*\ - * plscol0() - * - * Set a given color from color map 0 by 8 bit RGB value - * Does not result in any additional cells to be allocated. -\*--------------------------------------------------------------------------*/ - -MZ_DLLEXPORT -void -c_plscol0(PLINT icol0, PLINT r, PLINT g, PLINT b) -{ - if (plsc->cmap0 == NULL) - plscmap0n(0); - - if (icol0 < 0 || icol0 >= plsc->ncol0) { - char buffer[256]; - sprintf(buffer, "plscol0: Illegal color table value: %d", (int) icol0); - plabort(buffer); - return; - } - if ((r < 0 || r > 255) || (g < 0 || g > 255) || (b < 0 || b > 255)) { - char buffer[256]; - sprintf(buffer, "plscol0: Invalid RGB color: %d, %d, %d", - (int) r, (int) g, (int) b); - plabort(buffer); - return; - } - - plsc->cmap0[icol0].r = r; - plsc->cmap0[icol0].g = g; - plsc->cmap0[icol0].b = b; - - if (plsc->level > 0) - plP_state(PLSTATE_CMAP0); -} - -/*--------------------------------------------------------------------------*\ - * plgcol0() - * - * Returns 8 bit RGB values for given color from color map 0 - * Values are negative if an invalid color id is given -\*--------------------------------------------------------------------------*/ - -void -c_plgcol0(PLINT icol0, PLINT *r, PLINT *g, PLINT *b) -{ - if (plsc->cmap0 == NULL) - plscmap0n(0); - - *r = -1; - *g = -1; - *b = -1; - - if (icol0 < 0 || icol0 > plsc->ncol0) { - char buffer[256]; - sprintf(buffer, "plgcol0: Invalid color index: %d", (int) icol0); - plabort(buffer); - return; - } - - *r = plsc->cmap0[icol0].r; - *g = plsc->cmap0[icol0].g; - *b = plsc->cmap0[icol0].b; - - return; -} - -/*--------------------------------------------------------------------------*\ - * plscmap0() - * - * Set color map 0 colors by 8 bit RGB values. This sets the entire color - * map -- only as many colors as specified will be allocated. -\*--------------------------------------------------------------------------*/ - -void -c_plscmap0(PLINT *r, PLINT *g, PLINT *b, PLINT ncol0) -{ - int i; - - plscmap0n(ncol0); - - for (i = 0; i < plsc->ncol0; i++) { - if ((r[i] < 0 || r[i] > 255) || - (g[i] < 0 || g[i] > 255) || - (b[i] < 0 || b[i] > 255)) { - - char buffer[256]; - sprintf(buffer, "plscmap0: Invalid RGB color: %d, %d, %d", - (int) r[i], (int) g[i], (int) b[i]); - plabort(buffer); - return; - } - - plsc->cmap0[i].r = r[i]; - plsc->cmap0[i].g = g[i]; - plsc->cmap0[i].b = b[i]; - } - - if (plsc->level > 0) - plP_state(PLSTATE_CMAP0); -} - -/*--------------------------------------------------------------------------*\ - * plscmap1() - * - * Set color map 1 colors by 8 bit RGB values - * This also sets the number of colors. -\*--------------------------------------------------------------------------*/ - -void -c_plscmap1(PLINT *r, PLINT *g, PLINT *b, PLINT ncol1) -{ - int i; - - plscmap1n(ncol1); - - for (i = 0; i < plsc->ncol1; i++) { - if ((r[i] < 0 || r[i] > 255) || - (g[i] < 0 || g[i] > 255) || - (b[i] < 0 || b[i] > 255)) { - - char buffer[256]; - sprintf(buffer, "plscmap1: Invalid RGB color: %d, %d, %d", - (int) r[i], (int) g[i], (int) b[i]); - plabort(buffer); - return; - } - plsc->cmap1[i].r = r[i]; - plsc->cmap1[i].g = g[i]; - plsc->cmap1[i].b = b[i]; - } - - if (plsc->level > 0) - plP_state(PLSTATE_CMAP1); -} - -/*--------------------------------------------------------------------------*\ - * plscmap1l() - * - * Set color map 1 colors using a piece-wise linear relationship between - * position in the color map (from 0 to 1) and position in HLS or RGB color - * space. May be called at any time. - * - * The idea here is to specify a number of control points that specify the - * mapping between HLS (or RGB or CMY) and palette 1 value. Between these - * points, linear interpolation is used. By mapping position in the color - * map to function value, this gives a smooth variation of color with - * intensity. Any number of control points may be specified, located at - * arbitrary positions (intensities), although typically 2 - 4 are enough. - * Another way of stating this is that we are traversing a given number of - * lines through HLS (or RGB) space as we move through cmap 1 entries. The - * control points at the minimum and maximum intensity (0 and 1) must - * always be specified. By adding more control points you can get more - * variation. One good technique for plotting functions that vary about - * some expected average is to use an additional 2 control points in the - * center (intensity ~= 0.5) that are the same color as the background - * (typically white for paper output, black for crt), and same hue as the - * boundary control points. This allows the highs and lows to be very - * easily distinguished. - * - * Each control point must specify the position in cmap 1 as well as three - * coordinates in HLS or RGB space. The first point MUST correspond to - * position = 0, and the last to position = 1. - * - * The hue is interpolated around the "front" of the color wheel - * (red<->green<->blue<->red) unless the "rev" flag is set, in which case - * interpolation proceeds around the back (reverse) side. Specifying - * rev=NULL is equivalent to setting rev[]=0 for every control point. - * - * Bounds on RGB coordinates: - * R,G,B [0, 1] magnitude - * - * Bounds on HLS coordinates: - * hue [0, 360] degrees - * lightness [0, 1] magnitude - * saturation [0, 1] magnitude - * - * The inputs are: - * itype 0: HLS, 1: RGB - * npts number of control points - * pos[] position for each control point - * coord1[] first coordinate for each control point - * coord2[] second coordinate for each control point - * coord3[] third coordinate for each control point - * rev[] reverse flag for each control point -\*--------------------------------------------------------------------------*/ - -MZ_DLLEXPORT -void -c_plscmap1l(PLINT itype, PLINT npts, PLFLT *pos, - PLFLT *coord1, PLFLT *coord2, PLFLT *coord3, PLINT *rev) -{ - int n; - PLFLT h, l, s, r, g, b; - - if (npts < 2) { - plabort("plscmap1l: Must specify at least two control points"); - return; - } - - if ( (pos[0] != 0) || (pos[npts-1] != 1)) { - plabort("plscmap1l: First, last control points must lie on boundary"); - return; - } - - if ( npts > PL_MAX_CMAP1CP ) { - plabort("plscmap1l: exceeded maximum number of control points"); - return; - } - -/* Allocate if not done yet */ - - if (plsc->cmap1 == NULL) - plscmap1n(0); - -/* Save control points */ - - plsc->ncp1 = npts; - - for (n = 0; n < npts; n++) { - - if (itype == 0) { - h = coord1[n]; - l = coord2[n]; - s = coord3[n]; - } - else { - r = coord1[n]; - g = coord2[n]; - b = coord3[n]; - plRGB_HLS(r, g, b, &h, &l, &s); - } - - plsc->cmap1cp[n].h = h; - plsc->cmap1cp[n].l = l; - plsc->cmap1cp[n].s = s; - plsc->cmap1cp[n].p = pos[n]; - - if (rev == NULL) - plsc->cmap1cp[n].rev = 0; - else - plsc->cmap1cp[n].rev = rev[n]; - } - -/* Calculate and set color map */ - - plcmap1_calc(); -} - -/*--------------------------------------------------------------------------*\ - * plcmap1_calc() - * - * Bin up cmap 1 space and assign colors to make inverse mapping easy. - * Always do interpolation in HLS space. -\*--------------------------------------------------------------------------*/ - -void -plcmap1_calc(void) -{ - int i, n; - PLFLT delta, dp, dh, dl, ds; - PLFLT h, l, s, p, r, g, b; - -/* Loop over all control point pairs */ - - for (n = 0; n < plsc->ncp1-1; n++) { - - if ( plsc->cmap1cp[n].p == plsc->cmap1cp[n+1].p ) - continue; - - /* Differences in p, h, l, s between ctrl pts */ - - dp = plsc->cmap1cp[n+1].p - plsc->cmap1cp[n].p; - dh = plsc->cmap1cp[n+1].h - plsc->cmap1cp[n].h; - dl = plsc->cmap1cp[n+1].l - plsc->cmap1cp[n].l; - ds = plsc->cmap1cp[n+1].s - plsc->cmap1cp[n].s; - - /* Adjust dh if we are to go around "the back side" */ - - if (plsc->cmap1cp[n].rev) - dh = (dh > 0) ? dh-360 : dh+360; - - /* Loop over all color cells. Only interested in cells located (in */ - /* cmap1 space) between n_th and n+1_th control points */ - - for (i = 0; i < plsc->ncol1; i++) { - p = (double) i / (plsc->ncol1 - 1.0); - if ( (p < plsc->cmap1cp[n].p) || - (p > plsc->cmap1cp[n+1].p) ) - continue; - - /* Interpolate based on position of color cell in cmap1 space */ - - delta = (p - plsc->cmap1cp[n].p) / dp; - - /* Linearly interpolate to get color cell h, l, s values */ - - h = plsc->cmap1cp[n].h + dh * delta; - l = plsc->cmap1cp[n].l + dl * delta; - s = plsc->cmap1cp[n].s + ds * delta; - - while (h >= 360.) - h -= 360.; - - while (h < 0.) - h += 360.; - - plHLS_RGB(h, l, s, &r, &g, &b); - - plsc->cmap1[i].r = MAX(0, MIN(255, (int) (256. * r))); - plsc->cmap1[i].g = MAX(0, MIN(255, (int) (256. * g))); - plsc->cmap1[i].b = MAX(0, MIN(255, (int) (256. * b))); - } - } - - if (plsc->level > 0) - plP_state(PLSTATE_CMAP1); -} - -/*--------------------------------------------------------------------------*\ - * plscmap0n() - * - * Set number of colors in cmap 0, (re-)allocate cmap 0, and fill with - * default values for those colors not previously allocated (and less - * than index 15, after that you just get grey). - * - * The driver is not guaranteed to support all of these. -\*--------------------------------------------------------------------------*/ - -void -c_plscmap0n(PLINT ncol0) -{ - int ncol, size, imin, imax; - -/* No change */ - - if (ncol0 > 0 && plsc->ncol0 == ncol0) - return; - -/* Handle all possible startup conditions */ - - if (plsc->ncol0 <= 0 && ncol0 <= 0) - ncol = 16; - else if (ncol0 <= 0) - ncol = plsc->ncol0; - else - ncol = ncol0; - - imax = ncol-1; - size = ncol * sizeof(PLColor); - -/* Allocate the space */ - - if (plsc->cmap0 == NULL) { - plsc->cmap0 = (PLColor *) calloc(1, size); - imin = 0; - } - else { - plsc->cmap0 = (PLColor *) realloc(plsc->cmap0, size); - imin = plsc->ncol0; - } - -/* Fill in default entries */ - - plsc->ncol0 = ncol; - plcmap0_def(imin, imax); -} - -/*--------------------------------------------------------------------------*\ - * plscmap1n() - * - * Set number of colors in cmap 1, (re-)allocate cmap 1, and set default - * values if this is the first allocation. - * - * Note that the driver is allowed to disregard this number. - * In particular, most use fewer than we use internally. -\*--------------------------------------------------------------------------*/ - -MZ_DLLEXPORT -void -c_plscmap1n(PLINT ncol1) -{ - int ncol, size; - -/* No change */ - - if (ncol1 > 0 && plsc->ncol1 == ncol1) - return; - -/* Handle all possible startup conditions */ - - if (plsc->ncol1 <= 0 && ncol1 <= 0) - ncol = 128; - else if (ncol1 <= 0) - ncol = plsc->ncol1; - else - ncol = ncol1; - - size = ncol * sizeof(PLColor); - -/* Allocate the space */ - - if (plsc->ncol1 > 0) - plsc->cmap1 = (PLColor *) realloc(plsc->cmap1, size); - else - plsc->cmap1 = (PLColor *) calloc(ncol, sizeof(PLColor)); - -/* Fill in default entries */ - - plsc->ncol1 = ncol; - if (plsc->ncp1 == 0) - plcmap1_def(); - else - plcmap1_calc(); -} - -/*--------------------------------------------------------------------------*\ - * color_set() - * - * Initializes color table entry by RGB values. -\*--------------------------------------------------------------------------*/ - -static void -color_set(PLINT i, U_CHAR r, U_CHAR g, U_CHAR b, char *name ) -{ - plsc->cmap0[i].r = r; - plsc->cmap0[i].g = g; - plsc->cmap0[i].b = b; - plsc->cmap0[i].name = name; -} - -/*--------------------------------------------------------------------------*\ - * plcmap0_def() - * - * Initializes specified color map 0 color entry to its default. - * - * Initial RGB values for color map 0 taken from X11R6 - * (XFree86-3.3.6) X-windows - * rgb.txt file, and may not accurately represent the described colors on - * all systems. -\*--------------------------------------------------------------------------*/ - -#define color_def(i, r, g, b, n) \ -if (i >= imin && i <= imax) color_set(i, r, g, b, n); - -static void -plcmap0_def(int imin, int imax) -{ - int i; - - color_def(0, 0, 0, 0, "black" ); /* black */ - color_def(1, 255, 0, 0, "red"); /* red */ - color_def(2, 255, 255, 0, "yellow" ); /* yellow */ - color_def(3, 0, 255, 0, "green" ); /* green */ - color_def(4, 127, 255, 212, "aquamarine" ); /* aquamarine */ - color_def(5, 255, 192, 203, "pink" ); /* pink */ - color_def(6, 245, 222, 179, "wheat" ); /* wheat */ - color_def(7, 190, 190, 190, "grey" ); /* grey */ - color_def(8, 165, 42, 42, "brown" ); /* brown */ - color_def(9, 0, 0, 255, "blue" ); /* blue */ - color_def(10, 138, 43, 226, "BlueViolet" ); /* Blue Violet */ - color_def(11, 0, 255, 255, "cyan" ); /* cyan */ - color_def(12, 64, 224, 208, "turquoise" ); /* turquoise */ - color_def(13, 255, 0, 255, "magenta" ); /* magenta */ - color_def(14, 250, 128, 114, "salmon" ); /* salmon */ - color_def(15, 255, 255, 255, "white" ); /* white */ - -/* Any others are just arbitrarily set */ - - for (i = 16; i <= imax; i++) - color_def(i, 255, 0, 0, "red"); /* red */ -} - -/*--------------------------------------------------------------------------*\ - * plcmap1_def() - * - * Initializes color map 1. - * - * The default initialization uses 6 control points in HLS space, the inner - * ones being very close to one of the vertices of the HLS double cone. The - * vertex used (black or white) is chosen to be the closer to the background - * color. The 6 points were chosen over the older 4 points in order to make - * weaker structures more easily visible, and give more control through the - * palette editor. If you don't like these settings.. change them! -\*--------------------------------------------------------------------------*/ - -static void -plcmap1_def(void) -{ - PLFLT i[6], h[6], l[6], s[6], midpt = 0., vertex = 0.; - -/* Positions of control points */ - - i[0] = 0; /* left boundary */ - i[1] = 0.44; /* a little left of center */ - i[2] = 0.50; /* at center */ - i[3] = 0.50; /* at center */ - i[4] = 0.56; /* a little right of center */ - i[5] = 1; /* right boundary */ - -/* For center control points, pick black or white, whichever is closer to bg */ -/* Be carefult to pick just short of top or bottom else hue info is lost */ - - if (plsc->cmap0 != NULL) - vertex = ((PLFLT) plsc->cmap0[0].r + - (PLFLT) plsc->cmap0[0].g + - (PLFLT) plsc->cmap0[0].b) / 3. / 255.; - - if (vertex < 0.5) { - vertex = 0.01; - midpt = 0.10; - } else { - vertex = 0.99; - midpt = 0.90; - } - -/* Set hue */ - - h[0] = 260; /* low: blue-violet */ - h[1] = 260; /* only change as we go over vertex */ - h[2] = 260; /* only change as we go over vertex */ - h[3] = 0; /* high: red */ - h[4] = 0; /* high: red */ - h[5] = 0; /* keep fixed */ - -/* Set lightness */ - - l[0] = 0.5; /* low */ - l[1] = midpt; /* midpoint value */ - l[2] = vertex; /* bg */ - l[3] = vertex; /* bg */ - l[4] = midpt; /* midpoint value */ - l[5] = 0.5; /* high */ - -/* Set saturation -- keep at maximum */ - - s[0] = 1; - s[1] = 1; - s[2] = 1; - s[3] = 1; - s[4] = 1; - s[5] = 1; - - c_plscmap1l(0, 6, i, h, l, s, NULL); -} - -/*--------------------------------------------------------------------------*\ - * plscolor() - * - * Used to globally turn color output on/off -\*--------------------------------------------------------------------------*/ - -void -c_plscolor(PLINT color) -{ - plsc->colorset = 1; - plsc->color = color; -} - -/*--------------------------------------------------------------------------*\ - * plrgb() - * - * Set line color by red, green, blue from 0. to 1. - * Do NOT use this. Only retained for backward compatibility -\*--------------------------------------------------------------------------*/ - -void -c_plrgb(PLFLT r, PLFLT g, PLFLT b) -{ - if (plsc->level < 1) { - plabort("plrgb: Please call plinit first"); - return; - } - - plsc->icol0 = PL_RGB_COLOR; - plsc->curcolor.r = MAX(0, MIN(255, (int) (256. * r))); - plsc->curcolor.g = MAX(0, MIN(255, (int) (256. * g))); - plsc->curcolor.b = MAX(0, MIN(255, (int) (256. * b))); - - plsc->curcmap = 0; - plP_state(PLSTATE_COLOR0); -} - -/*--------------------------------------------------------------------------*\ - * plrgb1() - * - * Set line color by 8 bit RGB values. - * Do NOT use this. Only retained for backward compatibility -\*--------------------------------------------------------------------------*/ - -void -c_plrgb1(PLINT r, PLINT g, PLINT b) -{ - if (plsc->level < 1) { - plabort("plrgb1: Please call plinit first"); - return; - } - if ((r < 0 || r > 255) || (g < 0 || g > 255) || (b < 0 || b > 255)) { - plabort("plrgb1: Invalid color"); - return; - } - - plsc->icol0 = PL_RGB_COLOR; - plsc->curcolor.r = r; - plsc->curcolor.g = g; - plsc->curcolor.b = b; - - plsc->curcmap = 0; - plP_state(PLSTATE_COLOR0); -} - -/*--------------------------------------------------------------------------*\ - * void plhls() - * - * Set current color by hue, lightness, and saturation. - * Convert hls color coordinates to rgb, then call plrgb. - * Do NOT use this. Only retained for backward compatibility -\*--------------------------------------------------------------------------*/ - -void -c_plhls(PLFLT h, PLFLT l, PLFLT s) -{ - PLFLT r, g, b; - - plHLS_RGB(h, l, s, &r, &g, &b); - plrgb(r, g, b); -} - -/*--------------------------------------------------------------------------*\ - * void value() - * - * Auxiliary function used by plHLS_RGB(). -\*--------------------------------------------------------------------------*/ - -static PLFLT -value(double n1, double n2, double hue) -{ - PLFLT val; - - while (hue >= 360.) - hue -= 360.; - while (hue < 0.) - hue += 360.; - - if (hue < 60.) - val = n1 + (n2 - n1) * hue / 60.; - else if (hue < 180.) - val = n2; - else if (hue < 240.) - val = n1 + (n2 - n1) * (240. - hue) / 60.; - else - val = n1; - - return (val); -} - -/*--------------------------------------------------------------------------*\ - * void plHLS_RGB() - * - * Convert HLS color to RGB color. - * Bounds on HLS (input): - * hue [0., 360.] degrees - * lightness [0., 1.] magnitude - * saturation [0., 1.] magnitude - * - * Hue is always mapped onto the interval [0., 360.] regardless of input. - * Bounds on RGB (output) is always [0., 1.]. Convert to RGB color values - * by multiplying by 2**nbits (nbits typically 8). -\*--------------------------------------------------------------------------*/ - -void -plHLS_RGB(PLFLT h, PLFLT l, PLFLT s, PLFLT *p_r, PLFLT *p_g, PLFLT *p_b) -{ - PLFLT m1, m2; - - if (l <= .5) - m2 = l * (s + 1.); - else - m2 = l + s - l * s; - - m1 = 2 * l - m2; - - *p_r = value(m1, m2, h + 120.); - *p_g = value(m1, m2, h); - *p_b = value(m1, m2, h - 120.); -} - -/*--------------------------------------------------------------------------*\ - * void plRGB_HLS() - * - * Convert RGB color to HLS color. - * Bounds on RGB (input) is always [0., 1.]. - * Bounds on HLS (output): - * hue [0., 360.] degrees - * lightness [0., 1.] magnitude - * saturation [0., 1.] magnitude -\*--------------------------------------------------------------------------*/ - -void -plRGB_HLS(PLFLT r, PLFLT g, PLFLT b, PLFLT *p_h, PLFLT *p_l, PLFLT *p_s) -{ - PLFLT h, l, s, d, rc, gc, bc, rgb_min, rgb_max; - - rgb_min = MIN( r, MIN( g, b )); - rgb_max = MAX( r, MAX( g, b )); - - l = (rgb_min+rgb_max) / 2.0; - - if (rgb_min == rgb_max) { - s = 0; - h = 0; - } - else { - d = rgb_max - rgb_min; - if (l < 0.5) - s = 0.5 * d / l; - else - s = 0.5* d / (1.-l); - - rc = (rgb_max-r) / d; - gc = (rgb_max-g) / d; - bc = (rgb_max-b) / d; - - if (r == rgb_max) - h = bc-gc; - else if (g == rgb_max) - h = rc-bc+2; - else - h = gc-rc-2; - - h = h*60; - if (h < 0) - h = h+360; - else if (h >= 360) - h = h-360; - } - *p_h = h; - *p_l = l; - *p_s = s; -} - -/*--------------------------------------------------------------------------*\ - * A grab-bag of various control routines. -\*--------------------------------------------------------------------------*/ - -/*--------------------------------------------------------------------------*\ - * void plwarn() - * - * A handy way to issue warnings, if need be. -\*--------------------------------------------------------------------------*/ - -void -plwarn(char *errormsg) -{ - int was_gfx = 0; - - if (plsc->graphx == 1) { - was_gfx = 1; - pltext(); - } - - fprintf(stderr, "\n*** PLPLOT WARNING ***\n"); - if (*errormsg != '\0') - fprintf(stderr, "%s\n", errormsg); - - if (was_gfx == 1) - plgra(); -} - -/*--------------------------------------------------------------------------*\ - * void plabort() - * - * Much the same as plwarn(), but appends ", aborting operation" to the - * error message. Helps to keep source code uncluttered and provides a - * convention for error aborts. -\*--------------------------------------------------------------------------*/ - -void -plabort(char *errormsg) -{ - if (plsc->errcode != NULL) - *(plsc->errcode) = 1; - - if (plsc->errmsg != NULL) { - sprintf(plsc->errmsg, "\n*** PLPLOT ERROR ***\n"); - if (*errormsg != '\0') - sprintf(plsc->errmsg, "%s, aborting operation\n", errormsg); - - } else { - int was_gfx = 0; - - if (plsc->graphx == 1) { - was_gfx = 1; - pltext(); - } - - fprintf(stderr, "\n*** PLPLOT ERROR ***\n"); - if (*errormsg != '\0') - fprintf(stderr, "%s, aborting operation\n", errormsg); - - if (was_gfx == 1) - plgra(); - } -} - -/*--------------------------------------------------------------------------*\ - * void plexit() - * - * 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. It's best to turn - * off pause and then restore previous setting before returning. - * - * If cleanup needs to be done in the main program, the user should write - * his/her own exit handler and pass it in via plsexit(). This function - * should should either call plend() before exiting, or simply return. -\*--------------------------------------------------------------------------*/ - -void -plexit(char *errormsg) -{ - int status = 1; - - if (exit_handler != NULL) - status = (*exit_handler)(errormsg); - - plsc->nopause = 1; - if (*errormsg != '\0') { - fprintf(stderr, "\n*** PLPLOT ERROR ***\n"); - fprintf(stderr, "%s\n", errormsg); - } - plend(); - - fprintf(stderr, "Program aborted\n"); - exit(status); -} - -/*--------------------------------------------------------------------------*\ - * void plsexit() - * - * Sets an optional user exit handler. -\*--------------------------------------------------------------------------*/ - -void -plsexit(int (*handler) (char *)) -{ - exit_handler = handler; -} - -/*--------------------------------------------------------------------------*\ - * void plgra() - * - * Switches to graphics screen. - * - * Here and in pltext() it's a good idea to return silently if plinit() - * hasn't yet been called, since plwarn() calls pltext() and plgra(), and - * plwarn() may be called at any time. -\*--------------------------------------------------------------------------*/ - -void -c_plgra(void) -{ - if (plsc->level > 0) - plP_esc(PLESC_GRAPH, NULL); -} - -void -c_plxormod(PLINT mode, PLINT *status) /* xor mode */ -{ - static int ostate = 0; - - if (!plsc->dev_xor) { - *status = 0; - return; - } - - if (plsc->level > 0) { - plP_esc(PLESC_XORMOD, &mode); - if (mode) { - ostate = plsc->plbuf_write; - plsc->plbuf_write = 0; - } else - plsc->plbuf_write = ostate; - } - *status = 1; -} - -/*--------------------------------------------------------------------------*\ - * void pltext() - * - * Switches to text screen. -\*--------------------------------------------------------------------------*/ - -void -c_pltext(void) -{ - if (plsc->level > 0) - plP_esc(PLESC_TEXT, NULL); -} - -/*--------------------------------------------------------------------------*\ - * void pl_cmd() - * - * Front-end to driver escape function. - * In principle this can be used to pass just about anything directly - * to the driver. -\*--------------------------------------------------------------------------*/ - -void -pl_cmd(PLINT op, void *ptr) -{ - plP_esc(op, ptr); -} - -/*--------------------------------------------------------------------------*\ - * char *plFindCommand - * - * Looks for the specified executable file. Search path: - * PLPLOT_BIN_ENV = $(PLPLOT_BIN) - * current directory - * PLPLOT_HOME_ENV/bin = $(PLPLOT_HOME)/bin - * BIN_DIR - * - * The caller must free the returned pointer (points to malloc'ed memory) - * when finished with it. -\*--------------------------------------------------------------------------*/ - -char * -plFindCommand(char *fn) -{ - char *fs = NULL, *dn; - -/* PLPLOT_BIN_ENV = $(PLPLOT_BIN) */ - -#if defined(PLPLOT_BIN_ENV) - if ((dn = getenv(PLPLOT_BIN_ENV)) != NULL) { - plGetName(dn, "", fn, &fs); - if ( ! plFindName(fs)) - return fs; - fprintf(stderr, PLPLOT_BIN_ENV"=\"%s\"\n", dn); /* what IS set? */ - } -#endif /* PLPLOT_BIN_ENV */ - -/* Current directory */ - - plGetName(".", "", fn, &fs); - if ( ! plFindName(fs)) - return fs; - -/* PLPLOT_HOME_ENV/bin = $(PLPLOT_HOME)/bin */ - -#if defined(PLPLOT_HOME_ENV) - if ((dn = getenv(PLPLOT_HOME_ENV)) != NULL) { - plGetName(dn, "bin", fn, &fs); - if ( ! plFindName(fs)) - return fs; - fprintf(stderr, PLPLOT_HOME_ENV"=\"%s\"\n",dn); /* what IS set? */ - } -#endif /* PLPLOT_HOME_ENV */ - -/* BIN_DIR */ - -#if defined (BIN_DIR) - plGetName(BIN_DIR, "", fn, &fs); - if ( ! plFindName(fs)) - return fs; -#endif - -/* Crapped out */ - - free_mem(fs); - fprintf(stderr, "plFindCommand: cannot locate command: %s\n", fn); -#if defined (BIN_DIR) - fprintf(stderr, "bin dir=\"" BIN_DIR "\"\n" ); /* what WAS set? */ -#endif /* BIN_DIR */ - return NULL; -} - -/*--------------------------------------------------------------------------*\ - * FILE *plLibOpen(fn) - * - * Return file pointer to lib file. - * Locations checked: - * PLPLOT_LIB_ENV = $(PLPLOT_LIB) - * current directory - * PLPLOT_HOME_ENV/lib = $(PLPLOT_HOME)/lib - * DATA_DIR - * PLLIBDEV -\*--------------------------------------------------------------------------*/ - -FILE * -plLibOpen(char *fn) -{ - FILE *ret = NULL; - - PDFstrm *pdfs = plLibOpenPdfstrm(fn); - if (pdfs == NULL) { - return NULL; - } - if (pdfs->file != NULL) { - ret = pdfs->file; - pdfs->file = NULL; - } - pdf_close(pdfs); - return ret; -} - -PDFstrm * -plLibOpenPdfstrm(char *fn) -{ - PDFstrm *file; - char *fs = NULL, *dn = NULL; - -/**** search PLPLOT_LIB_ENV = $(PLPLOT_LIB) ****/ - -#if defined(PLPLOT_LIB_ENV) - if ((dn = getenv(PLPLOT_LIB_ENV)) != NULL) { - plGetName(dn, "", fn, &fs); - - if ((file = pdf_fopen(fs, "rb")) != NULL) - goto done; - - fprintf(stderr, PLPLOT_LIB_ENV"=\"%s\"\n", dn); /* what IS set? */ - } -#endif /* PLPLOT_LIB_ENV */ - -/**** search current directory ****/ - - if ((file = pdf_fopen(fn, "rb")) != NULL) - goto done; - -/**** search PLPLOT_HOME_ENV/lib = $(PLPLOT_HOME)/lib ****/ - -#if defined (PLPLOT_HOME_ENV) - if ((dn = getenv(PLPLOT_HOME_ENV)) != NULL) { - plGetName(dn, "lib", fn, &fs); - - if ((file = pdf_fopen(fs, "rb")) != NULL) - goto done; - fprintf(stderr, PLPLOT_HOME_ENV"=\"%s\"\n",dn); /* what IS set? */ - } -#endif /* PLPLOT_HOME_ENV/lib */ - -/**** search installed location ****/ - -#if defined (DATA_DIR) - plGetName(DATA_DIR, "", fn, &fs); - - if ((file = pdf_fopen(fs, "rb")) != NULL) - goto done; -#endif /* DATA_DIR */ - -/**** search hardwired location ****/ - -#ifdef PLLIBDEV - plGetName(PLLIBDEV, "", fn, &fs); - - if ((file = pdf_fopen(fs, "rb")) != NULL) - goto done; -#endif /* PLLIBDEV */ - -#ifdef macintosh - file = plMacLibOpen(fn); - if (file != NULL) - goto done; -#endif /* macintosh */ - - if (plplotLibDir != NULL) { - plGetName(plplotLibDir, "", fn, &fs); - if ((file = pdf_fopen(fs, "rb")) != NULL) - goto done; - - } - -/**** not found, give up ****/ - - return NULL; - - done: - free_mem(fs); - return (file); -} - -/*--------------------------------------------------------------------------*\ - * int plFindName - * - * Authors: Paul Dubois (LLNL), others? - * This function is in the public domain. - * - * Given a pathname, determine if it is a symbolic link. If so, continue - * searching to the ultimate terminus - there may be more than one link. - * Use the error value to determine when the terminus is reached, and to - * determine if the pathname really exists. Then stat it to determine - * whether it's executable. Return 0 for an executable, errno otherwise. - * Note that 'p' _must_ have at least one '/' character - it does by - * construction in this program. The contents of the array pointed to by - * 'p' are changed to the actual pathname if findname is successful. - * - * This function is only defined under Unix for now. -\*--------------------------------------------------------------------------*/ - -#ifdef do_not_do // changed, this is unnessisary in this build anyway -int -plFindName(char *p) -{ - int n; - char buf[1024], *cp; - extern int errno; - struct stat sbuf; - - pldebug("plFindName", "Trying to find %s\n", p); - while ((n = readlink(p, buf, 1024)) > 0) { - pldebug("plFindName", "Readlink read %d chars at: %s\n", n, p); - if (buf[0] == '/') { - /* Link is an absolute path */ - - strncpy(p, buf, n); - p[n] = '\0'; - pldebug("plFindName", "Link is absolute: %s\n", p); - } - else { - /* Link is relative to its directory; make it absolute */ - - cp = 1 + strrchr(p, '/'); - strncpy(cp, buf, n); - cp[n] = '\0'; - pldebug("plFindName", - "Link is relative: %s\n\tTotal path:%s\n", cp, p); - } - } - -/* This macro not defined on the NEC SX-3 */ - -#ifdef SX -#define S_ISREG(mode) (mode & S_IFREG) -#endif - -/* SGI machines return ENXIO instead of EINVAL Dubois 11/92 */ - - if (errno == EINVAL || errno == ENXIO) { - pldebug("plFindName", "%s may be the one...\n", p); - if ((stat(p, &sbuf) == 0) && S_ISREG(sbuf.st_mode)) { - pldebug("plFindName", "%s is a regular file\n", p); - return (access(p, X_OK)); - } - } - pldebug("plFindName", "%s found but is not executable\n", p); - return (errno ? errno : -1); -} - -#else -int -plFindName(char *p) -{ - return 1; -} -#endif - -/*--------------------------------------------------------------------------*\ - * void plGetName() - * - * Gets search name for file by concatenating the dir, subdir, and file - * name, allocating memory as needed. The appropriate delimiter is added - * after the dir specification as necessary. The caller is responsible - * for freeing the malloc'ed memory. -\*--------------------------------------------------------------------------*/ - -void -plGetName(char *dir, char *subdir, char *filename, char **filespec) -{ - int lfilespec; - -/* Malloc space for filespec */ - - free_mem(*filespec); - lfilespec = 10; - lfilespec = strlen(dir) + strlen(subdir) + strlen(filename) + 10; - *filespec = (char *) malloc(lfilespec); - - strcpy(*filespec, dir); - - if (*subdir != '\0') { - strcat_delim(*filespec); - strcat(*filespec, subdir); - } - if (*filename != '\0') { - strcat_delim(*filespec); - strcat(*filespec, filename); - } -} - -/*--------------------------------------------------------------------------*\ - * void strcat_delim() - * - * Append path name deliminator if necessary (does not add one if one's - * there already, or if dealing with a colon-terminated device name). -\*--------------------------------------------------------------------------*/ - -static void -strcat_delim(char *dirspec) -{ - int ldirspec = strlen(dirspec); -#if defined (MSDOS) - if (dirspec[ldirspec-1] != '\\') - strcat(dirspec, "\\"); -#elif defined (macintosh) - if (dirspec[ldirspec-1] != ':') - strcat(dirspec, ":"); -#else /* unix is the default */ - if (dirspec[ldirspec-1] != '/') - strcat(dirspec, "/"); -#endif -} - -/*--------------------------------------------------------------------------*\ - * plcol_interp() - * - * Initializes device cmap 1 entry by interpolation from pls->cmap1 - * entries. Returned PLColor is supposed to represent the i_th color - * out of a total of ncol colors in the current color scheme. -\*--------------------------------------------------------------------------*/ - -void -plcol_interp(PLStream *pls, PLColor *newcolor, int i, int ncol) -{ - PLFLT x, delta; - int il, ir; - - x = (double) (i * (pls->ncol1-1)) / (double) (ncol-1); - il = x; - ir = il + 1; - delta = x - il; - - if (ir > pls->ncol1 || il < 0) - fprintf(stderr, "Invalid color\n"); - - else if (ir == pls->ncol1 || (delta == 0.)) { - newcolor->r = pls->cmap1[il].r; - newcolor->g = pls->cmap1[il].g; - newcolor->b = pls->cmap1[il].b; - } - else { - newcolor->r = (1.-delta) * pls->cmap1[il].r + delta * pls->cmap1[ir].r; - newcolor->g = (1.-delta) * pls->cmap1[il].g + delta * pls->cmap1[ir].g; - newcolor->b = (1.-delta) * pls->cmap1[il].b + delta * pls->cmap1[ir].b; - } -} - -/*--------------------------------------------------------------------------*\ - * plOpenFile() - * - * Opens file for output, prompting if not set. - * Prints extra newline at end to make output look better in batch runs. - * A file name of "-" indicates output to stdout. -\*--------------------------------------------------------------------------*/ - -#define MAX_NUM_TRIES 10 -void -plOpenFile(PLStream *pls) -{ - int i = 0, count = 0; - size_t len; - char line[256]; - - while (pls->OutFile == NULL) { - -/* Setting pls->FileName = NULL forces creation of a new family member */ -/* You should also free the memory associated with it if you do this */ - - if (pls->family && pls->BaseName != NULL) - plP_getmember(pls); - -/* Prompt if filename still not known */ - - if (pls->FileName == NULL) { - do { - fprintf(stdout, "Enter graphics output file name: "); - if (!fgets(line, sizeof(line), stdin)) { - return; - } - len = strlen(line); - if (len) - len--; - line[len] = '\0'; /* strip new-line */ - count++; /* count zero entries */ - } while (!len && count < MAX_NUM_TRIES); - plP_sfnam(pls, line); - } - -/* If name is "-", send to stdout */ - - if ( ! strcmp(pls->FileName, "-")) { - pls->OutFile = stdout; - pls->output_type = 1; - break; - } - -/* Need this here again, for prompted family initialization */ - - if (pls->family && pls->BaseName != NULL) - plP_getmember(pls); - - if (i++ > 10) - plexit("Too many tries."); - - if ((pls->OutFile = fopen(pls->FileName, "wb+")) == NULL) - fprintf(stdout, "Can't open %s.\n", pls->FileName); - else - { -// fprintf(stderr, "Opened %s\n", pls->FileName); -// this is not needed - } - } -} - -/*--------------------------------------------------------------------------*\ - * plP_getmember() - * - * Sets up next file member name (in pls->FileName), but does not open it. -\*--------------------------------------------------------------------------*/ - -void -plP_getmember(PLStream *pls) -{ - char tmp[256]; - - if (pls->FileName == NULL) - pls->FileName = (char *) malloc(10 + strlen(pls->BaseName)); - - sprintf(tmp, "%s.%%0%1ii", pls->BaseName, (int) pls->fflen); - sprintf(pls->FileName, tmp, pls->member); -} - -/*--------------------------------------------------------------------------*\ - * plP_sfnam() - * - * Sets up file name & family stem name. - * Reserve some extra space (5 chars) to hold an optional member number. -\*--------------------------------------------------------------------------*/ - -void -plP_sfnam(PLStream *pls, const char *fnam) -{ - pls->OutFile = NULL; - - if (pls->FileName != NULL) - free((void *) pls->FileName); - - pls->FileName = (char *) malloc(10 + strlen(fnam)); - - strcpy(pls->FileName, fnam); - - if (pls->BaseName != NULL) - free((void *) pls->BaseName); - - pls->BaseName = (char *) malloc(10 + strlen(fnam)); - - strcpy(pls->BaseName, fnam); -} - -/*--------------------------------------------------------------------------*\ - * plFamInit() - * - * Initializes family file parameters. -\*--------------------------------------------------------------------------*/ - -void -plFamInit(PLStream *pls) -{ - if (pls->family) { - pls->bytecnt = 0; - if ( ! pls->member) - pls->member = 1; - if ( ! pls->finc) - pls->finc = 1; - if ( ! pls->fflen) - pls->fflen = 1; - if ( ! pls->bytemax) - pls->bytemax = PL_FILESIZE_KB * 1000; - } -} - -/*--------------------------------------------------------------------------*\ - * plGetFam() - * - * Starts new member file of family file set if necessary. - * - * Note each member file is a complete graphics file (can be printed - * individually), although 'plrender' will treat a family as a single - * logical file if given the family name instead of the member name. -\*--------------------------------------------------------------------------*/ - -void -plGetFam(PLStream *pls) -{ - PLFLT xpmm_loc, ypmm_loc; - if (pls->family) { - if (pls->bytecnt > pls->bytemax || pls->famadv) { - plP_tidy(); - pls->member += pls->finc; - pls->famadv = 0; - plP_init(); - /* Apply compensating factor to original xpmm and ypmm so that - * character aspect ratio is preserved when overall aspect ratio - * is changed. */ - plP_gpixmm(&xpmm_loc, &ypmm_loc); - plP_setpxl(xpmm_loc*plsc->caspfactor, ypmm_loc/plsc->caspfactor); - return; - } - } -} - -/*--------------------------------------------------------------------------*\ - * plRotPhy() - * - * Rotates physical coordinates if necessary for given orientation. - * Each time orient is incremented, the plot is rotated 90 deg clockwise. - * Note: this is now used only to rotate by 90 degrees for devices that - * expect portrait mode. -\*--------------------------------------------------------------------------*/ - -void -plRotPhy(PLINT orient, PLINT xmin, PLINT ymin, PLINT xmax, PLINT ymax, - int *px, int *py) -{ - int x, y; - - x = *px; - y = *py; - - switch (orient%4) { - - case 1: - *px = xmin + (y - ymin); - *py = ymin + (xmax - x); - break; - - case 2: - *px = xmin + (xmax - x); - *py = ymin + (ymax - y); - break; - - case 3: - *px = xmin + (ymax - y); - *py = ymin + (x - xmin); - break; - - default: - break; /* do nothing */ - } -} - -/*--------------------------------------------------------------------------*\ - * plAllocDev() - * - * Allocates a standard PLDev structure for device-specific data, stores - * the address in pls->dev, and returns the address as well. -\*--------------------------------------------------------------------------*/ - -PLDev * -plAllocDev(PLStream *pls) -{ - if (pls->dev != NULL) - free((void *) pls->dev); - - pls->dev = calloc(1, (size_t) sizeof(PLDev)); - if (pls->dev == NULL) - plexit("plAllocDev: cannot allocate memory\n"); - - return (PLDev *) pls->dev; -} - -/*--------------------------------------------------------------------------*\ - * plGinInit() - * - * Just fills in the PLGraphicsIn with appropriate initial values. -\*--------------------------------------------------------------------------*/ - -void -plGinInit(PLGraphicsIn *gin) -{ - gin->type = 0; - gin->state = 0; - gin->keysym = 0; - gin->button = 0; - gin->string[0] = '\0'; - gin->pX = gin->pY = -1; - gin->dX = gin->dY = 0.; - gin->wX = gin->wY = 0.; -} - -/*--------------------------------------------------------------------------*\ - * plGetInt() - * - * Prompts human to input an integer in response to given message. -\*--------------------------------------------------------------------------*/ - -PLINT -plGetInt(char *s) -{ - int m; - int i = 0; - char line[256]; - - while (i++ < 10) { - fprintf(stdout, "%s", s); - if (! (fgets(line, sizeof(line), stdin))) { - return 0; - } -#ifdef MSDOS - m = atoi(line); - return (m); -#else - if (sscanf(line, "%d", &m) == 1) - return (m); - fprintf(stdout, "No value or value out of range; please try again\n"); -#endif - } - plexit("Too many tries."); - return (0); -} - -/*--------------------------------------------------------------------------*\ - * plGetFlt() - * - * Prompts human to input a float in response to given message. -\*--------------------------------------------------------------------------*/ - -PLFLT -plGetFlt(char *s) -{ - PLFLT m; - double m1; - int i = 0; - char line[256]; - - while (i++ < 10) { - fprintf(stdout, "%s", s); - if (! (fgets(line, sizeof(line), stdin))) { - return (0.); - } -#ifdef MSDOS - m = atof(line); - return (m); -#else - if (sscanf(line, "%lf", &m1) == 1) { - m = (PLFLT) m1; - return (m); - } - fprintf(stdout, "No value or value out of range; please try again\n"); -#endif - } - plexit("Too many tries."); - return (0.); -} - -/*--------------------------------------------------------------------------*\ - * plstrdup() - * - * A replacement for strdup(), which isn't portable. - * Caller responsible for freeing the allocated memory. -\*--------------------------------------------------------------------------*/ - -char * -plstrdup(const char *src) -{ - char *dest = (char *) malloc( (strlen(src) + 1) * sizeof(char) ); - if (dest != NULL) - strcpy(dest, src); - else - plabort("Out of memory"); - - return dest; -} - diff --git a/src/plot/plplot/plcvt.c b/src/plot/plplot/plcvt.c deleted file mode 100644 index 9b99c453fd..0000000000 --- a/src/plot/plplot/plcvt.c +++ /dev/null @@ -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)); -} diff --git a/src/plot/plplot/pldebug.h b/src/plot/plplot/pldebug.h deleted file mode 100644 index f95b29d727..0000000000 --- a/src/plot/plplot/pldebug.h +++ /dev/null @@ -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 - -/* 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 -#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__ */ diff --git a/src/plot/plplot/pldtik.c b/src/plot/plplot/pldtik.c deleted file mode 100644 index ff64ab944c..0000000000 --- a/src/plot/plplot/pldtik.c +++ /dev/null @@ -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); - } -} diff --git a/src/plot/plplot/plevent.h b/src/plot/plplot/plevent.h deleted file mode 100644 index 6dba6c0ced..0000000000 --- a/src/plot/plplot/plevent.h +++ /dev/null @@ -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__ */ diff --git a/src/plot/plplot/plfill.c b/src/plot/plplot/plfill.c deleted file mode 100644 index 351d4959b2..0000000000 --- a/src/plot/plplot/plfill.c +++ /dev/null @@ -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; -} diff --git a/src/plot/plplot/plfreetype.h b/src/plot/plplot/plfreetype.h deleted file mode 100644 index 15dfc8768b..0000000000 --- a/src/plot/plplot/plfreetype.h +++ /dev/null @@ -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 -#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__ */ diff --git a/src/plot/plplot/plgridd.c b/src/plot/plplot/plgridd.c deleted file mode 100644 index 70ad348bd4..0000000000 --- a/src/plot/plplot/plgridd.c +++ /dev/null @@ -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 -#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; ix = (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; jx = (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; iz; - } - } - - 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 md) - md = items[k].dist; -#endif - zg[i][j] = 0.; - nt = 0.; - - for (k=0; k 2. || threshold < 1.) { - plabort("plgriddata(): GRID_NNLI: 1. < threshold < 2."); - return; - } - - for (i=0; i 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; i0; ii--) { - for (jj=0; jj 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; ix = (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; jx = (double) *xt++; - pt->y = (double) *yt; - pt++; - } - yt++; - } - - lpi_interpolate_points(npts, pin, nptsg, pgrid); - for(i=0; iz; - } - } - - 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; ix = (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; jx = (double) *xt++; - pt->y = (double) *yt; - pt++; - } - yt++; - } - - nnpi_interpolate_points(npts, pin, wmin, nptsg, pgrid); - for(i=0; iz; - } - } - - 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 max_dist) { - max_dist = items[j].dist; - max_slot = j; - } - } - } - } - for (j=0; j2, 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; iupperdelaunay) { - 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; iupperdelaunay) - 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 */ diff --git a/src/plot/plplot/plhist.c b/src/plot/plplot/plhist.c deleted file mode 100644 index 7ff741de64..0000000000 --- a/src/plot/plplot/plhist.c +++ /dev/null @@ -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); - } - } - } -} diff --git a/src/plot/plplot/plimage.c b/src/plot/plplot/plimage.c deleted file mode 100644 index b800578a91..0000000000 --- a/src/plot/plplot/plimage.c +++ /dev/null @@ -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 tz) - lzmin = tz; - } - } - - ixx=-1; - for (ix=xm; ix 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); -} diff --git a/src/plot/plplot/plline.c b/src/plot/plplot/plline.c deleted file mode 100644 index 4c608c09ef..0000000000 --- a/src/plot/plplot/plline.c +++ /dev/null @@ -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; - } -} diff --git a/src/plot/plplot/plmap.c b/src/plot/plplot/plmap.c deleted file mode 100644 index 399795a049..0000000000 --- a/src/plot/plplot/plmap.c +++ /dev/null @@ -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); - } - } - } -} diff --git a/src/plot/plplot/plmeta.c b/src/plot/plplot/plmeta.c deleted file mode 100644 index d3fe9b8b8e..0000000000 --- a/src/plot/plplot/plmeta.c +++ /dev/null @@ -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 - -/* 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 */ diff --git a/src/plot/plplot/plot3d.c b/src/plot/plplot/plot3d.c deleted file mode 100644 index f653bf7d2b..0000000000 --- a/src/plot/plplot/plot3d.c +++ /dev/null @@ -1,2087 +0,0 @@ -/* $Id: plot3d.c,v 1.2 2005/03/17 21:39:21 eli Exp $ - - 3d plot routines. -*/ - -#include "plplotP.h" - -/* Internal constants */ - -#define BINC 50 /* Block size for memory allocation */ - -static PLINT pl3mode = 0; /* 0 3d solid; 1 mesh plot */ -static PLINT pl3upv = 1; /* 1 update view; 0 no update */ - -static PLINT zbflg = 0, zbcol; -static PLFLT zbtck; - -static PLINT *oldhiview = NULL; -static PLINT *oldloview = NULL; -static PLINT *newhiview = NULL; -static PLINT *newloview = NULL; -static PLINT *utmp = NULL; -static PLINT *vtmp = NULL; -static PLFLT *ctmp = NULL; - -static PLINT mhi, xxhi, newhisize; -static PLINT mlo, xxlo, newlosize; - -/* Light source for shading */ -static PLFLT xlight, ylight, zlight; -static PLINT falsecolor=0; -static PLFLT fc_minz, fc_maxz; - -/* Prototypes for static functions */ - -static void plgrid3 (PLFLT); -static void plnxtv (PLINT *, PLINT *, PLFLT*, PLINT, PLINT); -static void plside3 (PLFLT *, PLFLT *, PLFLT **, PLINT, PLINT, PLINT); -static void plt3zz (PLINT, PLINT, PLINT, PLINT, - PLINT, PLINT *, PLFLT *, PLFLT *, PLFLT **, - PLINT, PLINT, PLINT *, PLINT *, PLFLT*); -static void plnxtvhi (PLINT *, PLINT *, PLFLT*, PLINT, PLINT); -static void plnxtvlo (PLINT *, PLINT *, PLFLT*, PLINT, PLINT); -static void plnxtvhi_draw(PLINT *u, PLINT *v, PLFLT* c, PLINT n); - -static void savehipoint (PLINT, PLINT); -static void savelopoint (PLINT, PLINT); -static void swaphiview (void); -static void swaploview (void); -static void myexit (char *); -static void myabort (char *); -static void freework (void); -static int plabv (PLINT, PLINT, PLINT, PLINT, PLINT, PLINT); -static void pl3cut (PLINT, PLINT, PLINT, PLINT, PLINT, - PLINT, PLINT, PLINT, PLINT *, PLINT *); -static PLFLT plGetAngleToLight(PLFLT* x, PLFLT* y, PLFLT* z); -static void plP_draw3d(PLINT x, PLINT y, PLFLT *c, PLINT j, PLINT move); - -/* #define MJL_HACK 1 */ -#if MJL_HACK -static void plP_fill3(PLINT x0, PLINT y0, PLINT x1, PLINT y1, - PLINT x2, PLINT y2, PLINT j); -static void plP_fill4(PLINT x0, PLINT y0, PLINT x1, PLINT y1, - PLINT x2, PLINT y2, PLINT x3, PLINT y3, PLINT j); -#endif - -/*--------------------------------------------------------------------------*\ - * void plsetlightsource(x, y, z) - * - * Sets the position of the light source. -\*--------------------------------------------------------------------------*/ - -void -c_pllightsource(PLFLT x, PLFLT y, PLFLT z) -{ - xlight = x; - ylight = y; - zlight = z; -} - -/*--------------------------------------------------------------------------*\ - * void plmesh(x, y, z, nx, ny, opt) - * - * Plots a mesh representation of the function z[x][y]. The x values - * are stored as x[0..nx-1], the y values as y[0..ny-1], and the - * z values are in the 2-d array z[][]. The integer "opt" specifies: - * see plmeshc() bellow. -\*--------------------------------------------------------------------------*/ - -void -c_plmesh(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt) -{ - c_plot3dc(x, y, z, nx, ny, opt | MESH, NULL, 0); -} - -/*--------------------------------------------------------------------------*\ - * void plmeshc(x, y, z, nx, ny, opt, clevel, nlevel) - * - * Plots a mesh representation of the function z[x][y]. The x values - * are stored as x[0..nx-1], the y values as y[0..ny-1], and the - * z values are in the 2-d array z[][]. The integer "opt" specifies: - * - * DRAW_LINEX draw lines parallel to the X axis - * DRAW_LINEY draw lines parallel to the Y axis - * DRAW_LINEXY draw lines parallel to both the X and Y axis - * MAG_COLOR draw the mesh with a color dependent of the magnitude - * BASE_CONT draw contour plot at bottom xy plane - * TOP_CONT draw contour plot at top xy plane (not yet) - * DRAW_SIDES draw sides - * - * or any bitwise combination, e.g. "MAG_COLOR | DRAW_LINEX" - * -\*--------------------------------------------------------------------------*/ - -MZ_DLLEXPORT -void -c_plmeshc(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, - PLFLT *clevel, PLINT nlevel) -{ - plot3dc(x, y, z, nx, ny, opt | MESH, clevel, nlevel); -} - -/* clipping helper for 3d polygons */ - -int -plP_clip_poly(int Ni, PLFLT *Vi[3], int axis, PLFLT dir, PLFLT offset) -{ - int anyout = 0; - PLFLT in[PL_MAXPOLY], T[3][PL_MAXPOLY]; - int No = 0; - int i, j, k; - - for(i=0; i=0 && in[j]>=0) { - for(k=0; k<3; k++) - Vi[k][No] = T[k][j]; - No++; - } else if(in[i]>=0 && in[j]<0) { - PLFLT u = in[i] / (in[i] - in[j]); - for(k = 0; k<3; k++) - Vi[k][No] = T[k][i]*(1-u) + T[k][j]*u; - No++; - } else if(in[i]<0 && in[j]>=0) { - PLFLT u = in[i] / (in[i] - in[j]); - for(k = 0; k<3; k++) - Vi[k][No] = T[k][i]*(1-u) + T[k][j]*u; - No++; - for(k=0; k<3; k++) - Vi[k][No] = T[k][j]; - No++; - } - } - return No; -} - -/* helper for plsurf3d, similar to c_plfill3() */ -static void -shade_triangle(PLFLT x0, PLFLT y0, PLFLT z0, - PLFLT x1, PLFLT y1, PLFLT z1, - PLFLT x2, PLFLT y2, PLFLT z2) -{ - int i; - /* arrays for interface to core functions */ - short u[6], v[6]; - PLFLT x[6], y[6], z[6]; - int n; - PLFLT xmin, xmax, ymin, ymax, zmin, zmax, zscale; - PLFLT *V[3]; - - plP_gdom(&xmin, &xmax, &ymin, &ymax); - plP_grange(&zscale, &zmin, &zmax); - - x[0] = x0; x[1] = x1; x[2] = x2; - y[0] = y0; y[1] = y1; y[2] = y2; - z[0] = z0; z[1] = z1; z[2] = z2; - n = 3; - - if (falsecolor) - plcol1(((z[0] + z[1] + z[2]) /3. - fc_minz) / (fc_maxz - fc_minz)); - else - plcol1(plGetAngleToLight(x, y, z)); - - V[0] = x; V[1] = y; V[2] = z; - - 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