diff options
Diffstat (limited to 'lisp/calc/calc-graph.el')
| -rw-r--r-- | lisp/calc/calc-graph.el | 688 |
1 files changed, 364 insertions, 324 deletions
diff --git a/lisp/calc/calc-graph.el b/lisp/calc/calc-graph.el index cec7a5d2136..ff537109816 100644 --- a/lisp/calc/calc-graph.el +++ b/lisp/calc/calc-graph.el | |||
| @@ -66,6 +66,7 @@ | |||
| 66 | (defvar calc-graph-data-cache-limit 10) | 66 | (defvar calc-graph-data-cache-limit 10) |
| 67 | (defvar calc-graph-no-auto-view nil) | 67 | (defvar calc-graph-no-auto-view nil) |
| 68 | (defvar calc-graph-no-wait nil) | 68 | (defvar calc-graph-no-wait nil) |
| 69 | (defvar calc-gnuplot-trail-mark) | ||
| 69 | 70 | ||
| 70 | (defun calc-graph-fast (many) | 71 | (defun calc-graph-fast (many) |
| 71 | (interactive "P") | 72 | (interactive "P") |
| @@ -224,11 +225,10 @@ | |||
| 224 | thing | 225 | thing |
| 225 | (let ((found (assoc thing calc-graph-var-cache))) | 226 | (let ((found (assoc thing calc-graph-var-cache))) |
| 226 | (or found | 227 | (or found |
| 227 | (progn | 228 | (let ((varname (concat "PlotData" |
| 228 | (setq varname (concat "PlotData" | 229 | (int-to-string |
| 229 | (int-to-string | 230 | (1+ (length calc-graph-var-cache)))))) |
| 230 | (1+ (length calc-graph-var-cache)))) | 231 | (setq var (list 'var (intern varname) |
| 231 | var (list 'var (intern varname) | ||
| 232 | (intern (concat "var-" varname))) | 232 | (intern (concat "var-" varname))) |
| 233 | found (cons thing var) | 233 | found (cons thing var) |
| 234 | calc-graph-var-cache (cons found calc-graph-var-cache)) | 234 | calc-graph-var-cache (cons found calc-graph-var-cache)) |
| @@ -275,6 +275,47 @@ | |||
| 275 | (interactive "P") | 275 | (interactive "P") |
| 276 | (calc-graph-plot flag t)) | 276 | (calc-graph-plot flag t)) |
| 277 | 277 | ||
| 278 | (defvar var-DUMMY) | ||
| 279 | (defvar var-DUMMY2) | ||
| 280 | (defvar var-PlotRejects) | ||
| 281 | |||
| 282 | ;; The following variables are local to calc-graph-plot, but are | ||
| 283 | ;; used in the functions calc-graph-compute-2d, calc-graph-refine-2d, | ||
| 284 | ;; calc-graph-recompute-2d, calc-graph-compute-3d and | ||
| 285 | ;; calc-graph-format-data, which are called by calc-graph-plot. | ||
| 286 | (defvar calc-graph-yvalue) | ||
| 287 | (defvar calc-graph-yvec) | ||
| 288 | (defvar calc-graph-numsteps) | ||
| 289 | (defvar calc-graph-numsteps3) | ||
| 290 | (defvar calc-graph-xvalue) | ||
| 291 | (defvar calc-graph-xvec) | ||
| 292 | (defvar calc-graph-xname) | ||
| 293 | (defvar calc-graph-yname) | ||
| 294 | (defvar calc-graph-xstep) | ||
| 295 | (defvar calc-graph-ycache) | ||
| 296 | (defvar calc-graph-ycacheptr) | ||
| 297 | (defvar calc-graph-refine) | ||
| 298 | (defvar calc-graph-keep-file) | ||
| 299 | (defvar calc-graph-xval) | ||
| 300 | (defvar calc-graph-xlow) | ||
| 301 | (defvar calc-graph-xhigh) | ||
| 302 | (defvar calc-graph-yval) | ||
| 303 | (defvar calc-graph-yp) | ||
| 304 | (defvar calc-graph-xp) | ||
| 305 | (defvar calc-graph-zp) | ||
| 306 | (defvar calc-graph-yvector) | ||
| 307 | (defvar calc-graph-resolution) | ||
| 308 | (defvar calc-graph-y3value) | ||
| 309 | (defvar calc-graph-y3name) | ||
| 310 | (defvar calc-graph-y3step) | ||
| 311 | (defvar calc-graph-zval) | ||
| 312 | (defvar calc-graph-stepcount) | ||
| 313 | (defvar calc-graph-is-splot) | ||
| 314 | (defvar calc-graph-surprise-splot) | ||
| 315 | (defvar calc-graph-blank) | ||
| 316 | (defvar calc-graph-non-blank) | ||
| 317 | (defvar calc-graph-curve-num) | ||
| 318 | |||
| 278 | (defun calc-graph-plot (flag &optional printing) | 319 | (defun calc-graph-plot (flag &optional printing) |
| 279 | (interactive "P") | 320 | (interactive "P") |
| 280 | (calc-slow-wrapper | 321 | (calc-slow-wrapper |
| @@ -282,22 +323,20 @@ | |||
| 282 | (tempbuf (get-buffer-create "*Gnuplot Temp-2*")) | 323 | (tempbuf (get-buffer-create "*Gnuplot Temp-2*")) |
| 283 | (tempbuftop 1) | 324 | (tempbuftop 1) |
| 284 | (tempoutfile nil) | 325 | (tempoutfile nil) |
| 285 | (curve-num 0) | 326 | (calc-graph-curve-num 0) |
| 286 | (refine (and flag (> (prefix-numeric-value flag) 0))) | 327 | (calc-graph-refine (and flag (> (prefix-numeric-value flag) 0))) |
| 287 | (recompute (and flag (< (prefix-numeric-value flag) 0))) | 328 | (recompute (and flag (< (prefix-numeric-value flag) 0))) |
| 288 | (surprise-splot nil) | 329 | (calc-graph-surprise-splot nil) |
| 289 | (tty-output nil) | 330 | (tty-output nil) |
| 290 | cache-env is-splot device output resolution precision samples-pos) | 331 | cache-env calc-graph-is-splot device output calc-graph-resolution precision samples-pos) |
| 291 | (or (boundp 'calc-graph-prev-kill-hook) | 332 | (add-hook 'kill-emacs-hook 'calc-graph-kill-hook) |
| 292 | (setq calc-graph-prev-kill-hook nil) | ||
| 293 | (add-hook 'kill-emacs-hook 'calc-graph-kill-hook)) | ||
| 294 | (save-excursion | 333 | (save-excursion |
| 295 | (calc-graph-init) | 334 | (calc-graph-init) |
| 296 | (set-buffer tempbuf) | 335 | (set-buffer tempbuf) |
| 297 | (erase-buffer) | 336 | (erase-buffer) |
| 298 | (set-buffer calc-gnuplot-input) | 337 | (set-buffer calc-gnuplot-input) |
| 299 | (goto-char (point-min)) | 338 | (goto-char (point-min)) |
| 300 | (setq is-splot (re-search-forward "^splot[ \t]" nil t)) | 339 | (setq calc-graph-is-splot (re-search-forward "^splot[ \t]" nil t)) |
| 301 | (let ((str (buffer-string)) | 340 | (let ((str (buffer-string)) |
| 302 | (ver calc-gnuplot-version)) | 341 | (ver calc-gnuplot-version)) |
| 303 | (set-buffer (get-buffer-create "*Gnuplot Temp*")) | 342 | (set-buffer (get-buffer-create "*Gnuplot Temp*")) |
| @@ -313,14 +352,14 @@ | |||
| 313 | "set nogrid\nset nokey\nset nopolar\n")) | 352 | "set nogrid\nset nokey\nset nopolar\n")) |
| 314 | (if (>= ver 3) | 353 | (if (>= ver 3) |
| 315 | (insert "set surface\nset nocontour\n" | 354 | (insert "set surface\nset nocontour\n" |
| 316 | "set " (if is-splot "" "no") "parametric\n" | 355 | "set " (if calc-graph-is-splot "" "no") "parametric\n" |
| 317 | "set notime\nset border\nset ztics\nset zeroaxis\n" | 356 | "set notime\nset border\nset ztics\nset zeroaxis\n" |
| 318 | "set view 60,30,1,1\nset offsets 0,0,0,0\n")) | 357 | "set view 60,30,1,1\nset offsets 0,0,0,0\n")) |
| 319 | (setq samples-pos (point)) | 358 | (setq samples-pos (point)) |
| 320 | (insert "\n\n" str)) | 359 | (insert "\n\n" str)) |
| 321 | (goto-char (point-min)) | 360 | (goto-char (point-min)) |
| 322 | (if is-splot | 361 | (if calc-graph-is-splot |
| 323 | (if refine | 362 | (if calc-graph-refine |
| 324 | (error "This option works only for 2d plots") | 363 | (error "This option works only for 2d plots") |
| 325 | (setq recompute t))) | 364 | (setq recompute t))) |
| 326 | (let ((calc-gnuplot-input (current-buffer)) | 365 | (let ((calc-gnuplot-input (current-buffer)) |
| @@ -366,10 +405,10 @@ | |||
| 366 | (if (equal output "STDOUT") | 405 | (if (equal output "STDOUT") |
| 367 | "" | 406 | "" |
| 368 | (prin1-to-string output))))) | 407 | (prin1-to-string output))))) |
| 369 | (setq resolution (calc-graph-find-command "samples")) | 408 | (setq calc-graph-resolution (calc-graph-find-command "samples")) |
| 370 | (if resolution | 409 | (if calc-graph-resolution |
| 371 | (setq resolution (string-to-int resolution)) | 410 | (setq calc-graph-resolution (string-to-int calc-graph-resolution)) |
| 372 | (setq resolution (if is-splot | 411 | (setq calc-graph-resolution (if calc-graph-is-splot |
| 373 | calc-graph-default-resolution-3d | 412 | calc-graph-default-resolution-3d |
| 374 | calc-graph-default-resolution))) | 413 | calc-graph-default-resolution))) |
| 375 | (setq precision (calc-graph-find-command "precision")) | 414 | (setq precision (calc-graph-find-command "precision")) |
| @@ -381,8 +420,8 @@ | |||
| 381 | (calc-graph-set-command "samples") | 420 | (calc-graph-set-command "samples") |
| 382 | (calc-graph-set-command "precision")) | 421 | (calc-graph-set-command "precision")) |
| 383 | (goto-char samples-pos) | 422 | (goto-char samples-pos) |
| 384 | (insert "set samples " (int-to-string (max (if is-splot 20 200) | 423 | (insert "set samples " (int-to-string (max (if calc-graph-is-splot 20 200) |
| 385 | (+ 5 resolution))) "\n") | 424 | (+ 5 calc-graph-resolution))) "\n") |
| 386 | (while (re-search-forward "{\\*[^}]+}[^,\n]*" nil t) | 425 | (while (re-search-forward "{\\*[^}]+}[^,\n]*" nil t) |
| 387 | (delete-region (match-beginning 0) (match-end 0)) | 426 | (delete-region (match-beginning 0) (match-end 0)) |
| 388 | (if (looking-at ",") | 427 | (if (looking-at ",") |
| @@ -398,7 +437,7 @@ | |||
| 398 | calc-simplify-mode | 437 | calc-simplify-mode |
| 399 | calc-infinite-mode | 438 | calc-infinite-mode |
| 400 | calc-word-size | 439 | calc-word-size |
| 401 | precision is-splot)) | 440 | precision calc-graph-is-splot)) |
| 402 | (if (and (not recompute) | 441 | (if (and (not recompute) |
| 403 | (equal (cdr (car calc-graph-data-cache)) cache-env)) | 442 | (equal (cdr (car calc-graph-data-cache)) cache-env)) |
| 404 | (while (> (length calc-graph-data-cache) | 443 | (while (> (length calc-graph-data-cache) |
| @@ -408,88 +447,88 @@ | |||
| 408 | (setq calc-graph-data-cache (list (cons nil cache-env))))) | 447 | (setq calc-graph-data-cache (list (cons nil cache-env))))) |
| 409 | (calc-graph-find-plot t t) | 448 | (calc-graph-find-plot t t) |
| 410 | (while (re-search-forward | 449 | (while (re-search-forward |
| 411 | (if is-splot | 450 | (if calc-graph-is-splot |
| 412 | "{\\([^{}:\n]+\\):\\([^{}:\n]+\\):\\([^{}:\n]+\\)}" | 451 | "{\\([^{}:\n]+\\):\\([^{}:\n]+\\):\\([^{}:\n]+\\)}" |
| 413 | "{\\([^{}:\n]+\\)\\(:\\)\\([^{}:\n]+\\)}") | 452 | "{\\([^{}:\n]+\\)\\(:\\)\\([^{}:\n]+\\)}") |
| 414 | nil t) | 453 | nil t) |
| 415 | (setq curve-num (1+ curve-num)) | 454 | (setq calc-graph-curve-num (1+ calc-graph-curve-num)) |
| 416 | (let* ((xname (buffer-substring (match-beginning 1) (match-end 1))) | 455 | (let* ((calc-graph-xname (buffer-substring (match-beginning 1) (match-end 1))) |
| 417 | (xvar (intern (concat "var-" xname))) | 456 | (xvar (intern (concat "var-" calc-graph-xname))) |
| 418 | (xvalue (math-evaluate-expr (calc-var-value xvar))) | 457 | (calc-graph-xvalue (math-evaluate-expr (calc-var-value xvar))) |
| 419 | (y3name (and is-splot | 458 | (calc-graph-y3name (and calc-graph-is-splot |
| 420 | (buffer-substring (match-beginning 2) | 459 | (buffer-substring (match-beginning 2) |
| 421 | (match-end 2)))) | 460 | (match-end 2)))) |
| 422 | (y3var (and is-splot (intern (concat "var-" y3name)))) | 461 | (y3var (and calc-graph-is-splot (intern (concat "var-" calc-graph-y3name)))) |
| 423 | (y3value (and is-splot (calc-var-value y3var))) | 462 | (calc-graph-y3value (and calc-graph-is-splot (calc-var-value y3var))) |
| 424 | (yname (buffer-substring (match-beginning 3) (match-end 3))) | 463 | (calc-graph-yname (buffer-substring (match-beginning 3) (match-end 3))) |
| 425 | (yvar (intern (concat "var-" yname))) | 464 | (yvar (intern (concat "var-" calc-graph-yname))) |
| 426 | (yvalue (calc-var-value yvar)) | 465 | (calc-graph-yvalue (calc-var-value yvar)) |
| 427 | filename) | 466 | filename) |
| 428 | (delete-region (match-beginning 0) (match-end 0)) | 467 | (delete-region (match-beginning 0) (match-end 0)) |
| 429 | (setq filename (calc-temp-file-name curve-num)) | 468 | (setq filename (calc-temp-file-name calc-graph-curve-num)) |
| 430 | (save-excursion | 469 | (save-excursion |
| 431 | (set-buffer calcbuf) | 470 | (set-buffer calcbuf) |
| 432 | (let (tempbuftop | 471 | (let (tempbuftop |
| 433 | (xp xvalue) | 472 | (calc-graph-xp calc-graph-xvalue) |
| 434 | (yp yvalue) | 473 | (calc-graph-yp calc-graph-yvalue) |
| 435 | (zp nil) | 474 | (calc-graph-zp nil) |
| 436 | (xlow nil) (xhigh nil) (y3low nil) (y3high nil) | 475 | (calc-graph-xlow nil) (calc-graph-xhigh nil) (y3low nil) (y3high nil) |
| 437 | xvec xval xstep var-DUMMY | 476 | calc-graph-xvec calc-graph-xval calc-graph-xstep var-DUMMY |
| 438 | y3vec y3val y3step var-DUMMY2 (zval nil) | 477 | y3val calc-graph-y3step var-DUMMY2 (calc-graph-zval nil) |
| 439 | yvec yval ycache ycacheptr yvector | 478 | calc-graph-yvec calc-graph-yval calc-graph-ycache calc-graph-ycacheptr calc-graph-yvector |
| 440 | numsteps numsteps3 | 479 | calc-graph-numsteps calc-graph-numsteps3 |
| 441 | (keep-file (and (not is-splot) (file-exists-p filename))) | 480 | (calc-graph-keep-file (and (not calc-graph-is-splot) (file-exists-p filename))) |
| 442 | (stepcount 0) | 481 | (calc-graph-stepcount 0) |
| 443 | (calc-symbolic-mode nil) | 482 | (calc-symbolic-mode nil) |
| 444 | (calc-prefer-frac nil) | 483 | (calc-prefer-frac nil) |
| 445 | (calc-internal-prec (max 3 precision)) | 484 | (calc-internal-prec (max 3 precision)) |
| 446 | (calc-simplify-mode (and (not (memq calc-simplify-mode | 485 | (calc-simplify-mode (and (not (memq calc-simplify-mode |
| 447 | '(none num))) | 486 | '(none num))) |
| 448 | calc-simplify-mode)) | 487 | calc-simplify-mode)) |
| 449 | (blank t) | 488 | (calc-graph-blank t) |
| 450 | (non-blank nil) | 489 | (calc-graph-non-blank nil) |
| 451 | (math-working-step 0) | 490 | (math-working-step 0) |
| 452 | (math-working-step-2 nil)) | 491 | (math-working-step-2 nil)) |
| 453 | (save-excursion | 492 | (save-excursion |
| 454 | (if is-splot | 493 | (if calc-graph-is-splot |
| 455 | (calc-graph-compute-3d) | 494 | (calc-graph-compute-3d) |
| 456 | (calc-graph-compute-2d)) | 495 | (calc-graph-compute-2d)) |
| 457 | (set-buffer tempbuf) | 496 | (set-buffer tempbuf) |
| 458 | (goto-char (point-max)) | 497 | (goto-char (point-max)) |
| 459 | (insert "\n" xname) | 498 | (insert "\n" calc-graph-xname) |
| 460 | (if is-splot | 499 | (if calc-graph-is-splot |
| 461 | (insert ":" y3name)) | 500 | (insert ":" calc-graph-y3name)) |
| 462 | (insert ":" yname "\n\n") | 501 | (insert ":" calc-graph-yname "\n\n") |
| 463 | (setq tempbuftop (point)) | 502 | (setq tempbuftop (point)) |
| 464 | (let ((calc-group-digits nil) | 503 | (let ((calc-group-digits nil) |
| 465 | (calc-leading-zeros nil) | 504 | (calc-leading-zeros nil) |
| 466 | (calc-number-radix 10) | 505 | (calc-number-radix 10) |
| 467 | (entry (and (not is-splot) | 506 | (entry (and (not calc-graph-is-splot) |
| 468 | (list xp yp xhigh numsteps)))) | 507 | (list calc-graph-xp calc-graph-yp calc-graph-xhigh calc-graph-numsteps)))) |
| 469 | (or (equal entry | 508 | (or (equal entry |
| 470 | (nth 1 (nth (1+ curve-num) | 509 | (nth 1 (nth (1+ calc-graph-curve-num) |
| 471 | calc-graph-file-cache))) | 510 | calc-graph-file-cache))) |
| 472 | (setq keep-file nil)) | 511 | (setq calc-graph-keep-file nil)) |
| 473 | (setcar (cdr (nth (1+ curve-num) calc-graph-file-cache)) | 512 | (setcar (cdr (nth (1+ calc-graph-curve-num) calc-graph-file-cache)) |
| 474 | entry) | 513 | entry) |
| 475 | (or keep-file | 514 | (or calc-graph-keep-file |
| 476 | (calc-graph-format-data))) | 515 | (calc-graph-format-data))) |
| 477 | (or keep-file | 516 | (or calc-graph-keep-file |
| 478 | (progn | 517 | (progn |
| 479 | (or non-blank | 518 | (or calc-graph-non-blank |
| 480 | (error "No valid data points for %s:%s" | 519 | (error "No valid data points for %s:%s" |
| 481 | xname yname)) | 520 | calc-graph-xname calc-graph-yname)) |
| 482 | (write-region tempbuftop (point-max) filename | 521 | (write-region tempbuftop (point-max) filename |
| 483 | nil 'quiet)))))) | 522 | nil 'quiet)))))) |
| 484 | (insert (prin1-to-string filename)))) | 523 | (insert (prin1-to-string filename)))) |
| 485 | (if surprise-splot | 524 | (if calc-graph-surprise-splot |
| 486 | (setcdr cache-env nil)) | 525 | (setcdr cache-env nil)) |
| 487 | (if (= curve-num 0) | 526 | (if (= calc-graph-curve-num 0) |
| 488 | (progn | 527 | (progn |
| 489 | (calc-gnuplot-command "clear") | 528 | (calc-gnuplot-command "clear") |
| 490 | (calc-clear-command-flag 'clear-message) | 529 | (calc-clear-command-flag 'clear-message) |
| 491 | (message "No data to plot!")) | 530 | (message "No data to plot!")) |
| 492 | (setq calc-graph-data-cache-limit (max curve-num | 531 | (setq calc-graph-data-cache-limit (max calc-graph-curve-num |
| 493 | calc-graph-data-cache-limit) | 532 | calc-graph-data-cache-limit) |
| 494 | filename (calc-temp-file-name 0)) | 533 | filename (calc-temp-file-name 0)) |
| 495 | (write-region (point-min) (point-max) filename nil 'quiet) | 534 | (write-region (point-min) (point-max) filename nil 'quiet) |
| @@ -517,325 +556,325 @@ | |||
| 517 | (eval command)))))))))) | 556 | (eval command)))))))))) |
| 518 | 557 | ||
| 519 | (defun calc-graph-compute-2d () | 558 | (defun calc-graph-compute-2d () |
| 520 | (if (setq yvec (eq (car-safe yvalue) 'vec)) | 559 | (if (setq calc-graph-yvec (eq (car-safe calc-graph-yvalue) 'vec)) |
| 521 | (if (= (setq numsteps (1- (length yvalue))) 0) | 560 | (if (= (setq calc-graph-numsteps (1- (length calc-graph-yvalue))) 0) |
| 522 | (error "Can't plot an empty vector") | 561 | (error "Can't plot an empty vector") |
| 523 | (if (setq xvec (eq (car-safe xvalue) 'vec)) | 562 | (if (setq calc-graph-xvec (eq (car-safe calc-graph-xvalue) 'vec)) |
| 524 | (or (= (1- (length xvalue)) numsteps) | 563 | (or (= (1- (length calc-graph-xvalue)) calc-graph-numsteps) |
| 525 | (error "%s and %s have different lengths" xname yname)) | 564 | (error "%s and %s have different lengths" calc-graph-xname calc-graph-yname)) |
| 526 | (if (and (eq (car-safe xvalue) 'intv) | 565 | (if (and (eq (car-safe calc-graph-xvalue) 'intv) |
| 527 | (math-constp xvalue)) | 566 | (math-constp calc-graph-xvalue)) |
| 528 | (setq xstep (math-div (math-sub (nth 3 xvalue) | 567 | (setq calc-graph-xstep (math-div (math-sub (nth 3 calc-graph-xvalue) |
| 529 | (nth 2 xvalue)) | 568 | (nth 2 calc-graph-xvalue)) |
| 530 | (1- numsteps)) | 569 | (1- calc-graph-numsteps)) |
| 531 | xvalue (nth 2 xvalue)) | 570 | calc-graph-xvalue (nth 2 calc-graph-xvalue)) |
| 532 | (if (math-realp xvalue) | 571 | (if (math-realp calc-graph-xvalue) |
| 533 | (setq xstep 1) | 572 | (setq calc-graph-xstep 1) |
| 534 | (error "%s is not a suitable basis for %s" xname yname))))) | 573 | (error "%s is not a suitable basis for %s" calc-graph-xname calc-graph-yname))))) |
| 535 | (or (math-realp yvalue) | 574 | (or (math-realp calc-graph-yvalue) |
| 536 | (let ((arglist nil)) | 575 | (let ((arglist nil)) |
| 537 | (setq yvalue (math-evaluate-expr yvalue)) | 576 | (setq calc-graph-yvalue (math-evaluate-expr calc-graph-yvalue)) |
| 538 | (calc-default-formula-arglist yvalue) | 577 | (calc-default-formula-arglist calc-graph-yvalue) |
| 539 | (or arglist | 578 | (or arglist |
| 540 | (error "%s does not contain any unassigned variables" yname)) | 579 | (error "%s does not contain any unassigned variables" calc-graph-yname)) |
| 541 | (and (cdr arglist) | 580 | (and (cdr arglist) |
| 542 | (error "%s contains more than one variable: %s" | 581 | (error "%s contains more than one variable: %s" |
| 543 | yname arglist)) | 582 | calc-graph-yname arglist)) |
| 544 | (setq yvalue (math-expr-subst yvalue | 583 | (setq calc-graph-yvalue (math-expr-subst calc-graph-yvalue |
| 545 | (math-build-var-name (car arglist)) | 584 | (math-build-var-name (car arglist)) |
| 546 | '(var DUMMY var-DUMMY))))) | 585 | '(var DUMMY var-DUMMY))))) |
| 547 | (setq ycache (assoc yvalue calc-graph-data-cache)) | 586 | (setq calc-graph-ycache (assoc calc-graph-yvalue calc-graph-data-cache)) |
| 548 | (delq ycache calc-graph-data-cache) | 587 | (delq calc-graph-ycache calc-graph-data-cache) |
| 549 | (nconc calc-graph-data-cache | 588 | (nconc calc-graph-data-cache |
| 550 | (list (or ycache (setq ycache (list yvalue))))) | 589 | (list (or calc-graph-ycache (setq calc-graph-ycache (list calc-graph-yvalue))))) |
| 551 | (if (and (not (setq xvec (eq (car-safe xvalue) 'vec))) | 590 | (if (and (not (setq calc-graph-xvec (eq (car-safe calc-graph-xvalue) 'vec))) |
| 552 | refine (cdr (cdr ycache))) | 591 | calc-graph-refine (cdr (cdr calc-graph-ycache))) |
| 553 | (calc-graph-refine-2d) | 592 | (calc-graph-refine-2d) |
| 554 | (calc-graph-recompute-2d)))) | 593 | (calc-graph-recompute-2d)))) |
| 555 | 594 | ||
| 556 | (defun calc-graph-refine-2d () | 595 | (defun calc-graph-refine-2d () |
| 557 | (setq keep-file nil | 596 | (setq calc-graph-keep-file nil |
| 558 | ycacheptr (cdr ycache)) | 597 | calc-graph-ycacheptr (cdr calc-graph-ycache)) |
| 559 | (if (and (setq xval (calc-graph-find-command "xrange")) | 598 | (if (and (setq calc-graph-xval (calc-graph-find-command "xrange")) |
| 560 | (string-match "\\`\\[\\([0-9.eE+-]*\\):\\([0-9.eE+-]*\\)\\]\\'" | 599 | (string-match "\\`\\[\\([0-9.eE+-]*\\):\\([0-9.eE+-]*\\)\\]\\'" |
| 561 | xval)) | 600 | calc-graph-xval)) |
| 562 | (let ((b2 (match-beginning 2)) | 601 | (let ((b2 (match-beginning 2)) |
| 563 | (e2 (match-end 2))) | 602 | (e2 (match-end 2))) |
| 564 | (setq xlow (math-read-number (substring xval | 603 | (setq calc-graph-xlow (math-read-number (substring calc-graph-xval |
| 565 | (match-beginning 1) | 604 | (match-beginning 1) |
| 566 | (match-end 1))) | 605 | (match-end 1))) |
| 567 | xhigh (math-read-number (substring xval b2 e2)))) | 606 | calc-graph-xhigh (math-read-number (substring calc-graph-xval b2 e2)))) |
| 568 | (if xlow | 607 | (if calc-graph-xlow |
| 569 | (while (and (cdr ycacheptr) | 608 | (while (and (cdr calc-graph-ycacheptr) |
| 570 | (Math-lessp (car (nth 1 ycacheptr)) xlow)) | 609 | (Math-lessp (car (nth 1 calc-graph-ycacheptr)) calc-graph-xlow)) |
| 571 | (setq ycacheptr (cdr ycacheptr))))) | 610 | (setq calc-graph-ycacheptr (cdr calc-graph-ycacheptr))))) |
| 572 | (setq math-working-step-2 (1- (length ycacheptr))) | 611 | (setq math-working-step-2 (1- (length calc-graph-ycacheptr))) |
| 573 | (while (and (cdr ycacheptr) | 612 | (while (and (cdr calc-graph-ycacheptr) |
| 574 | (or (not xhigh) | 613 | (or (not calc-graph-xhigh) |
| 575 | (Math-lessp (car (car ycacheptr)) xhigh))) | 614 | (Math-lessp (car (car calc-graph-ycacheptr)) calc-graph-xhigh))) |
| 576 | (setq var-DUMMY (math-div (math-add (car (car ycacheptr)) | 615 | (setq var-DUMMY (math-div (math-add (car (car calc-graph-ycacheptr)) |
| 577 | (car (nth 1 ycacheptr))) | 616 | (car (nth 1 calc-graph-ycacheptr))) |
| 578 | 2) | 617 | 2) |
| 579 | math-working-step (1+ math-working-step) | 618 | math-working-step (1+ math-working-step) |
| 580 | yval (math-evaluate-expr yvalue)) | 619 | calc-graph-yval (math-evaluate-expr calc-graph-yvalue)) |
| 581 | (setcdr ycacheptr (cons (cons var-DUMMY yval) | 620 | (setcdr calc-graph-ycacheptr (cons (cons var-DUMMY calc-graph-yval) |
| 582 | (cdr ycacheptr))) | 621 | (cdr calc-graph-ycacheptr))) |
| 583 | (setq ycacheptr (cdr (cdr ycacheptr)))) | 622 | (setq calc-graph-ycacheptr (cdr (cdr calc-graph-ycacheptr)))) |
| 584 | (setq yp ycache | 623 | (setq calc-graph-yp calc-graph-ycache |
| 585 | numsteps 1000000)) | 624 | calc-graph-numsteps 1000000)) |
| 586 | 625 | ||
| 587 | (defun calc-graph-recompute-2d () | 626 | (defun calc-graph-recompute-2d () |
| 588 | (setq ycacheptr ycache) | 627 | (setq calc-graph-ycacheptr calc-graph-ycache) |
| 589 | (if xvec | 628 | (if calc-graph-xvec |
| 590 | (setq numsteps (1- (length xvalue)) | 629 | (setq calc-graph-numsteps (1- (length calc-graph-xvalue)) |
| 591 | yvector nil) | 630 | calc-graph-yvector nil) |
| 592 | (if (and (eq (car-safe xvalue) 'intv) | 631 | (if (and (eq (car-safe calc-graph-xvalue) 'intv) |
| 593 | (math-constp xvalue)) | 632 | (math-constp calc-graph-xvalue)) |
| 594 | (setq numsteps resolution | 633 | (setq calc-graph-numsteps calc-graph-resolution |
| 595 | yp nil | 634 | calc-graph-yp nil |
| 596 | xlow (nth 2 xvalue) | 635 | calc-graph-xlow (nth 2 calc-graph-xvalue) |
| 597 | xhigh (nth 3 xvalue) | 636 | calc-graph-xhigh (nth 3 calc-graph-xvalue) |
| 598 | xstep (math-div (math-sub xhigh xlow) | 637 | calc-graph-xstep (math-div (math-sub calc-graph-xhigh calc-graph-xlow) |
| 599 | (1- numsteps)) | 638 | (1- calc-graph-numsteps)) |
| 600 | xvalue (nth 2 xvalue)) | 639 | calc-graph-xvalue (nth 2 calc-graph-xvalue)) |
| 601 | (error "%s is not a suitable basis for %s" | 640 | (error "%s is not a suitable basis for %s" |
| 602 | xname yname))) | 641 | calc-graph-xname calc-graph-yname))) |
| 603 | (setq math-working-step-2 numsteps) | 642 | (setq math-working-step-2 calc-graph-numsteps) |
| 604 | (while (>= (setq numsteps (1- numsteps)) 0) | 643 | (while (>= (setq calc-graph-numsteps (1- calc-graph-numsteps)) 0) |
| 605 | (setq math-working-step (1+ math-working-step)) | 644 | (setq math-working-step (1+ math-working-step)) |
| 606 | (if xvec | 645 | (if calc-graph-xvec |
| 607 | (progn | 646 | (progn |
| 608 | (setq xp (cdr xp) | 647 | (setq calc-graph-xp (cdr calc-graph-xp) |
| 609 | xval (car xp)) | 648 | calc-graph-xval (car calc-graph-xp)) |
| 610 | (and (not (eq ycacheptr ycache)) | 649 | (and (not (eq calc-graph-ycacheptr calc-graph-ycache)) |
| 611 | (consp (car ycacheptr)) | 650 | (consp (car calc-graph-ycacheptr)) |
| 612 | (not (Math-lessp (car (car ycacheptr)) xval)) | 651 | (not (Math-lessp (car (car calc-graph-ycacheptr)) calc-graph-xval)) |
| 613 | (setq ycacheptr ycache))) | 652 | (setq calc-graph-ycacheptr calc-graph-ycache))) |
| 614 | (if (= numsteps 0) | 653 | (if (= calc-graph-numsteps 0) |
| 615 | (setq xval xhigh) ; avoid cumulative roundoff | 654 | (setq calc-graph-xval calc-graph-xhigh) ; avoid cumulative roundoff |
| 616 | (setq xval xvalue | 655 | (setq calc-graph-xval calc-graph-xvalue |
| 617 | xvalue (math-add xvalue xstep)))) | 656 | calc-graph-xvalue (math-add calc-graph-xvalue calc-graph-xstep)))) |
| 618 | (while (and (cdr ycacheptr) | 657 | (while (and (cdr calc-graph-ycacheptr) |
| 619 | (Math-lessp (car (nth 1 ycacheptr)) xval)) | 658 | (Math-lessp (car (nth 1 calc-graph-ycacheptr)) calc-graph-xval)) |
| 620 | (setq ycacheptr (cdr ycacheptr))) | 659 | (setq calc-graph-ycacheptr (cdr calc-graph-ycacheptr))) |
| 621 | (or (and (cdr ycacheptr) | 660 | (or (and (cdr calc-graph-ycacheptr) |
| 622 | (Math-equal (car (nth 1 ycacheptr)) xval)) | 661 | (Math-equal (car (nth 1 calc-graph-ycacheptr)) calc-graph-xval)) |
| 623 | (progn | 662 | (progn |
| 624 | (setq keep-file nil | 663 | (setq calc-graph-keep-file nil |
| 625 | var-DUMMY xval) | 664 | var-DUMMY calc-graph-xval) |
| 626 | (setcdr ycacheptr (cons (cons xval (math-evaluate-expr yvalue)) | 665 | (setcdr calc-graph-ycacheptr (cons (cons calc-graph-xval (math-evaluate-expr calc-graph-yvalue)) |
| 627 | (cdr ycacheptr))))) | 666 | (cdr calc-graph-ycacheptr))))) |
| 628 | (setq ycacheptr (cdr ycacheptr)) | 667 | (setq calc-graph-ycacheptr (cdr calc-graph-ycacheptr)) |
| 629 | (if xvec | 668 | (if calc-graph-xvec |
| 630 | (setq yvector (cons (cdr (car ycacheptr)) yvector)) | 669 | (setq calc-graph-yvector (cons (cdr (car calc-graph-ycacheptr)) calc-graph-yvector)) |
| 631 | (or yp (setq yp ycacheptr)))) | 670 | (or calc-graph-yp (setq calc-graph-yp calc-graph-ycacheptr)))) |
| 632 | (if xvec | 671 | (if calc-graph-xvec |
| 633 | (setq xp xvalue | 672 | (setq calc-graph-xp calc-graph-xvalue |
| 634 | yvec t | 673 | calc-graph-yvec t |
| 635 | yp (cons 'vec (nreverse yvector)) | 674 | calc-graph-yp (cons 'vec (nreverse calc-graph-yvector)) |
| 636 | numsteps (1- (length xp))) | 675 | calc-graph-numsteps (1- (length calc-graph-xp))) |
| 637 | (setq numsteps 1000000))) | 676 | (setq calc-graph-numsteps 1000000))) |
| 638 | 677 | ||
| 639 | (defun calc-graph-compute-3d () | 678 | (defun calc-graph-compute-3d () |
| 640 | (if (setq yvec (eq (car-safe yvalue) 'vec)) | 679 | (if (setq calc-graph-yvec (eq (car-safe calc-graph-yvalue) 'vec)) |
| 641 | (if (math-matrixp yvalue) | 680 | (if (math-matrixp calc-graph-yvalue) |
| 642 | (progn | 681 | (progn |
| 643 | (setq numsteps (1- (length yvalue)) | 682 | (setq calc-graph-numsteps (1- (length calc-graph-yvalue)) |
| 644 | numsteps3 (1- (length (nth 1 yvalue)))) | 683 | calc-graph-numsteps3 (1- (length (nth 1 calc-graph-yvalue)))) |
| 645 | (if (eq (car-safe xvalue) 'vec) | 684 | (if (eq (car-safe calc-graph-xvalue) 'vec) |
| 646 | (or (= (1- (length xvalue)) numsteps) | 685 | (or (= (1- (length calc-graph-xvalue)) calc-graph-numsteps) |
| 647 | (error "%s has wrong length" xname)) | 686 | (error "%s has wrong length" calc-graph-xname)) |
| 648 | (if (and (eq (car-safe xvalue) 'intv) | 687 | (if (and (eq (car-safe calc-graph-xvalue) 'intv) |
| 649 | (math-constp xvalue)) | 688 | (math-constp calc-graph-xvalue)) |
| 650 | (setq xvalue (calcFunc-index numsteps | 689 | (setq calc-graph-xvalue (calcFunc-index calc-graph-numsteps |
| 651 | (nth 2 xvalue) | 690 | (nth 2 calc-graph-xvalue) |
| 652 | (math-div | 691 | (math-div |
| 653 | (math-sub (nth 3 xvalue) | 692 | (math-sub (nth 3 calc-graph-xvalue) |
| 654 | (nth 2 xvalue)) | 693 | (nth 2 calc-graph-xvalue)) |
| 655 | (1- numsteps)))) | 694 | (1- calc-graph-numsteps)))) |
| 656 | (if (math-realp xvalue) | 695 | (if (math-realp calc-graph-xvalue) |
| 657 | (setq xvalue (calcFunc-index numsteps xvalue 1)) | 696 | (setq calc-graph-xvalue (calcFunc-index calc-graph-numsteps calc-graph-xvalue 1)) |
| 658 | (error "%s is not a suitable basis for %s" xname yname)))) | 697 | (error "%s is not a suitable basis for %s" calc-graph-xname calc-graph-yname)))) |
| 659 | (if (eq (car-safe y3value) 'vec) | 698 | (if (eq (car-safe calc-graph-y3value) 'vec) |
| 660 | (or (= (1- (length y3value)) numsteps3) | 699 | (or (= (1- (length calc-graph-y3value)) calc-graph-numsteps3) |
| 661 | (error "%s has wrong length" y3name)) | 700 | (error "%s has wrong length" calc-graph-y3name)) |
| 662 | (if (and (eq (car-safe y3value) 'intv) | 701 | (if (and (eq (car-safe calc-graph-y3value) 'intv) |
| 663 | (math-constp y3value)) | 702 | (math-constp calc-graph-y3value)) |
| 664 | (setq y3value (calcFunc-index numsteps3 | 703 | (setq calc-graph-y3value (calcFunc-index calc-graph-numsteps3 |
| 665 | (nth 2 y3value) | 704 | (nth 2 calc-graph-y3value) |
| 666 | (math-div | 705 | (math-div |
| 667 | (math-sub (nth 3 y3value) | 706 | (math-sub (nth 3 calc-graph-y3value) |
| 668 | (nth 2 y3value)) | 707 | (nth 2 calc-graph-y3value)) |
| 669 | (1- numsteps3)))) | 708 | (1- calc-graph-numsteps3)))) |
| 670 | (if (math-realp y3value) | 709 | (if (math-realp calc-graph-y3value) |
| 671 | (setq y3value (calcFunc-index numsteps3 y3value 1)) | 710 | (setq calc-graph-y3value (calcFunc-index calc-graph-numsteps3 calc-graph-y3value 1)) |
| 672 | (error "%s is not a suitable basis for %s" y3name yname)))) | 711 | (error "%s is not a suitable basis for %s" calc-graph-y3name calc-graph-yname)))) |
| 673 | (setq xp nil | 712 | (setq calc-graph-xp nil |
| 674 | yp nil | 713 | calc-graph-yp nil |
| 675 | zp nil | 714 | calc-graph-zp nil |
| 676 | xvec t) | 715 | calc-graph-xvec t) |
| 677 | (while (setq xvalue (cdr xvalue) yvalue (cdr yvalue)) | 716 | (while (setq calc-graph-xvalue (cdr calc-graph-xvalue) calc-graph-yvalue (cdr calc-graph-yvalue)) |
| 678 | (setq xp (nconc xp (make-list (1+ numsteps3) (car xvalue))) | 717 | (setq calc-graph-xp (nconc calc-graph-xp (make-list (1+ calc-graph-numsteps3) (car calc-graph-xvalue))) |
| 679 | yp (nconc yp (cons 0 (copy-sequence (cdr y3value)))) | 718 | calc-graph-yp (nconc calc-graph-yp (cons 0 (copy-sequence (cdr calc-graph-y3value)))) |
| 680 | zp (nconc zp (cons '(skip) | 719 | calc-graph-zp (nconc calc-graph-zp (cons '(skip) |
| 681 | (copy-sequence (cdr (car yvalue))))))) | 720 | (copy-sequence (cdr (car calc-graph-yvalue))))))) |
| 682 | (setq numsteps (1- (* numsteps (1+ numsteps3))))) | 721 | (setq calc-graph-numsteps (1- (* calc-graph-numsteps |
| 683 | (if (= (setq numsteps (1- (length yvalue))) 0) | 722 | (1+ calc-graph-numsteps3))))) |
| 723 | (if (= (setq calc-graph-numsteps (1- (length calc-graph-yvalue))) 0) | ||
| 684 | (error "Can't plot an empty vector")) | 724 | (error "Can't plot an empty vector")) |
| 685 | (or (and (eq (car-safe xvalue) 'vec) | 725 | (or (and (eq (car-safe calc-graph-xvalue) 'vec) |
| 686 | (= (1- (length xvalue)) numsteps)) | 726 | (= (1- (length calc-graph-xvalue)) calc-graph-numsteps)) |
| 687 | (error "%s is not a suitable basis for %s" xname yname)) | 727 | (error "%s is not a suitable basis for %s" calc-graph-xname calc-graph-yname)) |
| 688 | (or (and (eq (car-safe y3value) 'vec) | 728 | (or (and (eq (car-safe calc-graph-y3value) 'vec) |
| 689 | (= (1- (length y3value)) numsteps)) | 729 | (= (1- (length calc-graph-y3value)) calc-graph-numsteps)) |
| 690 | (error "%s is not a suitable basis for %s" y3name yname)) | 730 | (error "%s is not a suitable basis for %s" calc-graph-y3name calc-graph-yname)) |
| 691 | (setq xp xvalue | 731 | (setq calc-graph-xp calc-graph-xvalue |
| 692 | yp y3value | 732 | calc-graph-yp calc-graph-y3value |
| 693 | zp yvalue | 733 | calc-graph-zp calc-graph-yvalue |
| 694 | xvec t)) | 734 | calc-graph-xvec t)) |
| 695 | (or (math-realp yvalue) | 735 | (or (math-realp calc-graph-yvalue) |
| 696 | (let ((arglist nil)) | 736 | (let ((arglist nil)) |
| 697 | (setq yvalue (math-evaluate-expr yvalue)) | 737 | (setq calc-graph-yvalue (math-evaluate-expr calc-graph-yvalue)) |
| 698 | (calc-default-formula-arglist yvalue) | 738 | (calc-default-formula-arglist calc-graph-yvalue) |
| 699 | (setq arglist (sort arglist 'string-lessp)) | 739 | (setq arglist (sort arglist 'string-lessp)) |
| 700 | (or (cdr arglist) | 740 | (or (cdr arglist) |
| 701 | (error "%s does not contain enough unassigned variables" yname)) | 741 | (error "%s does not contain enough unassigned variables" calc-graph-yname)) |
| 702 | (and (cdr (cdr arglist)) | 742 | (and (cdr (cdr arglist)) |
| 703 | (error "%s contains too many variables: %s" yname arglist)) | 743 | (error "%s contains too many variables: %s" calc-graph-yname arglist)) |
| 704 | (setq yvalue (math-multi-subst yvalue | 744 | (setq calc-graph-yvalue (math-multi-subst calc-graph-yvalue |
| 705 | (mapcar 'math-build-var-name | 745 | (mapcar 'math-build-var-name |
| 706 | arglist) | 746 | arglist) |
| 707 | '((var DUMMY var-DUMMY) | 747 | '((var DUMMY var-DUMMY) |
| 708 | (var DUMMY2 var-DUMMY2)))))) | 748 | (var DUMMY2 var-DUMMY2)))))) |
| 709 | (if (setq xvec (eq (car-safe xvalue) 'vec)) | 749 | (if (setq calc-graph-xvec (eq (car-safe calc-graph-xvalue) 'vec)) |
| 710 | (setq numsteps (1- (length xvalue))) | 750 | (setq calc-graph-numsteps (1- (length calc-graph-xvalue))) |
| 711 | (if (and (eq (car-safe xvalue) 'intv) | 751 | (if (and (eq (car-safe calc-graph-xvalue) 'intv) |
| 712 | (math-constp xvalue)) | 752 | (math-constp calc-graph-xvalue)) |
| 713 | (setq numsteps resolution | 753 | (setq calc-graph-numsteps calc-graph-resolution |
| 714 | xvalue (calcFunc-index numsteps | 754 | calc-graph-xvalue (calcFunc-index calc-graph-numsteps |
| 715 | (nth 2 xvalue) | 755 | (nth 2 calc-graph-xvalue) |
| 716 | (math-div (math-sub (nth 3 xvalue) | 756 | (math-div (math-sub (nth 3 calc-graph-xvalue) |
| 717 | (nth 2 xvalue)) | 757 | (nth 2 calc-graph-xvalue)) |
| 718 | (1- numsteps)))) | 758 | (1- calc-graph-numsteps)))) |
| 719 | (error "%s is not a suitable basis for %s" | 759 | (error "%s is not a suitable basis for %s" |
| 720 | xname yname))) | 760 | calc-graph-xname calc-graph-yname))) |
| 721 | (if (setq y3vec (eq (car-safe y3value) 'vec)) | 761 | (if (eq (car-safe calc-graph-y3value) 'vec) |
| 722 | (setq numsteps3 (1- (length y3value))) | 762 | (setq calc-graph-numsteps3 (1- (length calc-graph-y3value))) |
| 723 | (if (and (eq (car-safe y3value) 'intv) | 763 | (if (and (eq (car-safe calc-graph-y3value) 'intv) |
| 724 | (math-constp y3value)) | 764 | (math-constp calc-graph-y3value)) |
| 725 | (setq numsteps3 resolution | 765 | (setq calc-graph-numsteps3 calc-graph-resolution |
| 726 | y3value (calcFunc-index numsteps3 | 766 | calc-graph-y3value (calcFunc-index calc-graph-numsteps3 |
| 727 | (nth 2 y3value) | 767 | (nth 2 calc-graph-y3value) |
| 728 | (math-div (math-sub (nth 3 y3value) | 768 | (math-div (math-sub (nth 3 calc-graph-y3value) |
| 729 | (nth 2 y3value)) | 769 | (nth 2 calc-graph-y3value)) |
| 730 | (1- numsteps3)))) | 770 | (1- calc-graph-numsteps3)))) |
| 731 | (error "%s is not a suitable basis for %s" | 771 | (error "%s is not a suitable basis for %s" |
| 732 | y3name yname))) | 772 | calc-graph-y3name calc-graph-yname))) |
| 733 | (setq xp nil | 773 | (setq calc-graph-xp nil |
| 734 | yp nil | 774 | calc-graph-yp nil |
| 735 | zp nil | 775 | calc-graph-zp nil |
| 736 | xvec t) | 776 | calc-graph-xvec t) |
| 737 | (setq math-working-step 0) | 777 | (setq math-working-step 0) |
| 738 | (while (setq xvalue (cdr xvalue)) | 778 | (while (setq calc-graph-xvalue (cdr calc-graph-xvalue)) |
| 739 | (setq xp (nconc xp (make-list (1+ numsteps3) (car xvalue))) | 779 | (setq calc-graph-xp (nconc calc-graph-xp (make-list (1+ calc-graph-numsteps3) (car calc-graph-xvalue))) |
| 740 | yp (nconc yp (cons 0 (copy-sequence (cdr y3value)))) | 780 | calc-graph-yp (nconc calc-graph-yp (cons 0 (copy-sequence (cdr calc-graph-y3value)))) |
| 741 | zp (cons '(skip) zp) | 781 | calc-graph-zp (cons '(skip) calc-graph-zp) |
| 742 | y3step y3value | 782 | calc-graph-y3step calc-graph-y3value |
| 743 | var-DUMMY (car xvalue) | 783 | var-DUMMY (car calc-graph-xvalue) |
| 744 | math-working-step-2 0 | 784 | math-working-step-2 0 |
| 745 | math-working-step (1+ math-working-step)) | 785 | math-working-step (1+ math-working-step)) |
| 746 | (while (setq y3step (cdr y3step)) | 786 | (while (setq calc-graph-y3step (cdr calc-graph-y3step)) |
| 747 | (setq math-working-step-2 (1+ math-working-step-2) | 787 | (setq math-working-step-2 (1+ math-working-step-2) |
| 748 | var-DUMMY2 (car y3step) | 788 | var-DUMMY2 (car calc-graph-y3step) |
| 749 | zp (cons (math-evaluate-expr yvalue) zp)))) | 789 | calc-graph-zp (cons (math-evaluate-expr calc-graph-yvalue) calc-graph-zp)))) |
| 750 | (setq zp (nreverse zp) | 790 | (setq calc-graph-zp (nreverse calc-graph-zp) |
| 751 | numsteps (1- (* numsteps (1+ numsteps3)))))) | 791 | calc-graph-numsteps (1- (* calc-graph-numsteps (1+ calc-graph-numsteps3)))))) |
| 752 | 792 | ||
| 753 | (defun calc-graph-format-data () | 793 | (defun calc-graph-format-data () |
| 754 | (while (<= (setq stepcount (1+ stepcount)) numsteps) | 794 | (while (<= (setq calc-graph-stepcount (1+ calc-graph-stepcount)) calc-graph-numsteps) |
| 755 | (if xvec | 795 | (if calc-graph-xvec |
| 756 | (setq xp (cdr xp) | 796 | (setq calc-graph-xp (cdr calc-graph-xp) |
| 757 | xval (car xp) | 797 | calc-graph-xval (car calc-graph-xp) |
| 758 | yp (cdr yp) | 798 | calc-graph-yp (cdr calc-graph-yp) |
| 759 | yval (car yp) | 799 | calc-graph-yval (car calc-graph-yp) |
| 760 | zp (cdr zp) | 800 | calc-graph-zp (cdr calc-graph-zp) |
| 761 | zval (car zp)) | 801 | calc-graph-zval (car calc-graph-zp)) |
| 762 | (if yvec | 802 | (if calc-graph-yvec |
| 763 | (setq xval xvalue | 803 | (setq calc-graph-xval calc-graph-xvalue |
| 764 | xvalue (math-add xvalue xstep) | 804 | calc-graph-xvalue (math-add calc-graph-xvalue calc-graph-xstep) |
| 765 | yp (cdr yp) | 805 | calc-graph-yp (cdr calc-graph-yp) |
| 766 | yval (car yp)) | 806 | calc-graph-yval (car calc-graph-yp)) |
| 767 | (setq xval (car (car yp)) | 807 | (setq calc-graph-xval (car (car calc-graph-yp)) |
| 768 | yval (cdr (car yp)) | 808 | calc-graph-yval (cdr (car calc-graph-yp)) |
| 769 | yp (cdr yp)) | 809 | calc-graph-yp (cdr calc-graph-yp)) |
| 770 | (if (or (not yp) | 810 | (if (or (not calc-graph-yp) |
| 771 | (and xhigh (equal xval xhigh))) | 811 | (and calc-graph-xhigh (equal calc-graph-xval calc-graph-xhigh))) |
| 772 | (setq numsteps 0)))) | 812 | (setq calc-graph-numsteps 0)))) |
| 773 | (if is-splot | 813 | (if calc-graph-is-splot |
| 774 | (if (and (eq (car-safe zval) 'calcFunc-xyz) | 814 | (if (and (eq (car-safe calc-graph-zval) 'calcFunc-xyz) |
| 775 | (= (length zval) 4)) | 815 | (= (length calc-graph-zval) 4)) |
| 776 | (setq xval (nth 1 zval) | 816 | (setq calc-graph-xval (nth 1 calc-graph-zval) |
| 777 | yval (nth 2 zval) | 817 | calc-graph-yval (nth 2 calc-graph-zval) |
| 778 | zval (nth 3 zval))) | 818 | calc-graph-zval (nth 3 calc-graph-zval))) |
| 779 | (if (and (eq (car-safe yval) 'calcFunc-xyz) | 819 | (if (and (eq (car-safe calc-graph-yval) 'calcFunc-xyz) |
| 780 | (= (length yval) 4)) | 820 | (= (length calc-graph-yval) 4)) |
| 781 | (progn | 821 | (progn |
| 782 | (or surprise-splot | 822 | (or calc-graph-surprise-splot |
| 783 | (save-excursion | 823 | (save-excursion |
| 784 | (set-buffer (get-buffer-create "*Gnuplot Temp*")) | 824 | (set-buffer (get-buffer-create "*Gnuplot Temp*")) |
| 785 | (save-excursion | 825 | (save-excursion |
| 786 | (goto-char (point-max)) | 826 | (goto-char (point-max)) |
| 787 | (re-search-backward "^plot[ \t]") | 827 | (re-search-backward "^plot[ \t]") |
| 788 | (insert "set parametric\ns") | 828 | (insert "set parametric\ns") |
| 789 | (setq surprise-splot t)))) | 829 | (setq calc-graph-surprise-splot t)))) |
| 790 | (setq xval (nth 1 yval) | 830 | (setq calc-graph-xval (nth 1 calc-graph-yval) |
| 791 | zval (nth 3 yval) | 831 | calc-graph-zval (nth 3 calc-graph-yval) |
| 792 | yval (nth 2 yval))) | 832 | calc-graph-yval (nth 2 calc-graph-yval))) |
| 793 | (if (and (eq (car-safe yval) 'calcFunc-xy) | 833 | (if (and (eq (car-safe calc-graph-yval) 'calcFunc-xy) |
| 794 | (= (length yval) 3)) | 834 | (= (length calc-graph-yval) 3)) |
| 795 | (setq xval (nth 1 yval) | 835 | (setq calc-graph-xval (nth 1 calc-graph-yval) |
| 796 | yval (nth 2 yval))))) | 836 | calc-graph-yval (nth 2 calc-graph-yval))))) |
| 797 | (if (and (Math-realp xval) | 837 | (if (and (Math-realp calc-graph-xval) |
| 798 | (Math-realp yval) | 838 | (Math-realp calc-graph-yval) |
| 799 | (or (not zval) (Math-realp zval))) | 839 | (or (not calc-graph-zval) (Math-realp calc-graph-zval))) |
| 800 | (progn | 840 | (progn |
| 801 | (setq blank nil | 841 | (setq calc-graph-blank nil |
| 802 | non-blank t) | 842 | calc-graph-non-blank t) |
| 803 | (if (Math-integerp xval) | 843 | (if (Math-integerp calc-graph-xval) |
| 804 | (insert (math-format-number xval)) | 844 | (insert (math-format-number calc-graph-xval)) |
| 805 | (if (eq (car xval) 'frac) | 845 | (if (eq (car calc-graph-xval) 'frac) |
| 806 | (setq xval (math-float xval))) | 846 | (setq calc-graph-xval (math-float calc-graph-xval))) |
| 807 | (insert (math-format-number (nth 1 xval)) | 847 | (insert (math-format-number (nth 1 calc-graph-xval)) |
| 808 | "e" (int-to-string (nth 2 xval)))) | 848 | "e" (int-to-string (nth 2 calc-graph-xval)))) |
| 809 | (insert " ") | 849 | (insert " ") |
| 810 | (if (Math-integerp yval) | 850 | (if (Math-integerp calc-graph-yval) |
| 811 | (insert (math-format-number yval)) | 851 | (insert (math-format-number calc-graph-yval)) |
| 812 | (if (eq (car yval) 'frac) | 852 | (if (eq (car calc-graph-yval) 'frac) |
| 813 | (setq yval (math-float yval))) | 853 | (setq calc-graph-yval (math-float calc-graph-yval))) |
| 814 | (insert (math-format-number (nth 1 yval)) | 854 | (insert (math-format-number (nth 1 calc-graph-yval)) |
| 815 | "e" (int-to-string (nth 2 yval)))) | 855 | "e" (int-to-string (nth 2 calc-graph-yval)))) |
| 816 | (if zval | 856 | (if calc-graph-zval |
| 817 | (progn | 857 | (progn |
| 818 | (insert " ") | 858 | (insert " ") |
| 819 | (if (Math-integerp zval) | 859 | (if (Math-integerp calc-graph-zval) |
| 820 | (insert (math-format-number zval)) | 860 | (insert (math-format-number calc-graph-zval)) |
| 821 | (if (eq (car zval) 'frac) | 861 | (if (eq (car calc-graph-zval) 'frac) |
| 822 | (setq zval (math-float zval))) | 862 | (setq calc-graph-zval (math-float calc-graph-zval))) |
| 823 | (insert (math-format-number (nth 1 zval)) | 863 | (insert (math-format-number (nth 1 calc-graph-zval)) |
| 824 | "e" (int-to-string (nth 2 zval)))))) | 864 | "e" (int-to-string (nth 2 calc-graph-zval)))))) |
| 825 | (insert "\n")) | 865 | (insert "\n")) |
| 826 | (and (not (equal zval '(skip))) | 866 | (and (not (equal calc-graph-zval '(skip))) |
| 827 | (boundp 'var-PlotRejects) | ||
| 828 | (eq (car-safe var-PlotRejects) 'vec) | 867 | (eq (car-safe var-PlotRejects) 'vec) |
| 829 | (nconc var-PlotRejects | 868 | (nconc var-PlotRejects |
| 830 | (list (list 'vec | 869 | (list (list 'vec |
| 831 | curve-num | 870 | calc-graph-curve-num |
| 832 | stepcount | 871 | calc-graph-stepcount |
| 833 | xval yval))) | 872 | calc-graph-xval calc-graph-yval))) |
| 834 | (calc-refresh-evaltos 'var-PlotRejects)) | 873 | (calc-refresh-evaltos 'var-PlotRejects)) |
| 835 | (or blank | 874 | (or calc-graph-blank |
| 836 | (progn | 875 | (progn |
| 837 | (insert "\n") | 876 | (insert "\n") |
| 838 | (setq blank t)))))) | 877 | (setq calc-graph-blank t)))))) |
| 839 | 878 | ||
| 840 | (defun calc-temp-file-name (num) | 879 | (defun calc-temp-file-name (num) |
| 841 | (while (<= (length calc-graph-file-cache) (1+ num)) | 880 | (while (<= (length calc-graph-file-cache) (1+ num)) |
| @@ -859,9 +898,7 @@ | |||
| 859 | (setq calc-graph-file-cache (cdr calc-graph-file-cache)))) | 898 | (setq calc-graph-file-cache (cdr calc-graph-file-cache)))) |
| 860 | 899 | ||
| 861 | (defun calc-graph-kill-hook () | 900 | (defun calc-graph-kill-hook () |
| 862 | (calc-graph-delete-temps) | 901 | (calc-graph-delete-temps)) |
| 863 | (if calc-graph-prev-kill-hook | ||
| 864 | (funcall calc-graph-prev-kill-hook))) | ||
| 865 | 902 | ||
| 866 | (defun calc-graph-show-tty (output) | 903 | (defun calc-graph-show-tty (output) |
| 867 | "Default calc-gnuplot-plot-command for \"tty\" output mode. | 904 | "Default calc-gnuplot-plot-command for \"tty\" output mode. |
| @@ -870,6 +907,9 @@ This is useful for tek40xx and other graphics-terminal types." | |||
| 870 | nil calc-gnuplot-buffer nil | 907 | nil calc-gnuplot-buffer nil |
| 871 | "-c" (format "cat %s >/dev/tty; rm %s" output output))) | 908 | "-c" (format "cat %s >/dev/tty; rm %s" output output))) |
| 872 | 909 | ||
| 910 | (defvar calc-dumb-map nil | ||
| 911 | "The keymap for the \"dumb\" terminal plot.") | ||
| 912 | |||
| 873 | (defun calc-graph-show-dumb (&optional output) | 913 | (defun calc-graph-show-dumb (&optional output) |
| 874 | "Default calc-gnuplot-plot-command for Pinard's \"dumb\" terminal type. | 914 | "Default calc-gnuplot-plot-command for Pinard's \"dumb\" terminal type. |
| 875 | This \"dumb\" driver will be present in Gnuplot 3.0." | 915 | This \"dumb\" driver will be present in Gnuplot 3.0." |
| @@ -882,7 +922,6 @@ This \"dumb\" driver will be present in Gnuplot 3.0." | |||
| 882 | (sleep-for 1)) | 922 | (sleep-for 1)) |
| 883 | (goto-char (point-max)) | 923 | (goto-char (point-max)) |
| 884 | (re-search-backward "\f\\|^[ \t]+\\^$\\|G N U P L O T") | 924 | (re-search-backward "\f\\|^[ \t]+\\^$\\|G N U P L O T") |
| 885 | (setq found-pt (point)) | ||
| 886 | (if (looking-at "\f") | 925 | (if (looking-at "\f") |
| 887 | (progn | 926 | (progn |
| 888 | (forward-char 1) | 927 | (forward-char 1) |
| @@ -898,7 +937,7 @@ This \"dumb\" driver will be present in Gnuplot 3.0." | |||
| 898 | (end-of-line) | 937 | (end-of-line) |
| 899 | (backward-char 1) | 938 | (backward-char 1) |
| 900 | (recenter '(4))) | 939 | (recenter '(4))) |
| 901 | (or (boundp 'calc-dumb-map) | 940 | (or calc-dumb-map |
| 902 | (progn | 941 | (progn |
| 903 | (setq calc-dumb-map (make-sparse-keymap)) | 942 | (setq calc-dumb-map (make-sparse-keymap)) |
| 904 | (define-key calc-dumb-map "\n" 'scroll-up) | 943 | (define-key calc-dumb-map "\n" 'scroll-up) |
| @@ -1097,7 +1136,8 @@ This \"dumb\" driver will be present in Gnuplot 3.0." | |||
| 1097 | (or (calc-graph-find-plot nil nil) | 1136 | (or (calc-graph-find-plot nil nil) |
| 1098 | (error "No data points have been set!")) | 1137 | (error "No data points have been set!")) |
| 1099 | (let ((base (point)) | 1138 | (let ((base (point)) |
| 1100 | start) | 1139 | start |
| 1140 | end) | ||
| 1101 | (re-search-forward "[,\n]\\|[ \t]+with") | 1141 | (re-search-forward "[,\n]\\|[ \t]+with") |
| 1102 | (setq end (match-beginning 0)) | 1142 | (setq end (match-beginning 0)) |
| 1103 | (goto-char base) | 1143 | (goto-char base) |