From mboxrd@z Thu Jan 1 00:00:00 1970 From: Litvinov Sergey Subject: [PATCH] ob-fortran.el, add matrix as input Date: Sat, 01 Jun 2013 19:28:13 +0200 Message-ID: <5rvc5x211u.fsf@kana.aer.mw.tum.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UipbQ-0006Qd-Dg for emacs-orgmode@gnu.org; Sat, 01 Jun 2013 13:28:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UipbO-0000SX-Nq for emacs-orgmode@gnu.org; Sat, 01 Jun 2013 13:28:28 -0400 Received: from plane.gmane.org ([80.91.229.3]:43877) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UipbO-0000RN-GY for emacs-orgmode@gnu.org; Sat, 01 Jun 2013 13:28:26 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UipbL-0004yg-W9 for emacs-orgmode@gnu.org; Sat, 01 Jun 2013 19:28:24 +0200 Received: from kana.aer.mw.tum.de ([129.187.68.65]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 01 Jun 2013 19:28:23 +0200 Received: from slitvinov by kana.aer.mw.tum.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 01 Jun 2013 19:28:23 +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: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-a-matrix-input-to-ob-fortran.el.patch Content-Description: ob-fortran.el patch >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" -- 1.8.1.5 --=-=-=--