[Orgmode] Re: [BABEL] Output with octave [PATCH]
Hi Juan and d.tchin, One thing I'd like to ask for advice about is the behaviour of tabular data structures containing strings. For example #+begin_src octave ans = [['a','b'];['c','d']] #+end_src #+results: : acbd I don't know if my syntax above is correct, but it seems to me that this is a 2x2 table of some sort and so it would seem natural to me for that to return | a | b | | c | d | however, if you look at the code we are using below, you'll see that ischar() returns 1 for this object and so it gets written as a string. Can you suggest how we should alter the octave/matlab code below? Or perhaps people don't use tabular data structures containing strings in these languages? if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans); fclose(fid); else, dlmwrite('%s', ans, '\\t') end Dan Juan Pechiar pech...@computer.org writes: Hi, Below is a single PATCH for the 3 issues: - passing tables with EXP or complex notation to octave - correct formatting of matrixes into octave - interpretation of octave output as table Regards, .j. 8 diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el index 8e99f86..bf7fdd3 100644 --- a/lisp/ob-octave.el +++ b/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 var))) (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) 8 On Sun, Aug 01, 2010 at 05:07:27PM -0300, Juan wrote: 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: 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: 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. 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. ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
Re: [Orgmode] Re: [BABEL] Output with octave + [PATCH] x2
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: 8 diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el index 8e99f86..d0d16fe 100644 --- a/lisp/ob-octave.el +++ b/lisp/ob-octave.el @@ -181,7 +181,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) 8 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.e+00 | 2.e+00 | 3.e+00 | | 4.e+00 | 5.e+00 | 6.e+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.2500e+00 | #+source: check_input #+begin_src octave :var input=test_output() :results output ischar( input ) size( input ) #+end_src #+results: check_input : input = 1.2500e+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):: 8 diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el index 8e99f86..4329c7f 100644 --- a/lisp/ob-octave.el +++ b/lisp/ob-octave.el @@ -120,7 +120,7 @@ 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))) +(format %s var))) (defun org-babel-prep-session:octave (session params optional matlabp) Prepare SESSION according to the header arguments specified in PARAMS. 8 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. I'm not working with sessions, so I have not yet tested the original problem reported with 'org_babel_eoe' showing up as result. Regards, .j. On Sun, Aug 01, 2010 at 02:18:40PM -0400, Dan Davison wrote: Eric S Fraga ucec...@ucl.ac.uk writes: On Fri, 23 Jul 2010 16:59:43 + (UTC), d.tchin d.tc...@voila.fr wrote: I have problem to get output back in org mode file. ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
[Orgmode] Re: [BABEL] Output with octave + [PATCH] x2
Juan pech...@computer.org writes: Hi, I'm starting to work with ob-octave and found several problems: Hi Juan, Thanks very much. I've applied your patch with one minor change: (format %s (or var nil)) However, is there a better way to receive an elisp nil value in octave? I'm not working with sessions, so I have not yet tested the original problem reported with 'org_babel_eoe' showing up as result. Sorry to pursue you for more help, but that problem is not limited to sessions. A very simple demonstration of it is #+begin_src octave x = 5 x #+end_src #+results: : /usr/share/octave/packages/3.2 This happens because neither of these two lines of code alter the value of 'ans' (I presume the value we are seeing is something from octave's start-up sequence). Contrast this with #+begin_src octave x = 5 x+0 #+end_src #+results: : 5.e+00 Any idea of the best way forward? Dan Regards, .j. On Sun, Aug 01, 2010 at 02:18:40PM -0400, Dan Davison wrote: Eric S Fraga ucec...@ucl.ac.uk writes: On Fri, 23 Jul 2010 16:59:43 + (UTC), d.tchin d.tc...@voila.fr wrote: I have problem to get output back in org mode file. ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode