Merge branch 'maint'
[org-mode.git] / testing / examples / ob-fortran-test.org
blob8aa047f3ee37db4b1c95233d620c86e7e651469b
1 #+Title: a collection of examples for ob-fortran tests
2 #+OPTIONS: ^:nil
4 * simple programs
5   :PROPERTIES:
6   :ID:       459384e8-1797-4f11-867e-dde0473ea7cc
7   :END:
8 #+name: hello
9 #+begin_src fortran :results silent
10 print *, 'Hello world'
11 #+end_src
13 #+name: fortran_parameter
14 #+begin_src fortran :results silent
15 integer, parameter :: i = 10
16 write (*, '(i2)') i
17 #+end_src
19 * variable resolution
20   :PROPERTIES:
21   :ID:       d8d1dfd3-5f0c-48fe-b55d-777997e02242
22   :END:
23 #+begin_src fortran :var N = 15 :results silent
24 write (*, '(i2)') N
25 #+end_src
27 Define for preprocessed fortran
28 #+begin_src fortran :defines N 42 :results silent
29 implicit none
30 write (*, '(i2)') N
31 #+end_src
33 #+begin_src fortran :var s="word" :results silent
34 write (*, '(a4)') s
35 #+end_src
36 * arrays
37   :PROPERTIES:
38   :ID:       c28569d9-04ce-4cad-ab81-1ea29f691465
39   :END:
40 Real array as input
41 #+begin_src fortran :var s='(1.0 2.0 3.0) :results silent
42 write (*, '(3f5.2)'), s
43 #+end_src
45 #+name: test_tbl
46 | 1.0 |
47 | 2.0 |
49 #+begin_src fortran :var s=test_tbl :results silent
50 write (*, '(2f5.2)'), s
51 #+end_src
53 * matrix
54   :PROPERTIES:
55   :ID:       3f73ab19-d25a-428d-8c26-e8c6aa933976
56   :END:
57 Real matrix as input
58 #+name: fortran-input-matrix1
59 | 0.0 | 42.0 |
60 | 0.0 |  0.0 |
61 | 0.0 |  0.0 |
63 #+name: fortran-input-matrix2
64 | 0.0 | 0.0 | 0.0 |
65 | 0.0 | 0.0 | 42.0 |
67 #+begin_src fortran :var s=fortran-input-matrix1 :results silent
68 write (*, '(i2)'), nint(s(1,2))
69 #+end_src
71 #+begin_src fortran :var s=fortran-input-matrix2 :results silent
72 write (*, '(i2)'), nint(s(2,3))
73 #+end_src
75 * failing
76   :PROPERTIES:
77   :ID:       891ead4a-f87a-473c-9ae0-1cf348bcd04f
78   :END:
79 Should fail (TODO: add input variables for the case with explicit
80 program statement)
81 #+begin_src fortran :var s="word" :results silent
82 program ex
83 print *, "output of ex program"
84 end program ex
85 #+end_src
87 Fails to compile (TODO: error check in ob-fortran.el)
88 #+begin_src fortran :var s='(1 ()) :results silent
89 print *, s
90 #+end_src
92 Should fail to compile with gfortran
93 #+begin_src fortran :flags --std=f95 --pedantic-error :results silent
94 program ex
95 integer*8 :: i
96 end program ex
97 #+end_src
99 * programs input parameters
100   :PROPERTIES:
101   :ID:       2d5330ea-9934-4737-9ed6-e1d3dae2dfa4
102   :END:
103 Pass parameters to the program
104 #+begin_src fortran :cmdline "23" :results silent
105 character(len=255) :: cmd
106 call get_command_argument(1, cmd)
107 write (*,*) trim(cmd)
108 #+end_src