annotate lisp/calc/calc-graph.el @ 44709:e673f42e092e

*** empty log message ***
author Pavel Janík <Pavel@Janik.cz>
date Fri, 19 Apr 2002 19:04:25 +0000
parents 54abc38794d9
children f4d68f97221e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1 ;;; calc-graph.el --- graph output functions for Calc
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
2
40998
ee9c2872370b Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents: 40785
diff changeset
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
4
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
5 ;; Author: David Gillespie <daveg@synaptics.com>
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
6 ;; Maintainer: Colin Walters <walters@debian.org>
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
7
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
9
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is distributed in the hope that it will be useful,
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
11 ;; but WITHOUT ANY WARRANTY. No author or distributor
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
12 ;; accepts responsibility to anyone for the consequences of using it
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
13 ;; or for whether it serves any particular purpose or works at all,
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
14 ;; unless he says so in writing. Refer to the GNU Emacs General Public
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
15 ;; License for full details.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
16
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
17 ;; Everyone is granted permission to copy, modify and redistribute
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
18 ;; GNU Emacs, but only under the conditions described in the
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
19 ;; GNU Emacs General Public License. A copy of this license is
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
20 ;; supposed to have been given to you along with GNU Emacs so you
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
21 ;; can know your rights and responsibilities. It should be in a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
22 ;; file named COPYING. Among other things, the copyright notice
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
23 ;; and this notice must be preserved on all copies.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
24
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
25 ;;; Commentary:
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
26
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
27 ;;; Code:
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
28
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
29 ;; This file is autoloaded from calc-ext.el.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
30 (require 'calc-ext)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
31
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
32 (require 'calc-macs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
33
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
34 (defun calc-Need-calc-graph () nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
35
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
36
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
37 ;;; Graphics
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
38
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
39 ;;; Note that some of the following initial values also occur in calc.el.
43606
54abc38794d9 (calc-gnuplot-tempfile): Don't expand against
Colin Walters <walters@gnu.org>
parents: 41271
diff changeset
40 (defvar calc-gnuplot-tempfile "calc")
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
41
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
42 (defvar calc-gnuplot-default-device "default")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
43 (defvar calc-gnuplot-default-output "STDOUT")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
44 (defvar calc-gnuplot-print-device "postscript")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
45 (defvar calc-gnuplot-print-output "auto")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
46 (defvar calc-gnuplot-keep-outfile nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
47 (defvar calc-gnuplot-version nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
48
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
49 (defvar calc-gnuplot-display (getenv "DISPLAY"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
50 (defvar calc-gnuplot-geometry nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
51
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
52 (defvar calc-graph-default-resolution 15)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
53 (defvar calc-graph-default-resolution-3d 5)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
54 (defvar calc-graph-default-precision 5)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
55
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
56 (defvar calc-gnuplot-buffer nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
57 (defvar calc-gnuplot-input nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
58
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
59 (defvar calc-gnuplot-last-error-pos 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
60 (defvar calc-graph-last-device nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
61 (defvar calc-graph-last-output nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
62 (defvar calc-graph-file-cache nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
63 (defvar calc-graph-var-cache nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
64 (defvar calc-graph-data-cache nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
65 (defvar calc-graph-data-cache-limit 10)
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
66 (defvar calc-graph-no-auto-view nil)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
67 (defvar calc-graph-no-wait nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
68
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
69 (defun calc-graph-fast (many)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
70 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
71 (let ((calc-graph-no-auto-view t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
72 (calc-graph-delete t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
73 (calc-graph-add many)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
74 (calc-graph-plot nil)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
75
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
76 (defun calc-graph-fast-3d (many)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
77 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
78 (let ((calc-graph-no-auto-view t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
79 (calc-graph-delete t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
80 (calc-graph-add-3d many)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
81 (calc-graph-plot nil)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
82
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
83 (defun calc-graph-delete (all)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
84 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
85 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
86 (calc-graph-init)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
87 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
88 (set-buffer calc-gnuplot-input)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
89 (and (calc-graph-find-plot t all)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
90 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
91 (if (looking-at "s?plot")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
92 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
93 (setq calc-graph-var-cache nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
94 (delete-region (point) (point-max)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
95 (delete-region (point) (1- (point-max)))))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
96 (calc-graph-view-commands)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
97
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
98 (defun calc-graph-find-plot (&optional before all)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
99 (goto-char (point-min))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
100 (and (re-search-forward "^s?plot[ \t]+" nil t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
101 (let ((beg (point)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
102 (goto-char (point-max))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
103 (if (or all
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
104 (not (search-backward "," nil t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
105 (< (point) beg))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
106 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
107 (goto-char beg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
108 (if before
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
109 (beginning-of-line)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
110 (or before
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
111 (re-search-forward ",[ \t]+")))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
112 t)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
113
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
114 (defun calc-graph-add (many)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
115 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
116 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
117 (calc-graph-init)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
118 (cond ((null many)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
119 (calc-graph-add-curve (calc-graph-lookup (calc-top-n 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
120 (calc-graph-lookup (calc-top-n 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
121 ((or (consp many) (eq many 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
122 (let ((xdata (calc-graph-lookup (calc-top-n 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
123 (ylist (calc-top-n 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
124 (or (eq (car-safe ylist) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
125 (error "Y argument must be a vector"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
126 (while (setq ylist (cdr ylist))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
127 (calc-graph-add-curve xdata (calc-graph-lookup (car ylist))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
128 ((> (setq many (prefix-numeric-value many)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
129 (let ((xdata (calc-graph-lookup (calc-top-n (1+ many)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
130 (while (> many 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
131 (calc-graph-add-curve xdata
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
132 (calc-graph-lookup (calc-top-n many)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
133 (setq many (1- many)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
134 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
135 (let (pair)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
136 (setq many (- many))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
137 (while (> many 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
138 (setq pair (calc-top-n many))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
139 (or (and (eq (car-safe pair) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
140 (= (length pair) 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
141 (error "Argument must be an [x,y] vector"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
142 (calc-graph-add-curve (calc-graph-lookup (nth 1 pair))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
143 (calc-graph-lookup (nth 2 pair)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
144 (setq many (1- many))))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
145 (calc-graph-view-commands)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
146
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
147 (defun calc-graph-add-3d (many)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
148 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
149 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
150 (calc-graph-init)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
151 (cond ((null many)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
152 (calc-graph-add-curve (calc-graph-lookup (calc-top-n 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
153 (calc-graph-lookup (calc-top-n 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
154 (calc-graph-lookup (calc-top-n 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
155 ((or (consp many) (eq many 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
156 (let ((xdata (calc-graph-lookup (calc-top-n 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
157 (ydata (calc-graph-lookup (calc-top-n 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
158 (zlist (calc-top-n 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
159 (or (eq (car-safe zlist) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
160 (error "Z argument must be a vector"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
161 (while (setq zlist (cdr zlist))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
162 (calc-graph-add-curve xdata ydata
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
163 (calc-graph-lookup (car zlist))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
164 ((> (setq many (prefix-numeric-value many)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
165 (let ((xdata (calc-graph-lookup (calc-top-n (+ many 2))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
166 (ydata (calc-graph-lookup (calc-top-n (+ many 1)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
167 (while (> many 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
168 (calc-graph-add-curve xdata ydata
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
169 (calc-graph-lookup (calc-top-n many)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
170 (setq many (1- many)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
171 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
172 (let (curve)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
173 (setq many (- many))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
174 (while (> many 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
175 (setq curve (calc-top-n many))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
176 (or (and (eq (car-safe curve) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
177 (= (length curve) 4))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
178 (error "Argument must be an [x,y,z] vector"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
179 (calc-graph-add-curve (calc-graph-lookup (nth 1 curve))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
180 (calc-graph-lookup (nth 2 curve))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
181 (calc-graph-lookup (nth 3 curve)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
182 (setq many (1- many))))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
183 (calc-graph-view-commands)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
184
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
185 (defun calc-graph-add-curve (xdata ydata &optional zdata)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
186 (let ((num (calc-graph-count-curves))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
187 (pstyle (calc-var-value 'var-PointStyles))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
188 (lstyle (calc-var-value 'var-LineStyles)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
189 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
190 (set-buffer calc-gnuplot-input)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
191 (goto-char (point-min))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
192 (if (re-search-forward (if zdata "^plot[ \t]" "^splot[ \t]")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
193 nil t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
194 (error "Can't mix 2d and 3d curves on one graph"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
195 (if (re-search-forward "^s?plot[ \t]" nil t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
196 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
197 (end-of-line)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
198 (insert ", "))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
199 (goto-char (point-max))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
200 (or (eq (preceding-char) ?\n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
201 (insert "\n"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
202 (insert (if zdata "splot" "plot") " \n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
203 (forward-char -1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
204 (insert "{" (symbol-name (nth 1 xdata))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
205 ":" (symbol-name (nth 1 ydata)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
206 (if zdata
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
207 (insert ":" (symbol-name (nth 1 zdata))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
208 (insert "} "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
209 "title \"" (symbol-name (nth 1 ydata)) "\" "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
210 "with dots")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
211 (setq pstyle (and (eq (car-safe pstyle) 'vec) (nth (1+ num) pstyle)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
212 (setq lstyle (and (eq (car-safe lstyle) 'vec) (nth (1+ num) lstyle)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
213 (calc-graph-set-styles
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
214 (or (and (Math-num-integerp lstyle) (math-trunc lstyle))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
215 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
216 (or (and (Math-num-integerp pstyle) (math-trunc pstyle))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
217 (if (eq (car-safe (calc-var-value (nth 2 ydata))) 'vec)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
218 0 -1))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
219
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
220 (defun calc-graph-lookup (thing)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
221 (if (and (eq (car-safe thing) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
222 (calc-var-value (nth 2 thing)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
223 thing
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
224 (let ((found (assoc thing calc-graph-var-cache)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
225 (or found
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
226 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
227 (setq varname (concat "PlotData"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
228 (int-to-string
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
229 (1+ (length calc-graph-var-cache))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
230 var (list 'var (intern varname)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
231 (intern (concat "var-" varname)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
232 found (cons thing var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
233 calc-graph-var-cache (cons found calc-graph-var-cache))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
234 (set (nth 2 var) thing)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
235 (cdr found))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
236
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
237 (defun calc-graph-juggle (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
238 (interactive "p")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
239 (calc-graph-init)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
240 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
241 (set-buffer calc-gnuplot-input)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
242 (if (< arg 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
243 (let ((num (calc-graph-count-curves)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
244 (if (> num 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
245 (while (< arg 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
246 (setq arg (+ arg num))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
247 (while (>= (setq arg (1- arg)) 0)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
248 (calc-graph-do-juggle))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
249
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
250 (defun calc-graph-count-curves ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
251 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
252 (set-buffer calc-gnuplot-input)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
253 (if (re-search-forward "^s?plot[ \t]" nil t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
254 (let ((num 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
255 (goto-char (point-min))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
256 (while (search-forward "," nil t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
257 (setq num (1+ num)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
258 num)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
259 0)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
260
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
261 (defun calc-graph-do-juggle ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
262 (let (base)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
263 (and (calc-graph-find-plot t t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
264 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
265 (setq base (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
266 (calc-graph-find-plot t nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
267 (or (eq base (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
268 (let ((str (buffer-substring (+ (point) 2) (1- (point-max)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
269 (delete-region (point) (1- (point-max)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
270 (goto-char (+ base 5))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
271 (insert str ", ")))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
272
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
273 (defun calc-graph-print (flag)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
274 (interactive "P")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
275 (calc-graph-plot flag t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
276
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
277 (defun calc-graph-plot (flag &optional printing)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
278 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
279 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
280 (let ((calcbuf (current-buffer))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
281 (tempbuf (get-buffer-create "*Gnuplot Temp-2*"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
282 (tempbuftop 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
283 (tempoutfile nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
284 (curve-num 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
285 (refine (and flag (> (prefix-numeric-value flag) 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
286 (recompute (and flag (< (prefix-numeric-value flag) 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
287 (surprise-splot nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
288 (tty-output nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
289 cache-env is-splot device output resolution precision samples-pos)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
290 (or (boundp 'calc-graph-prev-kill-hook)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
291 (if calc-emacs-type-19
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
292 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
293 (setq calc-graph-prev-kill-hook nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
294 (add-hook 'kill-emacs-hook 'calc-graph-kill-hook))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
295 (setq calc-graph-prev-kill-hook kill-emacs-hook)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
296 (setq kill-emacs-hook 'calc-graph-kill-hook)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
297 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
298 (calc-graph-init)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
299 (set-buffer tempbuf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
300 (erase-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
301 (set-buffer calc-gnuplot-input)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
302 (goto-char (point-min))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
303 (setq is-splot (re-search-forward "^splot[ \t]" nil t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
304 (let ((str (buffer-string))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
305 (ver calc-gnuplot-version))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
306 (set-buffer (get-buffer-create "*Gnuplot Temp*"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
307 (erase-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
308 (insert "# (Note: This is a temporary copy---do not edit!)\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
309 (if (>= ver 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
310 (insert "set noarrow\nset nolabel\n"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
311 "set autoscale xy\nset nologscale xy\n"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
312 "set xlabel\nset ylabel\nset title\n"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
313 "set noclip points\nset clip one\nset clip two\n"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
314 "set format \"%g\"\nset tics\nset xtics\nset ytics\n"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
315 "set data style linespoints\n"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
316 "set nogrid\nset nokey\nset nopolar\n"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
317 (if (>= ver 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
318 (insert "set surface\nset nocontour\n"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
319 "set " (if is-splot "" "no") "parametric\n"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
320 "set notime\nset border\nset ztics\nset zeroaxis\n"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
321 "set view 60,30,1,1\nset offsets 0,0,0,0\n"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
322 (setq samples-pos (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
323 (insert "\n\n" str))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
324 (goto-char (point-min))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
325 (if is-splot
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
326 (if refine
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
327 (error "This option works only for 2d plots")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
328 (setq recompute t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
329 (let ((calc-gnuplot-input (current-buffer))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
330 (calc-graph-no-auto-view t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
331 (if printing
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
332 (setq device calc-gnuplot-print-device
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
333 output calc-gnuplot-print-output)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
334 (setq device (calc-graph-find-command "terminal")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
335 output (calc-graph-find-command "output"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
336 (or device
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
337 (setq device calc-gnuplot-default-device))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
338 (if output
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
339 (setq output (car (read-from-string output)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
340 (setq output calc-gnuplot-default-output)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
341 (if (or (equal device "") (equal device "default"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
342 (setq device (if printing
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
343 "postscript"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
344 (if (or (eq window-system 'x) (getenv "DISPLAY"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
345 "x11"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
346 (if (>= calc-gnuplot-version 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
347 "dumb" "postscript")))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
348 (if (equal device "dumb")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
349 (setq device (format "dumb %d %d"
40998
ee9c2872370b Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents: 40785
diff changeset
350 (1- (frame-width)) (1- (frame-height)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
351 (if (equal device "big")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
352 (setq device (format "dumb %d %d"
40998
ee9c2872370b Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents: 40785
diff changeset
353 (* 4 (- (frame-width) 3))
ee9c2872370b Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents: 40785
diff changeset
354 (* 4 (- (frame-height) 3)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
355 (if (stringp output)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
356 (if (or (equal output "auto")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
357 (and (equal output "tty") (setq tty-output t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
358 (setq tempoutfile (calc-temp-file-name -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
359 output tempoutfile))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
360 (setq output (eval output)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
361 (or (equal device calc-graph-last-device)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
362 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
363 (setq calc-graph-last-device device)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
364 (calc-gnuplot-command "set terminal" device)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
365 (or (equal output calc-graph-last-output)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
366 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
367 (setq calc-graph-last-output output)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
368 (calc-gnuplot-command "set output"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
369 (if (equal output "STDOUT")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
370 ""
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
371 (prin1-to-string output)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
372 (setq resolution (calc-graph-find-command "samples"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
373 (if resolution
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
374 (setq resolution (string-to-int resolution))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
375 (setq resolution (if is-splot
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
376 calc-graph-default-resolution-3d
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
377 calc-graph-default-resolution)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
378 (setq precision (calc-graph-find-command "precision"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
379 (if precision
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
380 (setq precision (string-to-int precision))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
381 (setq precision calc-graph-default-precision))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
382 (calc-graph-set-command "terminal")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
383 (calc-graph-set-command "output")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
384 (calc-graph-set-command "samples")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
385 (calc-graph-set-command "precision"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
386 (goto-char samples-pos)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
387 (insert "set samples " (int-to-string (max (if is-splot 20 200)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
388 (+ 5 resolution))) "\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
389 (while (re-search-forward "{\\*[^}]+}[^,\n]*" nil t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
390 (delete-region (match-beginning 0) (match-end 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
391 (if (looking-at ",")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
392 (delete-char 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
393 (while (memq (preceding-char) '(?\ ?\t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
394 (forward-char -1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
395 (if (eq (preceding-char) ?\,)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
396 (delete-backward-char 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
397 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
398 (set-buffer calcbuf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
399 (setq cache-env (list calc-angle-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
400 calc-complex-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
401 calc-simplify-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
402 calc-infinite-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
403 calc-word-size
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
404 precision is-splot))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
405 (if (and (not recompute)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
406 (equal (cdr (car calc-graph-data-cache)) cache-env))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
407 (while (> (length calc-graph-data-cache)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
408 calc-graph-data-cache-limit)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
409 (setcdr calc-graph-data-cache
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
410 (cdr (cdr calc-graph-data-cache))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
411 (setq calc-graph-data-cache (list (cons nil cache-env)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
412 (calc-graph-find-plot t t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
413 (while (re-search-forward
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
414 (if is-splot
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
415 "{\\([^{}:\n]+\\):\\([^{}:\n]+\\):\\([^{}:\n]+\\)}"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
416 "{\\([^{}:\n]+\\)\\(:\\)\\([^{}:\n]+\\)}")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
417 nil t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
418 (setq curve-num (1+ curve-num))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
419 (let* ((xname (buffer-substring (match-beginning 1) (match-end 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
420 (xvar (intern (concat "var-" xname)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
421 (xvalue (math-evaluate-expr (calc-var-value xvar)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
422 (y3name (and is-splot
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
423 (buffer-substring (match-beginning 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
424 (match-end 2))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
425 (y3var (and is-splot (intern (concat "var-" y3name))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
426 (y3value (and is-splot (calc-var-value y3var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
427 (yname (buffer-substring (match-beginning 3) (match-end 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
428 (yvar (intern (concat "var-" yname)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
429 (yvalue (calc-var-value yvar))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
430 filename)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
431 (delete-region (match-beginning 0) (match-end 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
432 (setq filename (calc-temp-file-name curve-num))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
433 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
434 (set-buffer calcbuf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
435 (let (tempbuftop
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
436 (xp xvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
437 (yp yvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
438 (zp nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
439 (xlow nil) (xhigh nil) (y3low nil) (y3high nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
440 xvec xval xstep var-DUMMY
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
441 y3vec y3val y3step var-DUMMY2 (zval nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
442 yvec yval ycache ycacheptr yvector
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
443 numsteps numsteps3
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
444 (keep-file (and (not is-splot) (file-exists-p filename)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
445 (stepcount 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
446 (calc-symbolic-mode nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
447 (calc-prefer-frac nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
448 (calc-internal-prec (max 3 precision))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
449 (calc-simplify-mode (and (not (memq calc-simplify-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
450 '(none num)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
451 calc-simplify-mode))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
452 (blank t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
453 (non-blank nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
454 (math-working-step 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
455 (math-working-step-2 nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
456 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
457 (if is-splot
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
458 (calc-graph-compute-3d)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
459 (calc-graph-compute-2d))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
460 (set-buffer tempbuf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
461 (goto-char (point-max))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
462 (insert "\n" xname)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
463 (if is-splot
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
464 (insert ":" y3name))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
465 (insert ":" yname "\n\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
466 (setq tempbuftop (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
467 (let ((calc-group-digits nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
468 (calc-leading-zeros nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
469 (calc-number-radix 10)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
470 (entry (and (not is-splot)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
471 (list xp yp xhigh numsteps))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
472 (or (equal entry
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
473 (nth 1 (nth (1+ curve-num)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
474 calc-graph-file-cache)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
475 (setq keep-file nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
476 (setcar (cdr (nth (1+ curve-num) calc-graph-file-cache))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
477 entry)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
478 (or keep-file
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
479 (calc-graph-format-data)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
480 (or keep-file
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
481 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
482 (or non-blank
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
483 (error "No valid data points for %s:%s"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
484 xname yname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
485 (write-region tempbuftop (point-max) filename
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
486 nil 'quiet))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
487 (insert (prin1-to-string filename))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
488 (if surprise-splot
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
489 (setcdr cache-env nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
490 (if (= curve-num 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
491 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
492 (calc-gnuplot-command "clear")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
493 (calc-clear-command-flag 'clear-message)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
494 (message "No data to plot!"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
495 (setq calc-graph-data-cache-limit (max curve-num
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
496 calc-graph-data-cache-limit)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
497 filename (calc-temp-file-name 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
498 (write-region (point-min) (point-max) filename nil 'quiet)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
499 (calc-gnuplot-command "load" (prin1-to-string filename))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
500 (or (equal output "STDOUT")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
501 calc-gnuplot-keep-outfile
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
502 (progn ; need to close the output file before printing/plotting
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
503 (setq calc-graph-last-output "STDOUT")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
504 (calc-gnuplot-command "set output")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
505 (let ((command (if printing
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
506 calc-gnuplot-print-command
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
507 (or calc-gnuplot-plot-command
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
508 (and (string-match "^dumb" device)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
509 'calc-graph-show-dumb)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
510 (and tty-output
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
511 'calc-graph-show-tty)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
512 (if command
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
513 (if (stringp command)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
514 (calc-gnuplot-command
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
515 "!" (format command
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
516 (or tempoutfile
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
517 calc-gnuplot-print-output)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
518 (if (symbolp command)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
519 (funcall command output)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
520 (eval command))))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
521
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
522 (defun calc-graph-compute-2d ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
523 (if (setq yvec (eq (car-safe yvalue) 'vec))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
524 (if (= (setq numsteps (1- (length yvalue))) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
525 (error "Can't plot an empty vector")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
526 (if (setq xvec (eq (car-safe xvalue) 'vec))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
527 (or (= (1- (length xvalue)) numsteps)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
528 (error "%s and %s have different lengths" xname yname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
529 (if (and (eq (car-safe xvalue) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
530 (math-constp xvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
531 (setq xstep (math-div (math-sub (nth 3 xvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
532 (nth 2 xvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
533 (1- numsteps))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
534 xvalue (nth 2 xvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
535 (if (math-realp xvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
536 (setq xstep 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
537 (error "%s is not a suitable basis for %s" xname yname)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
538 (or (math-realp yvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
539 (let ((arglist nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
540 (setq yvalue (math-evaluate-expr yvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
541 (calc-default-formula-arglist yvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
542 (or arglist
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
543 (error "%s does not contain any unassigned variables" yname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
544 (and (cdr arglist)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
545 (error "%s contains more than one variable: %s"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
546 yname arglist))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
547 (setq yvalue (math-expr-subst yvalue
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
548 (math-build-var-name (car arglist))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
549 '(var DUMMY var-DUMMY)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
550 (setq ycache (assoc yvalue calc-graph-data-cache))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
551 (delq ycache calc-graph-data-cache)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
552 (nconc calc-graph-data-cache
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
553 (list (or ycache (setq ycache (list yvalue)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
554 (if (and (not (setq xvec (eq (car-safe xvalue) 'vec)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
555 refine (cdr (cdr ycache)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
556 (calc-graph-refine-2d)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
557 (calc-graph-recompute-2d))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
558
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
559 (defun calc-graph-refine-2d ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
560 (setq keep-file nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
561 ycacheptr (cdr ycache))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
562 (if (and (setq xval (calc-graph-find-command "xrange"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
563 (string-match "\\`\\[\\([0-9.eE+-]*\\):\\([0-9.eE+-]*\\)\\]\\'"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
564 xval))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
565 (let ((b2 (match-beginning 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
566 (e2 (match-end 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
567 (setq xlow (math-read-number (substring xval
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
568 (match-beginning 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
569 (match-end 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
570 xhigh (math-read-number (substring xval b2 e2))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
571 (if xlow
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
572 (while (and (cdr ycacheptr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
573 (Math-lessp (car (nth 1 ycacheptr)) xlow))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
574 (setq ycacheptr (cdr ycacheptr)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
575 (setq math-working-step-2 (1- (length ycacheptr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
576 (while (and (cdr ycacheptr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
577 (or (not xhigh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
578 (Math-lessp (car (car ycacheptr)) xhigh)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
579 (setq var-DUMMY (math-div (math-add (car (car ycacheptr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
580 (car (nth 1 ycacheptr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
581 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
582 math-working-step (1+ math-working-step)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
583 yval (math-evaluate-expr yvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
584 (setcdr ycacheptr (cons (cons var-DUMMY yval)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
585 (cdr ycacheptr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
586 (setq ycacheptr (cdr (cdr ycacheptr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
587 (setq yp ycache
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
588 numsteps 1000000))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
589
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
590 (defun calc-graph-recompute-2d ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
591 (setq ycacheptr ycache)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
592 (if xvec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
593 (setq numsteps (1- (length xvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
594 yvector nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
595 (if (and (eq (car-safe xvalue) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
596 (math-constp xvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
597 (setq numsteps resolution
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
598 yp nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
599 xlow (nth 2 xvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
600 xhigh (nth 3 xvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
601 xstep (math-div (math-sub xhigh xlow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
602 (1- numsteps))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
603 xvalue (nth 2 xvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
604 (error "%s is not a suitable basis for %s"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
605 xname yname)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
606 (setq math-working-step-2 numsteps)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
607 (while (>= (setq numsteps (1- numsteps)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
608 (setq math-working-step (1+ math-working-step))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
609 (if xvec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
610 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
611 (setq xp (cdr xp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
612 xval (car xp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
613 (and (not (eq ycacheptr ycache))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
614 (consp (car ycacheptr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
615 (not (Math-lessp (car (car ycacheptr)) xval))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
616 (setq ycacheptr ycache)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
617 (if (= numsteps 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
618 (setq xval xhigh) ; avoid cumulative roundoff
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
619 (setq xval xvalue
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
620 xvalue (math-add xvalue xstep))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
621 (while (and (cdr ycacheptr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
622 (Math-lessp (car (nth 1 ycacheptr)) xval))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
623 (setq ycacheptr (cdr ycacheptr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
624 (or (and (cdr ycacheptr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
625 (Math-equal (car (nth 1 ycacheptr)) xval))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
626 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
627 (setq keep-file nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
628 var-DUMMY xval)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
629 (setcdr ycacheptr (cons (cons xval (math-evaluate-expr yvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
630 (cdr ycacheptr)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
631 (setq ycacheptr (cdr ycacheptr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
632 (if xvec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
633 (setq yvector (cons (cdr (car ycacheptr)) yvector))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
634 (or yp (setq yp ycacheptr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
635 (if xvec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
636 (setq xp xvalue
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
637 yvec t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
638 yp (cons 'vec (nreverse yvector))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
639 numsteps (1- (length xp)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
640 (setq numsteps 1000000)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
641
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
642 (defun calc-graph-compute-3d ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
643 (if (setq yvec (eq (car-safe yvalue) 'vec))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
644 (if (math-matrixp yvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
645 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
646 (setq numsteps (1- (length yvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
647 numsteps3 (1- (length (nth 1 yvalue))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
648 (if (eq (car-safe xvalue) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
649 (or (= (1- (length xvalue)) numsteps)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
650 (error "%s has wrong length" xname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
651 (if (and (eq (car-safe xvalue) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
652 (math-constp xvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
653 (setq xvalue (calcFunc-index numsteps
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
654 (nth 2 xvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
655 (math-div
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
656 (math-sub (nth 3 xvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
657 (nth 2 xvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
658 (1- numsteps))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
659 (if (math-realp xvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
660 (setq xvalue (calcFunc-index numsteps xvalue 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
661 (error "%s is not a suitable basis for %s" xname yname))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
662 (if (eq (car-safe y3value) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
663 (or (= (1- (length y3value)) numsteps3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
664 (error "%s has wrong length" y3name))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
665 (if (and (eq (car-safe y3value) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
666 (math-constp y3value))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
667 (setq y3value (calcFunc-index numsteps3
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
668 (nth 2 y3value)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
669 (math-div
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
670 (math-sub (nth 3 y3value)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
671 (nth 2 y3value))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
672 (1- numsteps3))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
673 (if (math-realp y3value)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
674 (setq y3value (calcFunc-index numsteps3 y3value 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
675 (error "%s is not a suitable basis for %s" y3name yname))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
676 (setq xp nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
677 yp nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
678 zp nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
679 xvec t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
680 (while (setq xvalue (cdr xvalue) yvalue (cdr yvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
681 (setq xp (nconc xp (make-list (1+ numsteps3) (car xvalue)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
682 yp (nconc yp (cons 0 (copy-sequence (cdr y3value))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
683 zp (nconc zp (cons '(skip)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
684 (copy-sequence (cdr (car yvalue)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
685 (setq numsteps (1- (* numsteps (1+ numsteps3)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
686 (if (= (setq numsteps (1- (length yvalue))) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
687 (error "Can't plot an empty vector"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
688 (or (and (eq (car-safe xvalue) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
689 (= (1- (length xvalue)) numsteps))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
690 (error "%s is not a suitable basis for %s" xname yname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
691 (or (and (eq (car-safe y3value) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
692 (= (1- (length y3value)) numsteps))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
693 (error "%s is not a suitable basis for %s" y3name yname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
694 (setq xp xvalue
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
695 yp y3value
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
696 zp yvalue
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
697 xvec t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
698 (or (math-realp yvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
699 (let ((arglist nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
700 (setq yvalue (math-evaluate-expr yvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
701 (calc-default-formula-arglist yvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
702 (setq arglist (sort arglist 'string-lessp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
703 (or (cdr arglist)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
704 (error "%s does not contain enough unassigned variables" yname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
705 (and (cdr (cdr arglist))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
706 (error "%s contains too many variables: %s" yname arglist))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
707 (setq yvalue (math-multi-subst yvalue
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
708 (mapcar 'math-build-var-name
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
709 arglist)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
710 '((var DUMMY var-DUMMY)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
711 (var DUMMY2 var-DUMMY2))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
712 (if (setq xvec (eq (car-safe xvalue) 'vec))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
713 (setq numsteps (1- (length xvalue)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
714 (if (and (eq (car-safe xvalue) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
715 (math-constp xvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
716 (setq numsteps resolution
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
717 xvalue (calcFunc-index numsteps
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
718 (nth 2 xvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
719 (math-div (math-sub (nth 3 xvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
720 (nth 2 xvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
721 (1- numsteps))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
722 (error "%s is not a suitable basis for %s"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
723 xname yname)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
724 (if (setq y3vec (eq (car-safe y3value) 'vec))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
725 (setq numsteps3 (1- (length y3value)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
726 (if (and (eq (car-safe y3value) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
727 (math-constp y3value))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
728 (setq numsteps3 resolution
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
729 y3value (calcFunc-index numsteps3
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
730 (nth 2 y3value)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
731 (math-div (math-sub (nth 3 y3value)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
732 (nth 2 y3value))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
733 (1- numsteps3))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
734 (error "%s is not a suitable basis for %s"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
735 y3name yname)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
736 (setq xp nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
737 yp nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
738 zp nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
739 xvec t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
740 (setq math-working-step 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
741 (while (setq xvalue (cdr xvalue))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
742 (setq xp (nconc xp (make-list (1+ numsteps3) (car xvalue)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
743 yp (nconc yp (cons 0 (copy-sequence (cdr y3value))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
744 zp (cons '(skip) zp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
745 y3step y3value
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
746 var-DUMMY (car xvalue)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
747 math-working-step-2 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
748 math-working-step (1+ math-working-step))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
749 (while (setq y3step (cdr y3step))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
750 (setq math-working-step-2 (1+ math-working-step-2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
751 var-DUMMY2 (car y3step)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
752 zp (cons (math-evaluate-expr yvalue) zp))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
753 (setq zp (nreverse zp)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
754 numsteps (1- (* numsteps (1+ numsteps3))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
755
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
756 (defun calc-graph-format-data ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
757 (while (<= (setq stepcount (1+ stepcount)) numsteps)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
758 (if xvec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
759 (setq xp (cdr xp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
760 xval (car xp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
761 yp (cdr yp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
762 yval (car yp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
763 zp (cdr zp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
764 zval (car zp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
765 (if yvec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
766 (setq xval xvalue
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
767 xvalue (math-add xvalue xstep)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
768 yp (cdr yp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
769 yval (car yp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
770 (setq xval (car (car yp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
771 yval (cdr (car yp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
772 yp (cdr yp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
773 (if (or (not yp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
774 (and xhigh (equal xval xhigh)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
775 (setq numsteps 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
776 (if is-splot
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
777 (if (and (eq (car-safe zval) 'calcFunc-xyz)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
778 (= (length zval) 4))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
779 (setq xval (nth 1 zval)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
780 yval (nth 2 zval)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
781 zval (nth 3 zval)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
782 (if (and (eq (car-safe yval) 'calcFunc-xyz)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
783 (= (length yval) 4))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
784 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
785 (or surprise-splot
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
786 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
787 (set-buffer (get-buffer-create "*Gnuplot Temp*"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
788 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
789 (goto-char (point-max))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
790 (re-search-backward "^plot[ \t]")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
791 (insert "set parametric\ns")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
792 (setq surprise-splot t))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
793 (setq xval (nth 1 yval)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
794 zval (nth 3 yval)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
795 yval (nth 2 yval)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
796 (if (and (eq (car-safe yval) 'calcFunc-xy)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
797 (= (length yval) 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
798 (setq xval (nth 1 yval)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
799 yval (nth 2 yval)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
800 (if (and (Math-realp xval)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
801 (Math-realp yval)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
802 (or (not zval) (Math-realp zval)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
803 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
804 (setq blank nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
805 non-blank t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
806 (if (Math-integerp xval)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
807 (insert (math-format-number xval))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
808 (if (eq (car xval) 'frac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
809 (setq xval (math-float xval)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
810 (insert (math-format-number (nth 1 xval))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
811 "e" (int-to-string (nth 2 xval))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
812 (insert " ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
813 (if (Math-integerp yval)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
814 (insert (math-format-number yval))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
815 (if (eq (car yval) 'frac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
816 (setq yval (math-float yval)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
817 (insert (math-format-number (nth 1 yval))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
818 "e" (int-to-string (nth 2 yval))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
819 (if zval
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
820 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
821 (insert " ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
822 (if (Math-integerp zval)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
823 (insert (math-format-number zval))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
824 (if (eq (car zval) 'frac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
825 (setq zval (math-float zval)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
826 (insert (math-format-number (nth 1 zval))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
827 "e" (int-to-string (nth 2 zval))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
828 (insert "\n"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
829 (and (not (equal zval '(skip)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
830 (boundp 'var-PlotRejects)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
831 (eq (car-safe var-PlotRejects) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
832 (nconc var-PlotRejects
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
833 (list (list 'vec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
834 curve-num
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
835 stepcount
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
836 xval yval)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
837 (calc-refresh-evaltos 'var-PlotRejects))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
838 (or blank
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
839 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
840 (insert "\n")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
841 (setq blank t))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
842
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
843 (defun calc-temp-file-name (num)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
844 (while (<= (length calc-graph-file-cache) (1+ num))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
845 (setq calc-graph-file-cache (nconc calc-graph-file-cache (list nil))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
846 (car (or (nth (1+ num) calc-graph-file-cache)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
847 (setcar (nthcdr (1+ num) calc-graph-file-cache)
43606
54abc38794d9 (calc-gnuplot-tempfile): Don't expand against
Colin Walters <walters@gnu.org>
parents: 41271
diff changeset
848 (list (make-temp-file
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
849 (concat calc-gnuplot-tempfile
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
850 (if (<= num 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
851 (char-to-string (- ?A num))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
852 (int-to-string num))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
853 nil)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
854
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
855 (defun calc-graph-delete-temps ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
856 (while calc-graph-file-cache
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
857 (and (car calc-graph-file-cache)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
858 (file-exists-p (car (car calc-graph-file-cache)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
859 (condition-case err
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
860 (delete-file (car (car calc-graph-file-cache)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
861 (error nil)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
862 (setq calc-graph-file-cache (cdr calc-graph-file-cache))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
863
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
864 (defun calc-graph-kill-hook ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
865 (calc-graph-delete-temps)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
866 (if calc-graph-prev-kill-hook
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
867 (funcall calc-graph-prev-kill-hook)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
868
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
869 (defun calc-graph-show-tty (output)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
870 "Default calc-gnuplot-plot-command for \"tty\" output mode.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
871 This is useful for tek40xx and other graphics-terminal types."
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
872 (call-process-region 1 1 shell-file-name
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
873 nil calc-gnuplot-buffer nil
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
874 "-c" (format "cat %s >/dev/tty; rm %s" output output)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
875
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
876 (defun calc-graph-show-dumb (&optional output)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
877 "Default calc-gnuplot-plot-command for Pinard's \"dumb\" terminal type.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
878 This \"dumb\" driver will be present in Gnuplot 3.0."
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
879 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
880 (save-window-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
881 (switch-to-buffer calc-gnuplot-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
882 (delete-other-windows)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
883 (goto-char calc-gnuplot-trail-mark)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
884 (or (search-forward "\f" nil t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
885 (sleep-for 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
886 (goto-char (point-max))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
887 (re-search-backward "\f\\|^[ \t]+\\^$\\|G N U P L O T")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
888 (setq found-pt (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
889 (if (looking-at "\f")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
890 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
891 (forward-char 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
892 (if (eolp) (forward-line 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
893 (or (calc-graph-find-command "time")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
894 (calc-graph-find-command "title")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
895 (calc-graph-find-command "ylabel")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
896 (let ((pt (point)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
897 (insert-before-markers (format "(%s)" (current-time-string)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
898 (goto-char pt)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
899 (set-window-start (selected-window) (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
900 (goto-char (point-max)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
901 (end-of-line)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
902 (backward-char 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
903 (recenter '(4)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
904 (or (boundp 'calc-dumb-map)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
905 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
906 (setq calc-dumb-map (make-sparse-keymap))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
907 (define-key calc-dumb-map "\n" 'scroll-up)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
908 (define-key calc-dumb-map " " 'scroll-up)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
909 (define-key calc-dumb-map "\177" 'scroll-down)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
910 (define-key calc-dumb-map "<" 'scroll-left)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
911 (define-key calc-dumb-map ">" 'scroll-right)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
912 (define-key calc-dumb-map "{" 'scroll-down)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
913 (define-key calc-dumb-map "}" 'scroll-up)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
914 (define-key calc-dumb-map "q" 'exit-recursive-edit)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
915 (define-key calc-dumb-map "\C-c\C-c" 'exit-recursive-edit)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
916 (use-local-map calc-dumb-map)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
917 (setq truncate-lines t)
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
918 (message "Type `q'%s to return to Calc"
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
919 (if (eq (lookup-key (current-global-map) "\e#") 'calc-dispatch)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
920 " or `M-# M-#'" ""))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
921 (recursive-edit)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
922 (bury-buffer "*Gnuplot Trail*")))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
923
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
924 (defun calc-graph-clear ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
925 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
926 (if calc-graph-last-device
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
927 (if (or (equal calc-graph-last-device "x11")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
928 (equal calc-graph-last-device "X11"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
929 (calc-gnuplot-command "set output"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
930 (if (equal calc-graph-last-output "STDOUT")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
931 ""
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
932 (prin1-to-string calc-graph-last-output)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
933 (calc-gnuplot-command "clear"))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
934
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
935 (defun calc-graph-title-x (title)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
936 (interactive "sX axis title: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
937 (calc-graph-set-command "xlabel" (if (not (equal title ""))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
938 (prin1-to-string title))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
939
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
940 (defun calc-graph-title-y (title)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
941 (interactive "sY axis title: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
942 (calc-graph-set-command "ylabel" (if (not (equal title ""))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
943 (prin1-to-string title))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
944
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
945 (defun calc-graph-title-z (title)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
946 (interactive "sZ axis title: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
947 (calc-graph-set-command "zlabel" (if (not (equal title ""))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
948 (prin1-to-string title))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
949
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
950 (defun calc-graph-range-x (range)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
951 (interactive "sX axis range: ")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
952 (calc-graph-set-range "xrange" range))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
953
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
954 (defun calc-graph-range-y (range)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
955 (interactive "sY axis range: ")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
956 (calc-graph-set-range "yrange" range))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
957
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
958 (defun calc-graph-range-z (range)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
959 (interactive "sZ axis range: ")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
960 (calc-graph-set-range "zrange" range))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
961
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
962 (defun calc-graph-set-range (cmd range)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
963 (if (equal range "$")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
964 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
965 (let ((val (calc-top-n 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
966 (if (and (eq (car-safe val) 'intv) (math-constp val))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
967 (setq range (concat
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
968 (math-format-number (math-float (nth 2 val))) ":"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
969 (math-format-number (math-float (nth 3 val)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
970 (if (and (eq (car-safe val) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
971 (= (length val) 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
972 (setq range (concat
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
973 (math-format-number (math-float (nth 1 val))) ":"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
974 (math-format-number (math-float (nth 2 val)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
975 (error "Range specification must be an interval or 2-vector")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
976 (calc-pop-stack 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
977 (if (string-match "\\[.+\\]" range)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
978 (setq range (substring range 1 -1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
979 (if (and (not (string-match ":" range))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
980 (or (string-match "," range)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
981 (string-match " " range)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
982 (aset range (match-beginning 0) ?\:))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
983 (calc-graph-set-command cmd (if (not (equal range ""))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
984 (concat "[" range "]"))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
985
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
986 (defun calc-graph-log-x (flag)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
987 (interactive "P")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
988 (calc-graph-set-log flag 0 0))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
989
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
990 (defun calc-graph-log-y (flag)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
991 (interactive "P")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
992 (calc-graph-set-log 0 flag 0))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
993
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
994 (defun calc-graph-log-z (flag)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
995 (interactive "P")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
996 (calc-graph-set-log 0 0 flag))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
997
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
998 (defun calc-graph-set-log (xflag yflag zflag)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
999 (let* ((old (or (calc-graph-find-command "logscale") ""))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1000 (xold (string-match "x" old))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1001 (yold (string-match "y" old))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1002 (zold (string-match "z" old))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1003 str)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1004 (setq str (concat (if (if xflag
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1005 (if (eq xflag 0) xold
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1006 (> (prefix-numeric-value xflag) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1007 (not xold)) "x" "")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1008 (if (if yflag
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1009 (if (eq yflag 0) yold
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1010 (> (prefix-numeric-value yflag) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1011 (not yold)) "y" "")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1012 (if (if zflag
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1013 (if (eq zflag 0) zold
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1014 (> (prefix-numeric-value zflag) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1015 (not zold)) "z" "")))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1016 (calc-graph-set-command "logscale" (if (not (equal str "")) str))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1017
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1018 (defun calc-graph-line-style (style)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1019 (interactive "P")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1020 (calc-graph-set-styles (and style (prefix-numeric-value style)) t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1021
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1022 (defun calc-graph-point-style (style)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1023 (interactive "P")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1024 (calc-graph-set-styles t (and style (prefix-numeric-value style))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1025
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1026 (defun calc-graph-set-styles (lines points)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1027 (calc-graph-init)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1028 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1029 (set-buffer calc-gnuplot-input)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1030 (or (calc-graph-find-plot nil nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1031 (error "No data points have been set!"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1032 (let ((base (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1033 (mode nil) (lstyle nil) (pstyle nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1034 start end lenbl penbl)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1035 (re-search-forward "[,\n]")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1036 (forward-char -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1037 (setq end (point) start end)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1038 (goto-char base)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1039 (if (looking-at "[^,\n]*[^,\n \t]\\([ \t]+with\\)")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1040 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1041 (setq start (match-beginning 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1042 (goto-char (match-end 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1043 (if (looking-at "[ \t]+\\([a-z]+\\)")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1044 (setq mode (buffer-substring (match-beginning 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1045 (match-end 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1046 (if (looking-at "[ \ta-z]+\\([0-9]+\\)")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1047 (setq lstyle (string-to-int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1048 (buffer-substring (match-beginning 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1049 (match-end 1)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1050 (if (looking-at "[ \ta-z]+[0-9]+[ \t]+\\([0-9]+\\)")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1051 (setq pstyle (string-to-int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1052 (buffer-substring (match-beginning 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1053 (match-end 1)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1054 (setq lenbl (or (equal mode "lines") (equal mode "linespoints"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1055 penbl (or (equal mode "points") (equal mode "linespoints")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1056 (if lines
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1057 (or (eq lines t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1058 (setq lstyle lines
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1059 lenbl (>= lines 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1060 (setq lenbl (not lenbl)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1061 (if points
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1062 (or (eq points t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1063 (setq pstyle points
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1064 penbl (>= points 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1065 (setq penbl (not penbl)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1066 (delete-region start end)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1067 (goto-char start)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1068 (insert " with "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1069 (if lenbl
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1070 (if penbl "linespoints" "lines")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1071 (if penbl "points" "dots")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1072 (if (and pstyle (> pstyle 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1073 (insert " " (if (and lstyle (> lstyle 0)) (int-to-string lstyle) "1")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1074 " " (int-to-string pstyle))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1075 (if (and lstyle (> lstyle 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1076 (insert " " (int-to-string lstyle))))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1077 (calc-graph-view-commands))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1078
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1079 (defun calc-graph-zero-x (flag)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1080 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1081 (calc-graph-set-command "noxzeroaxis"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1082 (and (if flag
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1083 (<= (prefix-numeric-value flag) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1084 (not (calc-graph-find-command "noxzeroaxis")))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1085 " ")))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1086
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1087 (defun calc-graph-zero-y (flag)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1088 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1089 (calc-graph-set-command "noyzeroaxis"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1090 (and (if flag
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1091 (<= (prefix-numeric-value flag) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1092 (not (calc-graph-find-command "noyzeroaxis")))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1093 " ")))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1094
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1095 (defun calc-graph-name (name)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1096 (interactive "sTitle for current curve: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1097 (calc-graph-init)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1098 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1099 (set-buffer calc-gnuplot-input)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1100 (or (calc-graph-find-plot nil nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1101 (error "No data points have been set!"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1102 (let ((base (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1103 start)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1104 (re-search-forward "[,\n]\\|[ \t]+with")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1105 (setq end (match-beginning 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1106 (goto-char base)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1107 (if (looking-at "[^,\n]*[^,\n \t]\\([ \t]+title\\)")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1108 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1109 (goto-char (match-beginning 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1110 (delete-region (point) end))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1111 (goto-char end))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1112 (insert " title " (prin1-to-string name))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1113 (calc-graph-view-commands))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1114
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1115 (defun calc-graph-hide (flag)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1116 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1117 (calc-graph-init)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1118 (and (calc-graph-find-plot nil nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1119 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1120 (or (looking-at "{")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1121 (error "Can't hide this curve (wrong format)"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1122 (forward-char 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1123 (if (looking-at "*")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1124 (if (or (null flag) (<= (prefix-numeric-value flag) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1125 (delete-char 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1126 (if (or (null flag) (> (prefix-numeric-value flag) 0))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1127 (insert "*"))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1128
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1129 (defun calc-graph-header (title)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1130 (interactive "sTitle for entire graph: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1131 (calc-graph-set-command "title" (if (not (equal title ""))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1132 (prin1-to-string title))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1133
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1134 (defun calc-graph-border (flag)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1135 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1136 (calc-graph-set-command "noborder"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1137 (and (if flag
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1138 (<= (prefix-numeric-value flag) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1139 (not (calc-graph-find-command "noborder")))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1140 " ")))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1141
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1142 (defun calc-graph-grid (flag)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1143 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1144 (calc-graph-set-command "grid" (and (if flag
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1145 (> (prefix-numeric-value flag) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1146 (not (calc-graph-find-command "grid")))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1147 " ")))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1148
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1149 (defun calc-graph-key (flag)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1150 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1151 (calc-graph-set-command "key" (and (if flag
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1152 (> (prefix-numeric-value flag) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1153 (not (calc-graph-find-command "key")))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1154 " ")))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1155
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1156 (defun calc-graph-num-points (res flag)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1157 (interactive "sNumber of data points: \nP")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1158 (if flag
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1159 (if (> (prefix-numeric-value flag) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1160 (if (equal res "")
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1161 (message "Default resolution is %d"
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1162 calc-graph-default-resolution)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1163 (setq calc-graph-default-resolution (string-to-int res)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1164 (if (equal res "")
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1165 (message "Default 3D resolution is %d"
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1166 calc-graph-default-resolution-3d)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1167 (setq calc-graph-default-resolution-3d (string-to-int res))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1168 (calc-graph-set-command "samples" (if (not (equal res "")) res))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1169
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1170 (defun calc-graph-device (name flag)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1171 (interactive "sDevice name: \nP")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1172 (if (equal name "?")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1173 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1174 (calc-gnuplot-command "set terminal")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1175 (calc-graph-view-trail))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1176 (if flag
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1177 (if (> (prefix-numeric-value flag) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1178 (if (equal name "")
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1179 (message "Default GNUPLOT device is \"%s\""
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1180 calc-gnuplot-default-device)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1181 (setq calc-gnuplot-default-device name))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1182 (if (equal name "")
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1183 (message "GNUPLOT device for Print command is \"%s\""
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1184 calc-gnuplot-print-device)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1185 (setq calc-gnuplot-print-device name)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1186 (calc-graph-set-command "terminal" (if (not (equal name ""))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1187 name)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1188
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1189 (defun calc-graph-output (name flag)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1190 (interactive "FOutput file name: \np")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1191 (cond ((string-match "\\<[aA][uU][tT][oO]$" name)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1192 (setq name "auto"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1193 ((string-match "\\<[tT][tT][yY]$" name)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1194 (setq name "tty"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1195 ((string-match "\\<[sS][tT][dD][oO][uU][tT]$" name)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1196 (setq name "STDOUT"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1197 ((equal (file-name-nondirectory name) "")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1198 (setq name ""))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1199 (t (setq name (expand-file-name name))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1200 (if flag
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1201 (if (> (prefix-numeric-value flag) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1202 (if (equal name "")
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1203 (message "Default GNUPLOT output file is \"%s\""
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1204 calc-gnuplot-default-output)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1205 (setq calc-gnuplot-default-output name))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1206 (if (equal name "")
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1207 (message "GNUPLOT output file for Print command is \"%s\""
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1208 calc-gnuplot-print-output)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1209 (setq calc-gnuplot-print-output name)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1210 (calc-graph-set-command "output" (if (not (equal name ""))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1211 (prin1-to-string name)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1212
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1213 (defun calc-graph-display (name)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1214 (interactive "sX display name: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1215 (if (equal name "")
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1216 (message "Current X display is \"%s\""
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1217 (or calc-gnuplot-display "<none>"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1218 (setq calc-gnuplot-display name)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1219 (if (calc-gnuplot-alive)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1220 (calc-gnuplot-command "exit"))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1221
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1222 (defun calc-graph-geometry (name)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1223 (interactive "sX geometry spec (or \"default\"): ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1224 (if (equal name "")
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1225 (message "Current X geometry is \"%s\""
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1226 (or calc-gnuplot-geometry "default"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1227 (setq calc-gnuplot-geometry (and (not (equal name "default")) name))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1228 (if (calc-gnuplot-alive)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1229 (calc-gnuplot-command "exit"))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1230
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1231 (defun calc-graph-find-command (cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1232 (calc-graph-init)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1233 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1234 (set-buffer calc-gnuplot-input)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1235 (goto-char (point-min))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1236 (if (re-search-forward (concat "^set[ \t]+" cmd "[ \t]*\\(.*\\)$") nil t)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1237 (buffer-substring (match-beginning 1) (match-end 1)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1238
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1239 (defun calc-graph-set-command (cmd &rest args)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1240 (calc-graph-init)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1241 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1242 (set-buffer calc-gnuplot-input)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1243 (goto-char (point-min))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1244 (if (re-search-forward (concat "^set[ \t]+" cmd "[ \t\n]") nil t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1245 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1246 (forward-char -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1247 (end-of-line)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1248 (let ((end (point)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1249 (beginning-of-line)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1250 (delete-region (point) (1+ end))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1251 (if (calc-graph-find-plot t t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1252 (if (eq (preceding-char) ?\n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1253 (forward-char -1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1254 (goto-char (1- (point-max)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1255 (if (and args (car args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1256 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1257 (or (bolp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1258 (insert "\n"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1259 (insert "set " (mapconcat 'identity (cons cmd args) " ") "\n"))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1260 (calc-graph-view-commands))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1261
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1262 (defun calc-graph-command (cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1263 (interactive "sGNUPLOT command: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1264 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1265 (calc-graph-init)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1266 (calc-graph-view-trail)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1267 (calc-gnuplot-command cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1268 (accept-process-output)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1269 (calc-graph-view-trail)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1270
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1271 (defun calc-graph-kill (&optional no-view)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1272 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1273 (calc-graph-delete-temps)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1274 (if (calc-gnuplot-alive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1275 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1276 (or no-view (calc-graph-view-trail))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1277 (let ((calc-graph-no-wait t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1278 (calc-gnuplot-command "exit"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1279 (sit-for 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1280 (if (process-status calc-gnuplot-process)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1281 (delete-process calc-gnuplot-process))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1282 (setq calc-gnuplot-process nil))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1283
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1284 (defun calc-graph-quit ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1285 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1286 (if (get-buffer-window calc-gnuplot-input)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1287 (calc-graph-view-commands t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1288 (if (get-buffer-window calc-gnuplot-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1289 (calc-graph-view-trail t))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1290 (calc-graph-kill t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1291
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1292 (defun calc-graph-view-commands (&optional no-need)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1293 (interactive "p")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1294 (or calc-graph-no-auto-view (calc-graph-init-buffers))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1295 (calc-graph-view calc-gnuplot-input calc-gnuplot-buffer (null no-need)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1296
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1297 (defun calc-graph-view-trail (&optional no-need)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1298 (interactive "p")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1299 (or calc-graph-no-auto-view (calc-graph-init-buffers))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1300 (calc-graph-view calc-gnuplot-buffer calc-gnuplot-input (null no-need)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1301
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1302 (defun calc-graph-view (buf other-buf need)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1303 (let (win)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1304 (or calc-graph-no-auto-view
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1305 (if (setq win (get-buffer-window buf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1306 (or need
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1307 (and (eq buf calc-gnuplot-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1308 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1309 (set-buffer buf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1310 (not (pos-visible-in-window-p (point-max) win))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1311 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1312 (bury-buffer buf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1313 (bury-buffer other-buf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1314 (let ((curwin (selected-window)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1315 (select-window win)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1316 (switch-to-buffer nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1317 (select-window curwin))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1318 (if (setq win (get-buffer-window other-buf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1319 (set-window-buffer win buf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1320 (if (eq major-mode 'calc-mode)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1321 (if (or need
40998
ee9c2872370b Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents: 40785
diff changeset
1322 (< (window-height) (1- (frame-height))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1323 (display-buffer buf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1324 (switch-to-buffer buf)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1325 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1326 (set-buffer buf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1327 (if (and (eq buf calc-gnuplot-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1328 (setq win (get-buffer-window buf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1329 (not (pos-visible-in-window-p (point-max) win)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1330 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1331 (goto-char (point-max))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1332 (vertical-motion (- 6 (window-height win)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1333 (set-window-start win (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1334 (goto-char (point-max)))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1335 (or calc-graph-no-auto-view (sit-for 0))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1336
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1337 (defun calc-gnuplot-check-for-errors ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1338 (if (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1339 (prog2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1340 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1341 (set-buffer calc-gnuplot-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1342 (goto-char calc-gnuplot-last-error-pos))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1343 (re-search-forward "^[ \t]+\\^$" nil t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1344 (goto-char (point-max))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1345 (setq calc-gnuplot-last-error-pos (point-max))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1346 (calc-graph-view-trail)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1347
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1348 (defun calc-gnuplot-command (&rest args)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1349 (calc-graph-init)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1350 (let ((cmd (concat (mapconcat 'identity args " ") "\n")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1351 (accept-process-output)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1352 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1353 (set-buffer calc-gnuplot-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1354 (calc-gnuplot-check-for-errors)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1355 (goto-char (point-max))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1356 (setq calc-gnuplot-trail-mark (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1357 (or (>= calc-gnuplot-version 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1358 (insert cmd))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1359 (set-marker (process-mark calc-gnuplot-process) (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1360 (process-send-string calc-gnuplot-process cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1361 (if (get-buffer-window calc-gnuplot-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1362 (calc-graph-view-trail))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1363 (accept-process-output (and (not calc-graph-no-wait)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1364 calc-gnuplot-process))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1365 (calc-gnuplot-check-for-errors)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1366 (if (get-buffer-window calc-gnuplot-buffer)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1367 (calc-graph-view-trail)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1368
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1369 (defun calc-graph-init-buffers ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1370 (or (and calc-gnuplot-buffer
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1371 (buffer-name calc-gnuplot-buffer))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1372 (setq calc-gnuplot-buffer (get-buffer-create "*Gnuplot Trail*")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1373 (or (and calc-gnuplot-input
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1374 (buffer-name calc-gnuplot-input))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1375 (setq calc-gnuplot-input (get-buffer-create "*Gnuplot Commands*"))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1376
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1377 (defun calc-graph-init ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1378 (or (calc-gnuplot-alive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1379 (let ((process-connection-type t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1380 origin)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1381 (if calc-gnuplot-process
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1382 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1383 (delete-process calc-gnuplot-process)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1384 (setq calc-gnuplot-process nil)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1385 (calc-graph-init-buffers)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1386 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1387 (set-buffer calc-gnuplot-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1388 (insert "\nStarting gnuplot...\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1389 (setq origin (point)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1390 (setq calc-graph-last-device nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1391 (setq calc-graph-last-output nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1392 (condition-case err
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1393 (let ((args (append (and calc-gnuplot-display
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1394 (not (equal calc-gnuplot-display
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1395 (getenv "DISPLAY")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1396 (list "-display"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1397 calc-gnuplot-display))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1398 (and calc-gnuplot-geometry
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1399 (list "-geometry"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1400 calc-gnuplot-geometry)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1401 (setq calc-gnuplot-process
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1402 (apply 'start-process
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1403 "gnuplot"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1404 calc-gnuplot-buffer
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1405 calc-gnuplot-name
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1406 args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1407 (process-kill-without-query calc-gnuplot-process))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1408 (file-error
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1409 (error "Sorry, can't find \"%s\" on your system"
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1410 calc-gnuplot-name)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1411 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1412 (set-buffer calc-gnuplot-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1413 (while (and (not (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1414 (goto-char origin)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1415 (search-forward "gnuplot> " nil t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1416 (memq (process-status calc-gnuplot-process) '(run stop)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1417 (accept-process-output calc-gnuplot-process))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1418 (or (memq (process-status calc-gnuplot-process) '(run stop))
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1419 (error "Unable to start GNUPLOT process"))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1420 (if (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1421 (goto-char origin)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1422 (re-search-forward
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1423 "G N U P L O T.*\n.*version \\([0-9]+\\)\\." nil t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1424 (setq calc-gnuplot-version (string-to-int (buffer-substring
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1425 (match-beginning 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1426 (match-end 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1427 (setq calc-gnuplot-version 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1428 (goto-char (point-max)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1429 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1430 (set-buffer calc-gnuplot-input)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1431 (if (= (buffer-size) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1432 (insert "# Commands for running gnuplot\n\n\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1433 (or calc-graph-no-auto-view
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1434 (eq (char-after (1- (point-max))) ?\n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1435 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1436 (goto-char (point-max))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1437 (insert "\n"))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1438
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1439 ;;; calc-graph.el ends here