Browse Source

From: Juan <Pechiar@computer.org>

Hi,

I'm starting to work with ob-octave and found several problems:

The first, for which I have a fix (see patch below) is that octave's
output was passed on as a string instead of being interpreted as a table:

[diff removed]

Now this works:

8<------------------------------------------------------------
#+source: test_output
#+begin_src octave :results value vector
[[1 2 3];[4 5 6]]
#+end_src

#+results: test_output
| 1.00000000e+00 | 2.00000000e+00 | 3.00000000e+00 |
| 4.00000000e+00 | 5.00000000e+00 | 6.00000000e+00 |
8<------------------------------------------------------------

(before the patch you'd get a single table element with something like
"1 2 3\n 4 5 6\n" inside).

The second problem is that if I use octave table output as input to
another block, it gets interpreted as a string instead of a vector:

8<------------------------------------------------------------
#+results: test_output
| 1.25000000e+00 |

#+source: check_input
#+begin_src octave :var input=test_output() :results output
ischar( input )
size( input )
#+end_src

#+results: check_input
: input = 1.25000000e+00
: ans =  1
: ans =
:     1   14
8<------------------------------------------------------------

This has to do with the EXP notation. The 'e+00' suffix makes the
whole table into a string. The problem is with "%S" in the formatting
inside org-babel-octave-var-to-octave.

The following patch seems to fix it (and makes it possible to work with
complex numbers inside the tables)::

[diff removed]

A third problem is with org-babel-octave-var-to-octave.

For example:

: (org-babel-octave-var-to-octave '( ( 1 2 3 ) ( 4 5 6 ) ))
: ->  "[[1, 2, 3], [4, 5, 6]]"

This is not a 2x3 matrix, but a 1x6 vector:

: octave-3.2.3:1> [[1,2,3],[4,5,6]]
: ans =
:    1   2   3   4   5   6

a semicolon ';' or '\n' is needed between rows instead of a comma.

To sum up:
   - 2 patches for prepare-session and importing the results back as
   org-tables (I don't know if these patches break anything).

   - 1 problem with matrix notation in org-babel-octave-var-to-octave.
   I'll try to provide a patch for this today.

2010-08-01  Juan Pechiar  <Pechiar@computer.org>

	* ob-octave.el (org-babel-octave-evaluate-external-process):
	use `org-babel-octave-import-elisp-from-file' instead of
	`org-babel-eval-read-file'.
	(org-babel-octave-var-to-octave): separate matrix rows with
	';', and use '%s' as format specifier instead of '%S'
Juan Pechiar 14 years ago
parent
commit
743a7b8293
1 changed files with 4 additions and 3 deletions
  1. 4 3
      lisp/ob-octave.el

+ 4 - 3
lisp/ob-octave.el

@@ -119,8 +119,9 @@ end")
 Converts an emacs-lisp variable into a string of octave code
 specifying a variable of the same value."
   (if (listp var)
-      (concat "[" (mapconcat #'org-babel-octave-var-to-octave var ", ") "]")
-    (format "%S" var)))
+      (concat "[" (mapconcat #'org-babel-octave-var-to-octave var
+			     (if (listp (car var)) "; " ",")) "]")
+    (format "%s" (or var "nil"))))
 
 (defun org-babel-prep-session:octave (session params &optional matlabp)
   "Prepare SESSION according to the header arguments specified in PARAMS."
@@ -181,7 +182,7 @@ value of the last statement in BODY, as elisp."
 	       (org-babel-eval
 		cmd
 		(format org-babel-octave-wrapper-method body tmp-file tmp-file))
-	       (org-babel-eval-read-file tmp-file))))))
+	       (org-babel-octave-import-elisp-from-file tmp-file))))))
 
 (defun org-babel-octave-evaluate-session
   (session body result-type &optional matlabp)