From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: [BABEL] Output with octave [PATCH] Date: Wed, 04 Aug 2010 00:18:12 -0400 Message-ID: <87aap3roxn.fsf@stats.ox.ac.uk> References: <87iq45x06e.wl%ucecesf@ucl.ac.uk> <871vai42nz.fsf@stats.ox.ac.uk> <20100801200727.GT5569@soloJazz.com> <20100801202214.GU5569@soloJazz.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=58517 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OgVQv-0007Qv-6x for emacs-orgmode@gnu.org; Wed, 04 Aug 2010 00:18:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OgVQt-0005Qk-N4 for emacs-orgmode@gnu.org; Wed, 04 Aug 2010 00:18:25 -0400 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:36532) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OgVQt-0005Qf-Cy for emacs-orgmode@gnu.org; Wed, 04 Aug 2010 00:18:23 -0400 In-Reply-To: <20100801202214.GU5569@soloJazz.com> (Juan Pechiar's message of "Sun, 1 Aug 2010 17:22:14 -0300") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Juan Pechiar Cc: emacs-orgmode@gnu.org, "d.tchin" 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 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