emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Litvinov Sergey <slitvinov@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] ob-fortran.el, add matrix as input
Date: Sat, 01 Jun 2013 19:28:13 +0200	[thread overview]
Message-ID: <5rvc5x211u.fsf@kana.aer.mw.tum.de> (raw)

[-- 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


             reply	other threads:[~2013-06-01 17:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-01 17:28 Litvinov Sergey [this message]
2013-06-04  4:56 ` [PATCH] ob-fortran.el, add matrix as input Eric Schulte
2013-06-05 20:39   ` Achim Gratz
2013-06-06 16:17     ` Eric Schulte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5rvc5x211u.fsf@kana.aer.mw.tum.de \
    --to=slitvinov@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).