From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: [PATCH] ob-fortran.el, add matrix as input Date: Mon, 03 Jun 2013 22:56:55 -0600 Message-ID: <87ip1ueanc.fsf@gmail.com> References: <5rvc5x211u.fsf@kana.aer.mw.tum.de> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55386) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjjJY-0004pi-0U for emacs-orgmode@gnu.org; Tue, 04 Jun 2013 00:57:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UjjJT-0008I1-2J for emacs-orgmode@gnu.org; Tue, 04 Jun 2013 00:57:43 -0400 Received: from mail-pb0-x236.google.com ([2607:f8b0:400e:c01::236]:48923) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjjJS-0008Hu-Se for emacs-orgmode@gnu.org; Tue, 04 Jun 2013 00:57:39 -0400 Received: by mail-pb0-f54.google.com with SMTP id ro12so6689470pbb.27 for ; Mon, 03 Jun 2013 21:57:38 -0700 (PDT) In-Reply-To: <5rvc5x211u.fsf@kana.aer.mw.tum.de> (Litvinov Sergey's message of "Sat, 01 Jun 2013 19:28:13 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Litvinov Sergey Cc: emacs-orgmode@gnu.org Applied, Thanks! Litvinov Sergey writes: > I would like to propose a tiny patch which adds matrix as an input for > ob-fortran.el. See changes in testing/examples/ob-fortran-test.org for > the examples. > > > From 4115610e692e5056fa4c0f9d498c12912d374646 Mon Sep 17 00:00:00 2001 > From: Litvinov Sergey > Date: Sat, 1 Jun 2013 19:20:06 +0200 > Subject: [PATCH] Add a matrix input to ob-fortran.el > > * lisp/ob-fortran.el: add a branch which handles nested lists > * testing/examples/ob-fortran-test.org: add a test for matrix input > * testing/lisp/test-ob-fortran.el: add a test for matrix input > --- > lisp/ob-fortran.el | 6 ++++++ > testing/examples/ob-fortran-test.org | 22 ++++++++++++++++++++++ > testing/lisp/test-ob-fortran.el | 12 ++++++++++++ > 3 files changed, 40 insertions(+) > > diff --git a/lisp/ob-fortran.el b/lisp/ob-fortran.el > index 1eab03e..a379273 100644 > --- a/lisp/ob-fortran.el > +++ b/lisp/ob-fortran.el > @@ -143,6 +143,12 @@ of the same value." > ((stringp val) > (format "character(len=%d), parameter :: %S = '%s'\n" > (length val) var val)) > + ;; val is a matrix > + ((and (listp val) (listp (car val))) > + (format "real, parameter :: %S(%d,%d) = transpose( reshape( %s , (/ %d, %d /) ) )\n" > + var (length val) (length (car val)) > + (org-babel-fortran-transform-list val) > + (length (car val)) (length val))) > ((listp val) > (format "real, parameter :: %S(%d) = %s\n" > var (length val) (org-babel-fortran-transform-list val))) > diff --git a/testing/examples/ob-fortran-test.org b/testing/examples/ob-fortran-test.org > index 47931bf..530d15e 100644 > --- a/testing/examples/ob-fortran-test.org > +++ b/testing/examples/ob-fortran-test.org > @@ -50,6 +50,28 @@ write (*, '(3f5.2)'), s > write (*, '(2f5.2)'), s > #+end_src > > +* matrix > + :PROPERTIES: > + :ID: 3f73ab19-d25a-428d-8c26-e8c6aa933976 > + :END: > +Real matrix as input > +#+name: fortran-input-matrix1 > +| 0.0 | 42.0 | > +| 0.0 | 0.0 | > +| 0.0 | 0.0 | > + > +#+name: fortran-input-matrix2 > +| 0.0 | 0.0 | 0.0 | > +| 0.0 | 0.0 | 42.0 | > + > +#+begin_src fortran :var s=fortran-input-matrix1 :results silent > +write (*, '(i2)'), nint(s(1,2)) > +#+end_src > + > +#+begin_src fortran :var s=fortran-input-matrix2 :results silent > +write (*, '(i2)'), nint(s(2,3)) > +#+end_src > + > * failing > :PROPERTIES: > :ID: 891ead4a-f87a-473c-9ae0-1cf348bcd04f > diff --git a/testing/lisp/test-ob-fortran.el b/testing/lisp/test-ob-fortran.el > index c355996..7754c64 100644 > --- a/testing/lisp/test-ob-fortran.el > +++ b/testing/lisp/test-ob-fortran.el > @@ -68,6 +68,18 @@ > (org-babel-next-src-block 2) > (should (equal "1.00 2.00" (org-babel-execute-src-block))))) > > +(ert-deftest ob-fortran/list-matrix-from-table1 () > + "Test real matrix from a table" > + (org-test-at-id "3f73ab19-d25a-428d-8c26-e8c6aa933976" > + (org-babel-next-src-block 1) > + (should (= 42 (org-babel-execute-src-block))))) > + > +(ert-deftest ob-fortran/list-matrix-from-table2 () > + "Test real matrix from a table" > + (org-test-at-id "3f73ab19-d25a-428d-8c26-e8c6aa933976" > + (org-babel-next-src-block 2) > + (should (= 42 (org-babel-execute-src-block))))) > + > (ert-deftest ob-fortran/no-variables-with-main () > "Test :var with explicit 'program'" > (org-test-at-id "891ead4a-f87a-473c-9ae0-1cf348bcd04f" -- Eric Schulte http://cs.unm.edu/~eschulte