emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ob-fortran.el, add matrix as input
@ 2013-06-01 17:28 Litvinov Sergey
  2013-06-04  4:56 ` Eric Schulte
  0 siblings, 1 reply; 4+ messages in thread
From: Litvinov Sergey @ 2013-06-01 17:28 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 157 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ob-fortran.el patch --]
[-- Type: text/x-patch, Size: 3123 bytes --]

From 4115610e692e5056fa4c0f9d498c12912d374646 Mon Sep 17 00:00:00 2001
From: Litvinov Sergey <slitvinov@gmail.com>
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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-06-06 16:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-01 17:28 [PATCH] ob-fortran.el, add matrix as input Litvinov Sergey
2013-06-04  4:56 ` Eric Schulte
2013-06-05 20:39   ` Achim Gratz
2013-06-06 16:17     ` Eric Schulte

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).