Re: [O] [PATCH] ob-fortran.el, add matrix as input

2013-06-06 Thread Eric Schulte
Achim Gratz  writes:

> Eric Schulte writes:
>> 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.
>
> I've not had time to test with anything, but this patch seems to make
> the same faulty assumption about tables always being a list of lists
> that I fixed just a few days ago someplace else.  When dealing with
> tables you have to expect hlines in place of a list with the row values
> otherwise you will not correctly recognize them.
>

Agreed, I've just updated the matrix check in ob-fortran to be more
strict so that tables with hlines will not be treated as matrices.

A more sophisticated solution to correctly interpret hlines in a manner
acceptable to Fortran would require more Fortran knowledge than I
posses.

Best,

>
>
> Regards,
> Achim.

-- 
Eric Schulte
http://cs.unm.edu/~eschulte



Re: [O] [PATCH] ob-fortran.el, add matrix as input

2013-06-05 Thread Achim Gratz
Eric Schulte writes:
> 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.

I've not had time to test with anything, but this patch seems to make
the same faulty assumption about tables always being a list of lists
that I fixed just a few days ago someplace else.  When dealing with
tables you have to expect hlines in place of a list with the row values
otherwise you will not correctly recognize them.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

SD adaptations for KORG EX-800 and Poly-800MkII V0.9:
http://Synth.Stromeko.net/Downloads.html#KorgSDada




Re: [O] [PATCH] ob-fortran.el, add matrix as input

2013-06-03 Thread Eric Schulte
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



[O] [PATCH] ob-fortran.el, add matrix as input

2013-06-01 Thread Litvinov Sergey
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"
-- 
1.8.1.5