#433 plot2d() produces bad postscript

closed
nobody
None
5
2012-12-04
2003-11-02
No

A statement like
(C4) plot2d(x^2,[x,-5,5],[PLOT_FORMAT,PS]);
should produce a printable postscript file.
But maxout.ps simply contains a list of numbers.

Please mind: plot3d() works all-right.

Regards,

Uli Kruppa.

Discussion

  • Robert Dodier
    Robert Dodier
    2003-11-27

    Logged In: YES
    user_id=501686

    The file plot.lisp contains the function plot2d_ps, which
    appears to work as intended (as described by
    describe(plot2d_ps)) -- plot2d_ps invokes gv to show the
    figure, and creates a PS file, maxout.ps. However, plot2d
    does not call plot2d_ps.

    Perhaps one can fix plot2d by having it call plot2d_ps, but
    the obvious way to do that (copying the 2 lines for the
    openmath function) yields a run-time error about long-float
    types. So the fix must have to be less naive. I'll try
    something else.

     
  • Robert Dodier
    Robert Dodier
    2003-11-28

    Logged In: YES
    user_id=501686

    I have found that the following patch will make
    plot2d(foo,[x,bar,baz],[plot_format,ps]) work the same as
    plot2d_ps(foo,[x,bar,baz]) -- I hope that's the intended
    behavior.

    The line numbers for plot.lisp are for revision 1.18, tagged
    5.9.0 in CVS. There are newer revisions of plot.lisp,
    however, the newest one (1.32) has the same code for
    plot2d_ps and the first part of plot2d (modified here).

    --- /usr/share/maxima/5.9.0/src/plot.lisp Sun Feb 9
    20:24:27 2003
    +++ just_plot2d.lisp Fri Nov 28 14:10:30 2003
    @@ -730,3 +4,3 @@
    (dolist (v options) ($set_plot_option v))
    - (or ($listp fun ) (setf fun `((mlist) ,fun)))
    + ;; (or ($listp fun ) (setf fun `((mlist) ,fun)))
    (cond ((eq (cadr fun) '$parametric)
    @@ -734,2 +8,4 @@
    (setf fun `((mlist) ,fun))))
    + (cond ((eq ($get_plot_option '$PLOT_FORMAT 2) '$ps)
    + (return-from $plot2d (apply '$plot2d_ps fun range
    options))))
    (cond ((eq ($get_plot_option '$PLOT_FORMAT 2) '$openmath)

    The modified code seems to work correctly with "(or ($listp
    fun ) (setf fun `((mlist) ,fun)))" commented out, however, I
    don't understand the function of that line & therefore
    better understanding is needed.

    Note that if "(or ($listp ....))" is not commented out, the
    following error occurs when I attempt to execute
    plot2d(x^3,[x,0.5,1.5],[plot_format,ps]):

    ----------------- begin debugger output -------------
    *** - argument to COMMON-LISP:FLOAT should be a real number:
    ((MLIST SIMP) 0.125)
    The following restarts are available:
    R1 = Macsyma top-level

    1. Break [1]> :w

    EVAL frame for form (COMMON-LISP:FLOAT ($REALPART (MEVAL*
    '((MLIST) ((MEXPT SIMP) |$x| 3)))) 1.0)
    1. Break [1]> :bl

    Enter the limit for max. frames to print or ':all' for all: 3

    EVAL frame for form (COMMON-LISP:FLOAT ($REALPART (MEVAL*
    '((MLIST) ((MEXPT SIMP) |$x| 3)))) 1.0)
    APPLY frame for call (:LAMBDA '0.5)
    EVAL frame for form (APPLY '$PLOT2D_PS FUN RANGE OPTIONS)
    ----------------- end debugger output -------------

    It appears to be attempting to evaluate (0.5)^3, and failing.

     
  • Robert Dodier
    Robert Dodier
    2003-11-29

    Logged In: YES
    user_id=501686

    I've rebuilt Maxima using current cvs (as of 20031128). Lisp
    is clisp 2.31. Now if the line "(or ...)" is commented out,
    plot2d(x^3,[x,0.5,1.5],[plot_format,ps]); doesn't generate
    an error, but it just hangs (no postscript output, no
    ghostview display, no tcl/tk display) until I press ctrl-C.

    The patched version of plot.lisp with the newly rebuilt
    Maxima yields the expected results with [plot_format, ps],
    and also with no plot_format specified (shows tcl/tk
    display), and [plot_format, gnuplot] (executes gnuplot
    although gnuplot output file appears to be incorrect for the
    version of gnuplot that is installed), and [plot_format,
    openmath] (creates output file in openmath format).

     
  • Robert Dodier
    Robert Dodier
    2003-12-05

    Logged In: YES
    user_id=501686

    I've created a patched version of plot.lisp in which (1)
    plot2d calls plot2d_ps if [plot_format,ps] is given; and (2)
    plot2d_ps creates output which includes Document
    Structuring Convention comments, of which %%BoundingBox is
    probably the most important; this makes it possible to
    include the PS file in other documents such as LaTeX.

    I'll attach the patch as a separate file.

     
  • Robert Dodier
    Robert Dodier
    2003-12-05

    Logged In: YES
    user_id=501686

    Hmm, I'm not seeing a button or menu to attach a file to
    this bug report. Oh well, here is the patch; I hope it's
    readable.

    --- plot.lisp Sun Sep 28 12:15:38 2003
    +++ plot_fixup.lisp Fri Dec 5 11:08:02 2003
    @@ -906,9 +906,25 @@
    ($getrange tem (cddr range))
    ($psdraw_curve tem)
    ($psaxes ($rest range))
    - (p "showpage")
    + (p "showpage") ;; IS THIS NEEDED ???
    ($viewps WILL APPEND A showpage TOO.)
    ($viewps)))

    +;; do-ps-created-date was cribbed from the Common Lisp
    Cookbook -- Dates and Times.
    +;; See: http://cl-cookbook.sourceforge.net/dates_and_times.html
    +
    +(defun do-ps-created-date (my-stream)
    + (defconstant *day-names* '("Mon" "Tue" "Wed" "Thu" "Fri"
    "Sat" "Sun"))
    + (multiple-value-bind
    + (second minute hour date month year day-of-week dst-p tz)
    + (get-decoded-time)
    + (format my-stream "%%CreatedDate: ~2,'0d:~2,'0d:~2,'0d
    ~a, ~d/~2,'0d/~d (GMT~@d)~%"
    + hour minute second (nth day-of-week *day-names*)
    month date year (- tz))))
    +
    +(defun do-ps-trailer ()
    + (p "showpage")
    + (p "%%Trailer")
    + (p "%%EOF"))
    +

    (defvar $gnuplot_command "mgnuplot")
    (defvar $geomview_command "geomview maxout.geomview")
    @@ -919,10 +935,15 @@
    (i 0) plot-format file plot-name
    ($plot_options $plot_options))
    (dolist (v options) ($set_plot_option v))
    - (or ($listp fun ) (setf fun `((mlist) ,fun)))
    +
    + ;; IF NOT COMMENTED, plot2d(expr,range,[plot_format,ps])
    GENERATES BAD POSTSCRIPT (SEE BUG REPORT #834729)
    + ;; (or ($listp fun ) (setf fun `((mlist) ,fun)))
    +
    (cond ((eq (cadr fun) '$parametric)
    (or range (setq range (nth 4 fun)))
    (setf fun `((mlist) ,fun))))
    + (cond ((eq ($get_plot_option '$PLOT_FORMAT 2) '$ps)
    + (return-from $plot2d (apply '$plot2d_ps fun range
    options))))
    (cond ((eq ($get_plot_option '$PLOT_FORMAT 2) '$openmath)
    (return-from $plot2d (apply '$plot2dOpen fun range
    options))))
    (check-range range)
    @@ -1226,7 +1247,29 @@
    (t (setq do-prolog t)))
    (or $pstream (setq $pstream (open "maxout.ps" :direction
    :output :if-exists :supersede)))
    (cond (do-prolog
    - (p "%!")
    + (p "%!PS-Adobe-2.0")
    + (p "%%Title: Maxima 2d plot") ;; title
    could be filename and/or plot equation
    + (p "%%Creator: Maxima version:" *autoconf-version*
    "on" (lisp-implementation-type))
    + (do-ps-created-date $pstream)
    + (p "%%DocumentFonts: Helvetica")
    +
    + ;; Put the lower left corner of the bounding box
    at $ps_translate,
    + ;; and put the upper right corner at
    ($ps_translate + $window_size).
    + (p "%%BoundingBox:"
    + (round (nth 1 $ps_translate))
    + (round (nth 2 $ps_translate))
    + (round (+ (nth 1 $ps_translate) (nth 1
    $window_size)))
    + (round (+ (nth 2 $ps_translate) (nth 2
    $window_size))))
    +
    + (p "%%Orientation: Portrait")
    + (p "%%Pages: 1")
    + (p "%%EndComments")
    + (p "%%BeginPrologue")
    + (p "%%EndPrologue")
    + (p "%%BeginSetup")
    + (p "%%PaperSize: Letter")
    + (p "%%EndSetup")
    + (p "%%Page: 1 1")
    (p (* .5 (nth 1 $window_size))
    (* .5 (nth 2 $window_size))
    "translate"
    @@ -1323,7 +1366,7 @@

    (defun $viewps ( &optional file)
    (cond ((and (streamp $pstream))
    - ($pscom "showpage")
    + (do-ps-trailer)
    (force-output $pstream)))
    (cond (file (setq file (maxima-string file)))
    (t(setq file "maxout.ps")

     
  • Raymond Toy
    Raymond Toy
    2003-12-06

    • status: open --> closed
     
  • Raymond Toy
    Raymond Toy
    2003-12-06

    Logged In: YES
    user_id=28849

    Patch applied. This works and produces a nominally valid PS
    file that ghostscript can handle. Closing this bug.

    I note that the ps viewer command doesn't seem to be easily
    settable from maxima.